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

rite a program that reads in a set of students\' scores from a file and writes t

ID: 3626623 • Letter: R

Question

rite a program that reads in a set of students' scores from a file and writes to an output file the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200. If the scores are as follows:

76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149,


Then the output is:

Range Number of Students

0-24 1

25-49 1

50-74 0

75-99 5

100-124 1

125-149 3

150-174 4

175-200 5


MY ANSWER:(it compile but the output is always 0 and please fix the format of the output)


#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

const int MAX_CODE_SIZE = 200;

void getCode(ifstream& infile, int list[], int& length, bool& lenCodeOk);


int main()
{
int codeArray[MAX_CODE_SIZE];

int codeLength;

bool lengthCodeOk;

ifstream infile;
;



infile.open("scores1.txt");


if (!infile)
{
cout << "Can't open the input file" << endl;
return 1;
}


getCode (infile, codeArray, codeLength, lengthCodeOk);

infile.close();

return 0;
}



void getCode(ifstream& infile, int list[], int& length, bool& lenCodeOk)
{
int count;
int value;
int range[8] = {0};


lenCodeOk = true;



if (length > MAX_CODE_SIZE)
{
lenCodeOk = false;
return;
}

value = 0;

for (count = 0; count < length; count++)
{
infile >> list[count];

value = list[count];

if (value >= 0 && value < 25)
range[0]++;
else if(value > 24 && value < 50)
range[1]++;
else if (value > 49 && value < 75)
range[2]++;
else if (value > 74 && value < 100)
range[3]++;
else if (value > 99 && value < 125)
range[4]++;
else if (value > 124 && value < 150)
range[5]++;
else if (value > 149 && value < 175)
range[6]++;
else if (value > 174 && value < 200)
range[7]++;
}

cout << "The number of students with scores 0 - 24 are: " << range[0] << endl;
cout << "The number of students with scores 25 - 49 are: " << range[1] << endl;
cout << "The number of students with scores 50 - 74 are: " << range[2] << endl;
cout << "The number of students with scores 75 - 99 are: " << range[3] << endl;
cout << "The number of students with scores 100 - 124 are: " << range[4] << endl;
cout << "The number of students with scores 125 - 149 are: " << range[5] << endl;
cout << "The number of students with scores 150 - 174 are: " << range[6] << endl;
cout << "The number of students with scores 175 - 200 are: " << range[7] << endl;
cout << endl;
}

Explanation / Answer

hi there u was not give the getcode function the length of the grades in the file so it basically was garbage and the program was not reach the for loop u have and u asked to output the information to an output file and i added this please rate #include #include #include using namespace std; const int MAX_CODE_SIZE = 200; void getCode(int list[], int& length, bool& lenCodeOk); int main() { int codeArray[MAX_CODE_SIZE]; int codeLength; bool lengthCodeOk; ifstream infile; infile.open("test.txt"); if (!infile) { cout 49 && value < 75) range[2]++; else if (value > 74 && value < 100) range[3]++; else if (value > 99 && value < 125) range[4]++; else if (value > 124 && value < 150) range[5]++; else if (value > 149 && value < 175) range[6]++; else if (value > 174 && value < 200) range[7]++; } ofstream out; out.open("out.txt"); cout