I am having trouble figuring out how to go about this. This is the prompt.
C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name i.e. jSmith). Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student.
Below is an example of what the calculation would be for the program.
score1 * .3 + score2 * .3 + score3 * .4
Inside the main function definition, declare your variables being sure to give them a descriptive name where it is easy for the reader of the code to know what is stored in each. Along with variables for the values you will be reading out of the file you will also need one set up to use with the input file and the output file. These also need to be descriptive so it is obvious as to which file is being used.
In this program the user will not be entering in any data as it will all come to from the file. Likewise, all output will be written to a file so the user will not see anything come to the screen. To keep from the user being confused as if anything happened or not it is always good to give them a ending statement i.e. Something like the following:
Program has completed and the output can be found in 'studentGrade.txt'
Save the contents of the file
This is what I have so far.
And this is the studentinfo.txt
ID SCORES
2437 61 92 79
9065 82 63 95
9816 71 92 59
4607 83 91 95
9747 69 99 61
2481 92 86 59
3893 62 70 71
5735 65 91 68
3735 98 77 68
8085 90 63 97
3247 72 96 89
6548 56 52 56
5859 100 99 68
4740 89 80 97
4424 72 72 69
5494 67 87 70
6114 71 87 96
5700 100 64 79
9890 93 92 92
6786 73 79 97
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <fstream>
using namespace std;
int main (){
ifstream input;
input.open("StudentInfo.txt");
int score1, score2, score3;
input>>score1;
input>>score2;
input>>score3;
cout << "Total score is " << ((score1*.3) + (score2*.3) + (score3*.4)) << endl;
input.close();
cout << "Done" << endl;
ouput.open("Studentgrade.txt");
output <<
return 0;
}
|