Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I do not know how to start this (and I can\'t use arrays): // Program Average ca

ID: 3627488 • Letter: I

Question

I do not know how to start this (and I can't use arrays):

// Program Average calculates the average of five test scores where the
// lowest score is dropped for each student. The program also calculates
// a class average.

#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;
// void function prototypes go here

int main()
{
ifstream inData; // input file
ofstream outData; // output file
string studentID; // student ID number
int numStudents; // number of students in file
int t1; // test 1 score
int t2; // test 2 score
int t3; // test 3 score
int t4; // test 4 score
int t5; // test 5 score
int lowestTest; // lowest test score
double average; // average of 4 highest tests
double sumOfAverages; // sum of the averages of all students
double classAverage; // average for class


inData.open("e:\chap7\data1.txt"); //CHANGE THE PATH FOR YOUR STORAGE DEVICE
outData.open("e:\chap7 esults.txt"); //CHANGE THE PATH FOR YOUR STORAGE DEVICE

outData << fixed << showpoint;
Initialize(numStudents, sumOfAverages);

GetData(inData, studentID, t1, t2, t3, t4, t5);
if (!inData)
{
cout << "File not found" << endl;
getch();
}
else
{
while (inData)
{
FindLowest(t1, t2, t3, t4, t5, lowestTest);
CalcAverage(t1, t2, t3, t4, t5, lowestTest, average);
PrintResults(outData, studentID, t1, t2, t3, t4, t5, average);
AccumulateClassInfo(numStudents, average, sumOfAverages);
GetData(inData, studentID, t1, t2, t3, t4, t5);
}
}
CalcClassAverage(numStudents, sumOfAverages, classAverage);
PrintClassInfo(outData, numStudents, classAverage);

return 0;
}
//**********************************************************************
// Initialize function heading goes here

//Preconditions: none
//Postconditions: The counter and accumulator are set to zero
{
// function body goes here
}
//**********************************************************************
// GetData function heading goes here

//Preconditions: The file is open and ready to be read from
//Postconditions: The studentID and the five test grades have been read
{
// function body goes here
}
//**********************************************************************
// FindLowest function heading goes here

//Preconditions: The five test grades have been read
//Postconditions: The lowest grade is found
{
// function body goes here
}
//**********************************************************************
// CalcAverage function heading goes here

//Preconditions: The five test grades have been read
// The lowest test grade is known
//Postconditions: The average of the four best grades is calculated
{
//function body goes here
}
//**********************************************************************
// PrintResults function heading goes here

//Preconditions: The output file is open and ready to be written to
// The student ID and the five test grades have been read
// The average of the four best test grades has been calculated
//Postconditions: The student ID, the five test grades, and the calculated
// average (with 2 decimal points) have been written to a file
{
//function body goes here
}
//**********************************************************************
// AccumulateClassInfo function heading goes here

//Preconditions: The current number of students is known
// The current accumulated average is known
//Postconditions: The number of students is incremented
// The new average is added to the total
{
// function body goes here
}
//**********************************************************************
// CalcClassAverage function heading goes here

//Preconditions: All data has been process and the number of students
// and the sum of class averages is known
//Postconditions: The class average is calculated
{
// function body goes here
}
//**********************************************************************
// PrintClassInfo function heading goes here

//Preconditions: The output file is open and all data has been processed
// The number of students and the class average is known
//Postconditions: The number of students and class average (with 2 decimal
// places) has been written to the file
{
// function body goes here
}

Please help.

Explanation / Answer

// Program Average calculates the average of five test scores where the // lowest score is dropped for each student. The program also calculates // a class average. #include <iostream> #include <conio.h> #include <fstream> #include <iomanip> #include <string> using namespace std; // void function prototypes go here void initialize(int &numStudents, double &sumOfAverages) //Preconditions: none //Postconditions: The counter and accumulator are set to zero { numStudents = 0; sumOfAverages = 0.0; } void GetData(ifstream &inData, string &studentID, int &t1, int &t2, int &t3, int &t4, int &t5) //Preconditions: The file is open and ready to be read from //Postconditions: The studentID and the five test grades have been read { inData >> studentID >> t1 >> t2 >> t3 >> t4 >> t5; } int FindLowest(int t1, int t2, int t3, int t4, int t5) //Preconditions: The five test grades have been read //Postconditions: The lowest grade is found { int lowest = t1; if(lowest > t2) lowest = t2; if(lowest > t3) lowest = t3; if(lowest > t4) lowest = t4; if(lowest > t5) lowest = t5; return lowest; } void CalcAverage(int t1, int t2, int t3, int t4, int t5, double &average) //Preconditions: The five test grades have been read //Postconditions: The average of the four best grades is calculated { int total = t1 + t2 + t3 + t4 + t5; total -= FindLowest(t1, t2, t3, t4, t5); average = (total / 4.00); } void PrintResults(ofstream &outData, string studentID, int t1, int t2, int t3, int t4, int t5, double average) //Preconditions: The output file is open and ready to be written to // The student ID and the five test grades have been read //Postconditions: The student ID, the five test grades, and the calculated // average (with 2 decimal points) have been written to a file { outData << studentID << ": " << t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 << " avg: " << average << endl; cout << studentID << ": " << t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 << " avg: " << average << endl; } void AccumulateClassInfo(int &numStudents, double &sumOfAverages, double average) //Preconditions: The current number of students is known // The current accumulated average is known //Postconditions: The number of students is incremented // The new average is added to the total { sumOfAverages += average; numStudents++; } void CalcClassAverage(int numStudents, double sumOfAverages, double &classAverage) //Preconditions: All data has been process and the number of students // and the sum of class averages is known //Postconditions: The class average is calculated { classAverage = sumOfAverages / numStudents; } void PrintClassInfo(ofstream &outData, int numStudents, double classAverage) //Preconditions: The output file is open and all data has been processed // The number of students and the class average is known //Postconditions: The number of students and class average (with 2 decimal // places) has been written to the file { outData << "Total students in class: " << numStudents << " and class average: " << classAverage; cout << "Total students in class: " << numStudents << " and class average: " << classAverage; } int main() { ifstream inData; // input file ofstream outData; // output file string studentID; // student ID number int numStudents; // number of students in file int t1; // test 1 score int t2; // test 2 score int t3; // test 3 score int t4; // test 4 score int t5; // test 5 score double average; // average of 4 highest tests double sumOfAverages; // sum of the averages of all students double classAverage; // average for class inData.open("data.txt"); //CHANGE THE PATH FOR YOUR STORAGE DEVICE outData.open("results.txt"); //CHANGE THE PATH FOR YOUR STORAGE DEVICE if (!inData) { cout << "File not found" << endl; system("pause"); } else { initialize(numStudents, sumOfAverages); outData << fixed << showpoint << setprecision(2); while (inData) { GetData(inData, studentID, t1, t2, t3, t4, t5); CalcAverage(t1, t2, t3, t4, t5, average); PrintResults(outData, studentID, t1, t2, t3, t4, t5, average); AccumulateClassInfo(numStudents, sumOfAverages, average); } } CalcClassAverage(numStudents, sumOfAverages, classAverage); PrintClassInfo(outData, numStudents, classAverage); cout << endl << "Done!"; system("pause"); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote