Really Stumped!!! Not even sure where to start this is my first attempt at something like this and little info from the videos for a program like this. Here are are the parameters I need to follow not sure how to implement the file?:
2. Use a nested loop structure to read the data from the text file and calculate the student’s average grade.
a. The outer look will be a while loop; the inner loop will be a for loop (4 quizzes)
b. To calculate each student’s average score, use a total variable initialized to 0 before the for loop, then calculate the student’s average after the loop.
c. To calculate the class average, initialize a classTotal variable to 0 before the while loop, add each student’s total into the classTotal following the for loop, then calculate the classAverage after the while loop.
d. Only display 2 decimals for the averages.
3. BEWARE of integer division.
4. Use cout to output the values of the variables to the console. Your cout statement MUST use the variables to display the values
5. Output must be labelled and easy to read as shown in the sample output below.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int x, y, studentID, grade1, grade2, grade3, grade4, average;
int total = 0;
char again = 'Y';
ofstream file;
file.open("grade.txt");
while ( again == 'Y' || again == 'y')
{
for (x = 0; x < 1; x++)
{//enter grades
cout << "Enter student ID#:" << endl;
cin >> studentID;
cout << "Enter grade: " << endl;
cin >> grade1;
if (grade1 <0 || grade1 > 100)
{
cout << "0 - 100 only! Enter again: " << endl;
cin >> grade1;
}
else if (grade1 <= 0 || grade1 >= 100)
{
cout << endl;
}
cout << "Enter grade: " << endl;
cin >> grade2;
if (grade2 <0 || grade2 > 100)
{
cout << "0 - 100 only! Enter again: " << endl;
cin >> grade2;
}
else if (grade2 <= 0 || grade2 >= 100)
{
cout << endl;
}
cout << "Enter grade: " << endl;
cin >> grade3;
if (grade3 <0 || grade3 > 100)
{
cout << "0 - 100 only! Enter again: " << endl;
cin >> grade3;
}
else if (grade3 <= 0 || grade3 >= 100)
{
cout << endl;
}
cout << "Enter grade: " << endl;
cin >> grade4;
if (grade4 <0 || grade4 > 100)
{
cout << "0 - 100 only! Enter again: " << endl;
cin >> grade4;
}
else if (grade4 <= 0 || grade4 >= 100)
{
cout << endl;
}
//file imput
file << studentID << " " << grade1 << " " << grade2 << " " << grade3 << " " << grade4 << endl;
}//stop or continue?
cout << "Enter Y/N to enter another student: " << endl;
cin >> again;
}//while loop ends
while (average <= 0 && average >= 0)
{
for (y = 0; y < average ; y++)
{
}
}
cout << "OK, we will stop here." << endl;
return 0;
}
|