hello, I am new to c++ and need help with this code. If anyone could help it would be very much appreciated. thanks!
1 2 3 4 5 6 7 8 9
Write a complete program to input a series of test grades from a file named test.txt and report the number of student grades, the number of AS, BS, CS, DS, and FS, the percent below average (DS and FS) and the percent above average (AS and BS).
For the file test.txt as follows: Section-001
A C F F D B B C C C A C C B B C D
Section-005
C F F D B F C C C A C A B B A D Output should be: 33 student grades
A: 5 B: 7 C: 12 D: 4 F: 5
Above average: 36.36%
Below average: 27.27%
I think that, to get sample code from forum members you need to show a decent attempt at the problem first.
However, to get you started, imagine what you would do if you were doing this statistics problem by hand.
- You would probably keep a set of 6 tallies to accumulate your counts for each grade (A,B,C,D,E,F). In C++ this would be an int array of size 6, each initialised to 0.
- you would pick up your piece of paper (in C++, open a file)
- you would go along reading one (char) mark at a time and incrementing the corresponding tally (in C++, add 1 to the relevant array element)
- think how you would tell if you had come to the end of the marks.
By now, you have the tally for each mark - that part is done.
At this point, we are missing information. What is "average"? Is it something supplied from outside (e.g. "average" is a grade C - probably the case here) or do you compute it from your numbers? (If so, how?)
Could you also post the exact, formatted, contents of test.txt. This will affect how you read the marks.
Have a go and we'll look at it. (There are good tutorials on, e.g., reading files, setting up arrays, on this site. You may also want to scan over other posts in the Beginners' forum: there are many people trying to do similar things.)
Is your .txt file just letter grades or do the phrases 'Section-001', 'Section-005' appear in it as well? In that case they need to be removed while the grades are being read