0% found this document useful (0 votes)
15 views3 pages

Qbasic Exercises

This document presents nine programming exercises in Qbasic and their solutions. The exercises include programs to determine the largest of three numbers, perform currency conversions, compare words, calculate exam grades, medians, summations, factorials, arithmetic means, and correlation coefficients. The lines of Qbasic code for each solution are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Qbasic Exercises

This document presents nine programming exercises in Qbasic and their solutions. The exercises include programs to determine the largest of three numbers, perform currency conversions, compare words, calculate exam grades, medians, summations, factorials, arithmetic means, and correlation coefficients. The lines of Qbasic code for each solution are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Qbasic Exercises

1.- Create a program that reads three numbers and indicates which one is the largest.
2.- Create a program that converts pesetas to euros. Improve it by adding the exchange of
euros to pesetas and let the user decide what exchange rate they want, if it's in euros
to pesetas or the other way around.
3.- Create a program that allows you to decide if two words are the same or different.
4.- Create a program that asks what your numerical grade is on an exam (e.g. 6) and
I indicated the corresponding grade (in the example PASSED).
5.- Create a program that calculates the median of three numbers.
6.- Create a program that sums the entered numbers
7.- Create a program that calculates the factorial of a number
8.- Create a program that calculates arithmetic means.
9.- Create a program that calculates the correlation coefficient of two variables.

SOME SOLVED EXERCISES

1.- Create a program that reads three numbers and indicates which one is the largest.

10 REM ************************ EXERCISE *************************


20 REM ** Read three numbers and write the largest of them **********
30 CLS
40 INPUT "INTRODUCE THREE DIFFERENT NUMBERS (SEPARATED BY COMMAS)", A, B, C
50 IF A > B AND A > C THEN PRINT "THE LARGEST NUMBER IS"; A
60 IF B > A AND B > C THEN PRINT "THE LARGEST NUMBER IS"; B
70 IF C > A AND C > B THEN PRINT "THE LARGER NUMBER IS"; C
80 END

3.- Create a program that allows deciding whether two words are the same or different.
10 REM *EQUALITY OF WORDS PROGRAM*
20 INPUT "Enter two words (Separated by commas)", X$, Y$
30 IF X$ = Y$ THEN
40 PRINT "The two words are the same"
50 ELSE
60 You have written two different words
70 END IF
80 END

4.- Create a program that asks for your numerical grade on an exam (e.g., 6) and
I indicated the corresponding grade (in the example PASSED).

10 REM ******** GRADES PROGRAM ***************


20 INPUT "WHAT HAS BEEN YOUR EXAM SCORE? ", GRADE
30 IF NOTA < 5 THEN PRINT "YOU HAVE OBTAINED A FAIL"
IF NOTA >= 5 AND NOTA < 7 THEN PRINT "YOU HAVE OBTAINED A PASS"
50 IF GRADE >= 7 AND GRADE < 9 THEN PRINT "YOU HAVE OBTAINED A GOOD GRADE"
IF NOTA >= 9 AND NOTA < 10 THEN PRINT "YOU HAVE OBTAINED A DISTINCTION"
70 IF NOTA = 10 THEN PRINT "CONGRATULATIONS, YOU HAVE OBTAINED AN HONORS DEGREE"
80 END
7.- Create a program that calculates the factorial of a number
10 REM ********************* EXERCISE **************************
20 REM ****** Program for calculating factorial ****************
30 CLS
40 REM ********* VARIABLE INITIALIZATION ********************
50 FACT = 1
60 PRINT "THIS PROGRAM CALCULATES THE FACTORIAL OF A NUMBER"
70 INPUT "ENTER AN INTEGER ", NUM
80 IF NUM > 34 THEN PRINT "ONLY CALCULATE FACTORIALS FOR LESS THAN"
35": GOTO 70
90 FOR I = 1 TO NUM
100 FACT = FACT * I
110 NEXT I
120 CLS
130 PRINT
140 PRINT "THE FACTORIAL OF"; NUM; "IS"; FACT
150 END

8.- Create a program that calculates arithmetic averages.


10 REM *******************************
20 REM **CALCULATION OF MEAN AND VARIANCE**
30 REM *******************************
40 REM *INITIALIZATION OF VARIABLES*
50 SUMATORIO = 0
60 SUMATORIO2 = 0
70 REM *DATA ENTRY*
80 CLS
90 PRINT "THIS PROGRAM CALCULATES THE AVERAGE AND VARIANCE"
100 INPUT "HOW MANY DATA WILL YOU ENTER"; NUMBER
110 FOR X = 1 TO NUMBER
120 INPUT "ENTER A DATA ", DATA
SUMATORIO = SUMATORIO + DATO
SUMATORIO2 = SUMATORIO2 + DATO * DATO
150 NEXT X
160 REM *CALCULATE*
170 MEDIA = SUM / NUMBER
180 VARIANCE = (SUMMATION2 / NUMBER) - (MEAN * MEAN)
190 REM *RESULTS OUTPUT*
200 PRINT
210 PRINT
220 PRINT "MEDIA="; MEDIA
230 PRINT "VARIANCE="; VARIANCE
240 END
9.- Create a program that calculates the correlation coefficient of two variables.
10 REM *****************************************************
20 REM **CALCULATION OF PEARSON'S CORRELATION COEFFICIENT**
30 REM *****************************************************
40 REM **************INITIALIZATION OF VARIABLES**********
50 SUMATORIOA = 0
60 SUMATORIOA2 = 0
61 SUMATORIOB = 0
62 SUMATORIOB2 = 0
63 SUMPROD = 0
70 REM ***************DATA ENTRY********************
80 CLS
90 PRINT "THIS PROGRAM CALCULATES THE CORRELATION COEFFICIENT OF
PEARSON
100 INPUT "HOW MANY PAIRS OF DATA ARE YOU GOING TO ENTER?"; NUMBER
110 FOR X = 1 TO NUMBER
120 PRINT "ENTER THE PAIR OF DATA (SEPARATED BY COMMAS) N§";
X
121 INPUT DATA1, DATA2
130 SUMATORIOA = SUMATORIOA + DATA1
SUMATORIOA2 = SUMATORIOA2 + DATO1 * DATO1
141 SUMATORIOB = SUMATORIOB + DATO2
142 SUMATORIOB2 = SUMATORIOB2 + DATO2 * DATO2
143 SUMPROD = SUMPROD + DATA1 * DATA2
150 NEXT X
160 REM ***************CALCULATE***************************
170 MEDIAA = SUMATORIOA / NUMBER
180 VARIANCEA = (SUMATORIOA2 / NUMBER) - (MEDIAA * MEDIAA)
181 MEDIAB = SUMATORIOB / NUMBER
(SUMATORIOB2 / NUMBER) - (MEANB * MEANB)
183 NUMERATOR = (NUMBER * SUMPROD) - (SUMMATIONA * SUMMATIONB)
184 ROOT1 = NUMBER * SUMMATIONA2 - SUMMATIONA ^ 2
185 ROOT2 = NUMBER * SUMMATIONB2 - SUMMATIONB ^ 2
186 PEARSON = NUMERATOR / ((ROOT1 ^ (1 / 2)) * (ROOT2 ^ (1 / 2)))
190 REM ***************OUTPUT RESULTS********************
200 CLS
210 PRINT
211 PRINT " FIRST VARIABLE"
220 PRINT " MEDIA="; MEDIAA
230 PRINT " VARIANCE="; VARIANZAA
231 PRINT
SECOND VARIABLE
250 PRINT " MEDIA="; MEDIAB
260 PRINT " VARIANCE="; VARIANCEB
270 PRINT
280 PRINT " PEARSON CORRELATION COEFFICIENT"
290 PRINT " r(x,y)= "; PEARSON
300 END

You might also like