I need help with this assignment.
Program 7
You are to write a program that will compute your CS1428 quiz average after you have selected a quiz to drop.
The program should read input from a data file named “quizinfo.txt” where each line of the file contains
quiz number maximum points on the quiz points earned on the quiz
The above are separated by tabs.
Note: Both point values should be float or double as some quizzes may have ½ points earned
You can assume that there will be no more than 12 quizzes. (Use a Named Constant for this)
The end of the data is indicated by a negative quiz number and 0s for the other two data values on the line.
Do not allow your program to run off the end of arrays!!
Note: This is a sentinel value read. Please do it correctly.
The data is displayed to the user where they can then select a quiz number to 'drop'. The quiz average with the
dropped quiz is then displayed to the nearest whole number. A statement similar to the following should be used to
output the average:
“If you drop quiz <quiz #> then your quiz average will be <calculated average>.”
The user should be allowed to repeat the process with another quiz selection until they elect to exit the program
by entering a negative value for the quiz number.
You should validate the input file open.
The usual style requirements of header comment format, variable description, indentation, etc. should be followed.
All output is to the screen/console.
This program is due on THURSDAY, November 1, by the start of class.
Advice: On paper – list the tasks the program should perform in the order they need to be performed. Then (in
English or pseudo Code/English) expand each task.
Example of input file content:
0 27 14
1 14 11
2 30 24
3 34 31
4 9 7
5 14 10
-1 0 0
This is what i have so far
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
|
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
const int VALUES= 13; // the array that will hold the values
int Quiz[VALUES]; // quiz number
double MaxPoints[VALUES]; // max points on quiz
double PointsEarned[VALUES]; // points earned on quiz
const int SENTINEL = -1; // sentinel value
int Count =0; // counts the number of quizzes
double SumTotal =0; // the total number of points possible
double SumEarned =0;
double average;
int QuizNum;
ifstream input;
input.open("quizinput.txt");
if(Quiz[Count])
{
input >> Quiz[Count];
while ( QuizNum != SENTINEL && Quiz[Count <= 13])
{
Count ++;
for(int i =0; i <= Quiz[13]; i++)
{
input >> MaxPoints[i];
SumTotal += MaxPoints[i];
input >> PointsEarned[i];
SumEarned += PointsEarned[i];
}
for(int i =0; i<= Count; i ++)
{
input >> Quiz[i-1];
input >> MaxPoints[i-1];
input >> PointsEarned[i-1];
cout << Quiz[i] << " " << MaxPoints[i]<<
" " << PointsEarned[i] <<endl << endl;
}
cout << "What Quiz would you like to drop ?" << endl;
cin >> QuizNum;
average = static_cast<double> (SumTotal - MaxPoints[QuizNum])/
SumEarned - PointsEarned[QuizNum];
cout << "If you drop quiz " << QuizNum <<
" then your quiz average will be "<< average << endl;
}
}
else
{
cout << " The input file did not open ";
return -1;
}
return 0;
}
|
Please help as quickly as possible