You are given a text file (grades.txt) that contains the following grades for a group of students:
Tommy Lane 88 76 52 70 65 80
Mary Smith 90 88 96 90 98 94
Susie Taylor 73 65 68 79 84 92
After the first and last names, the first three grades are homework grades. The next two grades are test grades. The last grade is the final exam grade. Grades are calculated as follows:
Final Exam 20%
The instructor uses a seven-point grade scale:
< 69 F
Write a program that reads the student data from the file and creates a report (to the screen) showing each student’s name (last name, first name), their average (rounded to one decimal place), and their letter grade. If a student’s average would round up to the next grade level, allow them that letter grade. For example, an average of 92.5 would be an A.
I have some code but im just stuck, i need to know whats missing, or if anyone could point me in the right direction.
#include <string> // Required for string type
#include <fstream> // Required for file streams
#include <cstdlib> // Required for exit statement
using namespace std;
ifstream in; // Creation of input file stream
ofstream out; // Creation of output file stream
int main ()
string name; // declaring strings
int score1, score2, score3, score4, score5, score6;
while read data
in >> name >> score1 >> score2 >> score3 >> score4 >> score5 >> score6;
average = CalculateAverage(score1, score2, score3, score4, score5, score6);
double calculateAverage(int score1, score2, score3, score4, score5, score6);
Which of the following does your program do and not do?
- reads the student data from the file
- creates a report (to the screen) showing each student’s name (last name, first name)
- their average (rounded to one decimal place)
- their letter grade.
- round up to the next grade level
Also, an int divided by an int gives an int. What is 3/2? One. What is 11/4? Two. I'm not telling you this just for the fun of it.
1) You want to print last name, first name separately but you are reading only one string. If the format of the names stored in the file are as "Tommy Lane 88 76 52 70 65 80" then you need to read two strings and then print them separately.
2) You say you want to print the report on the screen, but you are opening a file to write to. You dont need to open a file, you can use cout. Something like cout << lastName << ", " << firstName << " " << average << " " << grade << endl;
3) I dont see a problem in "return ((score1+score2+score3+score4+score5+score6)/6;" it should return a double as long as you change the type of the scores to double in the signature (at least g++ and clang++ will). But the resulting value will not be rounded as you want. Use ceil or floor for that, you need to include cmath for this.
If your average is 61.89 then ceil will give you 62 and floor will give you 61.