WASSCE ICT Elective QBasic Question 2018 [Solved]

(Last Updated On: )
REM QBasic Code to Assign Grades Based on Examination Scores

DIM indexNumber AS INTEGER
DIM subject AS STRING
DIM score AS INTEGER
DIM grade AS STRING

REM Accept student details
INPUT "Enter Student Index Number: ", indexNumber
INPUT "Enter Subject: ", subject
INPUT "Enter Examination Score (out of 100): ", score

REM Determine grade based on the score
IF score >= 90 THEN
    grade = "A"
ELSEIF score >= 80 THEN
    grade = "B"
ELSEIF score >= 70 THEN
    grade = "C"
ELSEIF score >= 60 THEN
    grade = "D"
ELSEIF score >= 50 THEN
    grade = "E"
ELSE
    grade = "F"
END IF

REM Display the grade
PRINT "Student Index Number: "; indexNumber
PRINT "Subject: "; subject
PRINT "Examination Score: "; score
PRINT "Grade: "; grade

END

Explanation:

  • DIM indexNumber AS STRING, DIM subject AS STRING, DIM score AS INTEGER: Declare variables to store the student’s index number, subject, and examination score.
  • INPUT “Enter Student Index Number: “, indexNumber: Prompt the user to enter the student’s index number and store it in the indexNumber variable.
  • INPUT “Enter Subject: “, subject: Prompt the user to enter the subject and store it in the subject variable.
  • INPUT “Enter Examination Score (out of 100): “, score: Prompt the user to enter the examination score and store it in the score variable.
  • IF score >= 90 THEN…END IF: Check the score against various grade boundaries using IF…ELSEIF…ELSE statements and assign the appropriate grade to the grade variable.
  • PRINT “Student Index Number: “; indexNumber: Display the student’s index number on the screen.
  • PRINT “Subject: “; subject: Display the subject on the screen.
  • PRINT “Examination Score: “; score: Display the examination score on the screen.
  • PRINT “Grade: “; grade: Display the calculated grade on the screen.

Feel free to run this code in a QBasic environment to test its functionality!

Likes:
Views:
303

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!