You are on page 1of 4

CSC 104 Knowledge of the QBASIC programming language:

Practice! And be motivated


Calculate the total monthly net pay of each employee and generate the output report. Write a Basic program to input the records of a file where each record contains the identity of a person, the amount of loan in Naira he obtains (the principal), the interest rate of the loan and the number of payment period per year. The program should compute the loan payment required for each pay period to repay the outstanding principal in one year at the indicated rate in N equal payments. The formula for calculating payment is: Payment = (p(1+k) + 12)/n where p = principal loan k = interest rate n = number of periods per year

Solution Program 10 CLS 20 REM set previous key settings off 30 KEY OFF 40 REM enter the number of the debtors 50 INPUT "please enter the number of debtors to consider ", d 60 CLS 70 DIM A$(d), B$(d), C(d), D(d), E(d), F(d) 80 REM create a FOR and NEXT loop to accept the records of debtors 90 FOR I = 1 TO d 100 INPUT "surname:", A$(I) 110 INPUT "other names:", B$(I) 120 INPUT "principal loan", C(I) 130 INPUT "interest rate", K(I) 140 INPUT "payment period per year:="; E(I) 150 REM compute the payment per period for each debtor 160 F(I) = (C(I) * (1 + K(I)) + 12) / E(I) 170 CLS 180 NEXT I 190 CLS 200 REM print the report 210 FOR I = 1 TO d

Practice make permanent

CSC 104 Knowledge of the QBASIC programming language:

220 PRINT A$(I), B$(I), C(I), K(I), E(I), F(I) 220 NEXT I 230 END Write a Qbasic program to find the root of a quadratic equation using the formula if the result is less than 0 the program should print the root are imaginary and end the program? What are the Disadvantages of qbasic?

Write an algorithm to convert the length in feet to centimeter. Algorithm START Input Length_in_ft Length_in_cm = Length_in_ft x 30 Print Length_in_cm END Write a program to sort ten numbers? Solution: DIM nums(10) CLS FOR i = 0 TO 9 nums(i) = (RND * 10) + 1 PRINT nums(i) NEXT PRINT PRINT "Press Enter to sort numbers" REM pause to look at numbers FOR W=1 TO 100 NEXT W CLS FOR loop1 = 0 TO 9 FOR loop2 = loop1 + 1 TO 9 IF nums(loop1) > nums(loop2) THEN SWAP nums(loop1), nums(loop2) NEXT NEXT FOR i = 0 TO 9 PRINT nums(i) NEXT

Practice make permanent

CSC 104 Knowledge of the QBASIC programming language:

Write a simple but a complete Qbasic that will accept three numbers find the sum and the average of these numbers? How do you create a calculator on QBasic? Solution:Using SELECT/CASE CLS PRINT "Welcome to the QBASIC Calculator!" PRINT "Enter two numbers each separated by a comma: (n,n)" INPUT num1, num2 PRINT "Choose a basic operation:" PRINT "MENU: 1> Add 2> Subtract 3> Multiply 4> Divide" INPUT "Type a menu selection number from 1 to 4"; opNo% SELECT CASE opNo% CASE 1: answer = num1 + num2 CASE 2: answer = num1 - num2 CASE 3: answer = num1 * num2 CASE 4: answer = num1 / num2 END SELECT PRINT "The answer is: "; answer Solution:Using IF/THEN 10 CLS 20 PRINT "Welcome to the QBasic Calculator!" 30 PRINT "Enter two numbers." 40 INPUT nm, nm1 50 PRINT "Choose a basic operation:" 60 PRINT "1. Add 2. Subtract 3. Multiply 4. Divide" 70 INPUT num 80 IF num = 1 THEN 100 90 IF num = 2 THEN 110 91 IF num = 3 THEN 120 92 IF num = 4 THEN 130 100 PRINT "The result is"; nm + nm1 GOTO 140 110 PRINT "The result is"; nm - nm1 GOTO 140 120 PRINT "The result is"; nm * nm1 GOTO 140 130 PRINT "The result is"; nm / nm1 Enter the first of four numbers: Enter the second of four numbers: END 140 END

Q10: Write algorithms and programs that will result in the following outputs. Make use of the INPUT statement. 1.Enter your name Date of Birth Class Output Screen should look like: NameBirth dateClass Baron21/08/001 Production&Meta

Practice make permanent

CSC 104 Knowledge of the QBASIC programming language:

Enter the third of three numbers: Enter the fourth of four numbers: The sum of the numbers is: The Average of the numbers is:
Choose the answer that describes the result when this segment of code is executed. LET X = 3.14159 LET F$ = "#.##" PRINT USING F$;X a. 3.14159 is printed b. 3.1416 is printed c. 3.142 is printed d. 3.14 is printed

Write a program in qbasic to print the multiplication table of 15? Write a FOR loop that finds the average of the numbers between 1 and 1000. Use a PRINT statement to display the answers to the user. Write a Qbasic program which finds the areas of ten rectangles one after the other and prints the results. Use the FOR-TO and NEXT statements Write a Qbasic program which generates the multiples of 5 between 5 and 50 and prints the results. Write a Qbasic program which reads the value of the ages of 60 pupils in a school, finds the sum of the ages, average age of the pupils and prints the number of pupils, sum of their ages and average age. Differentiate the following 1. 2. 3. 4. 5. 6. 7. READ. DATA & INPUT PRINT & PRINT USING VAL & STR$ SINGLE SUBSCRIPTED VARIABLE & DOUBLE SUBSCRIPTED VARIABLE MID$ $ LEFT$ INT & FIX STOP & END

Practice make permanent

You might also like