Program to be revised at the bottom #include<iostream> #include<fstream> #includ
ID: 3688968 • Letter: P
Question
Program to be revised at the bottom
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void openFile(ifstream & inFile);
void readArray(ifstream & inFile, double numbers[], int & score);
void determineHighLow(double numbers[], int scores, double & high, double & low);
void calculateScore(double numbers[], int count, double high, double low, double &sum);
void displayScore(double total);
int main()
{
double high, low, total, sum;
int score;
ifstream inFile;
int count = 0;
const int SCORES = 10;
double numbers[SCORES];
openFile(inFile);
readArray(inFile, numbers, score);
determineHighLow(numbers, score, high, low);
calculateScore(numbers, score, high, low, sum);
displayScore(sum);
system("pause");
return 0;
}
void openFile(ifstream & inFile)
{
inFile.open("scores.txt");
if (!inFile)
{
cout << "Can't find the input file" << endl;
system("pause");
exit(-1);
}
}
void readArray(ifstream & inFile, double numbers[], int & score)
{
score = 0;
while (!inFile.eof())
{
inFile >> numbers[score];
score++;
}
}
?
void determineHighLow(double numbers[], int count, double &high, double &low)
{
high = numbers[0];
low = numbers[0];
for (int i = 0; i < count; i++)
{
if (numbers[i] > high)
{
high = numbers[i];
}
else if (numbers[i] < low)
{
low = numbers[i];
}
}
cout << "Dropped Scores " << high << " " << low << endl;
}
void calculateScore(double numbers[], int count, double high, double low, double & sum)
{
sum = 0;
for (int i = 0; i < count; i++)
{
sum = sum + numbers[i];
}
sum = sum - high - low;
}
void displayScore(double total)
{
cout << "Received score is " << total << endl;
}
Explanation / Answer
Here is the code for you:
#include<iostream>
#include<vector>
#include<fstream>
#include<cstring>
using namespace std;
void openFile(ifstream &inFile);
void readArray(ifstream & infile, vector<double>numbers, int & score);
void determineHighLow(vector<double>numbers, const int SCORES, int count, double &high, double &low);
void calculateScore(vector<double>numbers, const int SCORES, int count, double high, double low, double &total);
void displayScore(double total);
int main()
{
double high, low, total;
int score;
ifstream inFile;
int count = 0;
const int SCORES = 8;
vector<double> numbers(SCORES);
openFile(inFile);
readArray(inFile, numbers, score);
determineHighLow(numbers, SCORES, count, high, low);
calculateScore(numbers, SCORES, count, high, low, total);
system("pause");
return 0;
}
void openFile(ifstream &inFile)
{
inFile.open("scores.txt");
if (inFile.fail())
{
cout << "can ' t find the input file" << endl;
system("pause");
exit(-1);
}
}
void readArray(ifstream &inFile, vector<double>numbers, int & score)
{
score = 0;
double oneScore;
while (!inFile.eof())
{
inFile >> oneScore;
numbers.push_back(oneScore);
score++;
}
}
void determineHighLow(vector<double> numbers, const int SCORES, int count, double &high, double &low)
{
high = numbers.at(0);
low = numbers.at(0);
for (int I = 0; I < count; I++)
{
if (numbers.at(I) > high )
{
high = numbers.at(I);
}
else if (numbers.at(I) < low)
{
low = numbers.at(I);
}
}
cout << "Dropped Scores " << high << " " << low << endl;
}
void calculateScore(vector<double>numbers, const int SCORES, int count, double high, double low, double &total)
{
total = 0;
for (int i = 0; i < count; i++)
{
total = total + numbers.at(i);
}
total = total - high - low;
}
void displayScore(double total)
{
cout << "Received score is " << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.