input file and array?

need help i cant figure this out, my teacher wants us to read this in from a file:
TFFTTTFTFTFFTTFTTTFF
ALU76359 TFTFTFTFTFTFTFTFTFTF
CPU98563 TFFTTTFTFTFFTTFFFTFF
RAM69522 TFFTTTFT FFTTFTTTFF
GPS22105 TFFTTTFTFTFTTTTTTTTT
GPU67851 FFFFFFFFFFFFFFFFFFFF
DUM00001 T F T F T F T F T F
IBM99887 FTTF FTTFFTFFFTT
MAC78899 FTFTFT TFTFTF FTFTFT

the top line are the correct answers and the rest are students answered the questions, we have to use arrays. if anyone could help that would be great. :)

Well, it depends what you actually want to do.

Do you want to mark these students?
One by one ... or do you want to store all the marks and do subsequent analysis (like, fraction of correct marks for Q1 etc)?

Be more precise ... and provide some initial code, indicating what you are trying to do.


You could (but there are plenty of alternatives):
- read the first line into either a char array (20+1 elements) ... or alternatively a string
- loop round reading one line of a file ...
for each ... putting the first 8 chars into a studentID, skipping a blank, putting the rest into a char array of studentAnswers.

So, choose your approach first - and have an idea what you want at the end. Such as:

Correct:              Answer [TFFTTTFTFTFFTTFTTTFF]

Student: ALU76359     Answer [TFTFTFTFTFTFTFTFTFTF]     Mark:  7
Student: CPU98563     Answer [TFFTTTFTFTFFTTFFFTFF]     Mark: 18
Student: RAM69522     Answer [TFFTTTFT FFTTFTTTFF ]     Mark: 13
Student: GPS22105     Answer [TFFTTTFTFTFTTTTTTTTT]     Mark: 16
Student: GPU67851     Answer [FFFFFFFFFFFFFFFFFFFF]     Mark:  9
Student: DUM00001     Answer [T F T F T F T F T F ]     Mark:  9
Student: IBM99887     Answer [FTTF FTTFFTFFFTT    ]     Mark:  4
Student: MAC78899     Answer [FTFTFT TFTFTF FTFTFT]     Mark: 11

Total number of students = 8

Question / percentage correct:
 1    62.5
 2    62.5
 3    75.0
 4    50.0
 5    62.5
 6    50.0
 7    62.5
 8    62.5
 9    62.5
10    37.5
11    75.0
12    50.0
13    62.5
14    25.0
15    50.0
16    50.0
17    50.0
18    37.5
19    62.5
20    37.5
Last edited on
Topic archived. No new replies allowed.