Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me with ma lil problem
#1
Trying for last few weeks to find out how to get ma program i designed for College to read specific data from ma database.
when program finished should show Pass Mark of 40% should output the following:-

· The number of students taking the exam.
· The number of students passing the exam.
· The number of students failing the exam.
· The average mean examination mark.
· The average examination pass mark.

TEST DATA Smith=70 , Peters=35, Osborne=45, Jenkins=53, Evans=40, Davies=51, Adams=75


included to code below.


REM STUDENT SCORES

SCREEN 13
FOR t = 1 to 255
COLOR t
PRINT "o"
NEXT t

[b][b]CLS
TYPE studentType
Lastname AS STRING * 30
Mark AS INTEGER
END TYPE
DIM student AS studentType


PRINT "1.) Create new recordset"
PRINT "2.) View existing recordset"
PRINT "3.) Students that passed"
INPUT "Which option? ", selection%


IF selection% = 1 THEN
INPUT "How many students are there? ", numRecords%
recordLen# = LEN(student)
OPEN "e:\database.dat" FOR RANDOM AS #1 LEN = recordLen#
FOR i% = 1 TO numRecords%
CLS
INPUT "Last name: ", student.Lastname
INPUT "Mark: ", student.Mark
PUT #1, , student
NEXT i%
CLS
CLOSE #1
PRINT "Recordset creation complete"
END
END IF

IF selection% = 2 THEN
recordLen# = LEN(student)
OPEN "e:\database.dat" FOR RANDOM AS #1 LEN = recordLen#
format$ = "\ \ ### "
PRINT "Last name Mark "
PRINT "------------------ -----"
DO WHILE NOT EOF(1)
GET #1, , student
PRINT USING format$; student.Lastname; student.Mark
LOOP
CLOSE #1
END
END IF

IF selection% = 3 THEN
recordLen# = LEN(student)
OPEN "e:\database.dat" FOR RANDOM AS #1 LEN = recordLen#
ELSEIF Mark >= 40 THEN
format$ = "\ \ ### "
PRINT "Last name Mark "
PRINT "------------------ -----"
DO WHILE NOT EOF(1)
GET #1
PRINT USING format$; student.Lastname; student.Mark
LOOP
CLOSE #1
END
END IF
Reply
#2
This should get you started. Let me know if you have any trouble following this code.

[syntax="QBASIC"]
'THIS IS JUST A QUICK REWRITE OF ALPHASTORM900'S STUDENT SCORE DATABASE
'PROGRAM. I ADDED SOME SMALL STUFF, LIKE ONLY LETTING THE USER ENTER CERTAIN
'OPTIONS AT THE MENU, AND REPLACING THE IF BLOCK WITH A SELECT CASE BLOCK.
'ALSO, I USE ONLY ONE OPEN / CLOSE STATEMENT INSTEAD OF THREE SEPARATE ONES.
'I MOVED THE FILE TO A CONSTANT, SO REMEMBER TO CHANGE THE PATH BACK TO E:
'FOR FURTHER TESTING. LET ME KNOW IF THERE ARE ANY PROBLEMS OR QUESTIONS.
'
' - Written 04/07/2005 by mb

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Define the filepath and filename.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CONST FileName$ = "database.dat"

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Change to graphics mode [320x200].
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
SCREEN 13

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Define record template StudentType; Define record Student as StudentType.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
TYPE StudentType
LastName AS STRING * 30
Mark AS INTEGER
END TYPE
DIM Student AS StudentType
DIM NoName AS STRING * 30

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Open the file.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
OPEN FileName$ FOR RANDOM AS #1 LEN = LEN(Student)

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Display menu of options and get selection (Menu%) from user.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
PRINT "1.) Create new recordset"
PRINT "2.) View existing recordset"
PRINT "3.) Students that passed"
PRINT "4.) Quit"
PRINT
PRINT "Which option?"
DO
Menu% = VAL(INKEY$)
LOOP UNTIL Menu% >= 1 AND Menu% <= 4

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'React to selection.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
SELECT CASE Menu%

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Create new recordset.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CASE 1
INPUT "How many students are there? ", NumOfStudents%
FOR i% = 1 TO NumOfStudents%
CLS
INPUT "Last name: ", Student.LastName
INPUT "Mark: ", Student.Mark
PUT #1, i%, Student
NEXT i%
CLS
PRINT "Recordset creation complete"

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'View existing recordset, or just students that passed.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CASE 2, 3
format$ = "\ \ ###"
PRINT "Last name Mark "
PRINT "------------------ -----"
DO WHILE NOT EOF(1)
i% = i% + 1
GET #1, i%, Student

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'If Menu%=2, list all student. If Menu%=3, list passing ones.
'Remember: check for the EOF record, where LastName is blank!
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IF Menu% = 2 OR (Menu% = 3 AND Student.Mark >= 40) THEN
IF Student.LastName <> NoName THEN
PRINT USING format$; Student.LastName; Student.Mark
END IF
END IF
LOOP
PRINT "Done."

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Quit the program.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CASE 4
PRINT "Quitting..."

END SELECT

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Close the file and pass control back to OS.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CLOSE #1
SYSTEM
[/syntax]
Reply
#3
The answer to your question is complicated, and your problems are all contained in your last paragraph, the IF selection% = 3 THEN. A few comments are in order, as follows:

1. Your ELSEIF Mark >= 40 THEN is premature, as, at this point, nothing has been read from the file. Then, Mark by itself has not been defined!, and you must use student.Mark

2. You must test for student.Mark >= 40 only after reading each record, that is, after the GET #1.

3. GET #1, by itself, will get you nothing! You must tell the program what you want it to get, thus, GET #1, student.

4. Just joking, but, in my time, 40 was NOT passing!

5. No indenting!!! Indenting, while not required for a program to work, IS required for us poor humans to understand what is going on! ALWAYS indent, as shown in my recoding below.

6. A few more things, here and there, for instance, the spaces between your printing of Last Name and Mark is inadequate, and defining format$ = "\ \ ### " inside your loop is a waste, as it only needs to be defined once, [i]outside[/]of any loop.

Here is the Selection # part of your code, reworked into the following, which works:

Code:
IF selection% = 3 THEN
  format$ = "\ \ ### "      
  recordLen# = LEN(student)
  OPEN "e:\database.dat" FOR RANDOM AS #1 LEN = recordLen#
    PRINT "Last name        Mark "
    PRINT "------------------ -------"
    DO WHILE NOT EOF(1)
      GET #1, , student
      IF student.Mark >= 40 THEN
        PRINT USING format$; student.Lastname; student.Mark
      END IF
    LOOP
  CLOSE #1
  END
END IF
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#4
Meg,

You're always ready and able to turn an ugly toad into a prince of a program. Nice work!
*****
Reply
#5
Thx Meg helpped me Greatly. Smile
Reply
#6
just wandering if ne can point me in way of how add mean examination mark and average exam pass mark. or maybe point to m=place where i can get help e.g book ref, or site thx Big Grin
Reply
#7
Quote:1. add mean examination mark
2. average exam pass mark
How do you define these quantities ( in real life i.e. )?
Reply
#8
1. all marks added together divided by number of records
2. same as above but just the marks bove 40
Reply
#9
so... just think about your answers... the first one translates into code easily... the scond one requires the knowledge of comparison symbols, like "<" less than, or ">" greater than. the program sees 22 < 30 as true (-1) because 22 less than 30, get it?

so if grade > needed to pass then print whatever u need to , get it? ;p
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)