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

Need to read a list of named and grades from a text file . The file will be user

ID: 3547238 • Letter: N

Question

Need to read a list of named and grades from a text file. The file will be user-specified. I need then to print out original list, the list of names and grades                     in order by grade. I have to print the number of A's, B's, C's D's, F's and the average, highest and lowest grade. So if the data is as follows: Joe 45, Jim                     55, Sam 90, Ace 95, Bill 75. Then the output will be: Joe 45, Jim 55, Sam 90, Ace 95, Bill 75.....Ace 95, Sam 90, Bill 75, Jim 55, Joe 45.....There were 2 A's,                     There were 0 B's, There was 1 C, There was 1 D, There was 1 F. Highest 95, Lowest 45, Average 60.0. Must use functions. Commenst must be included. Variables                     within functions must be local.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void selectSort(int list[],string name[], int n)
{
     //STEP 1: repeat each position toFill from 0 to n-2
for(int toFill=0; toFill<=n-2; toFill++)
{
    //STEP 2.1:intialize smallPos to toFill
    int smallPos = toFill;
    // STEP 2.2: repeat pos ranging from toFill to n-1
    for(int pos = toFill; pos<=n-1; pos++)
    {
            //STEP 2.3: if list[pos] is smaller than list[smallPos]
        if(list[pos]<list[smallPos])
        //STEP 2.4 copy pos to smallPos
        smallPos = pos;
    } // end for
    // STEP 3: if smallPos not equal to toFill swap list[smallPos] to list[toFill]
    if(smallPos!=toFill)
    {
    int temp = list[smallPos];
    list[smallPos] = list[toFill];
    list[toFill] = temp;
    string local_name = name[smallPos];
    name[smallPos] = name[toFill];
    name[toFill] = local_name;
    }
} //end for
}

void calculate_grades(int grade[],int grade_letter[],int count)
{
for(int i=0; i<count; i++)
{
if(grade[i]>=90 && grade[i]<=100)
grade_letter[0]++;
if(grade[i]>=80 && grade[i]<=89)
grade_letter[1]++;
if(grade[i]>=70 && grade[i]<=79)
grade_letter[2]++;
if(grade[i]>=60 && grade[i]<=69)
grade_letter[3]++;
else
grade_letter[4]++;
}
}

int main()
{
ifstream infile;
string file_name;
string student_name[10];
int grade[10];
int grade_letter[5]={0};
int count=0;
cout << "Enter file name to open :";
cin >> file_name;
cout << endl;
infile.open(file_name.c_str());
if(!infile)
{
cout << "Unable to open file" << file_name << endl;
return 0;
}
while(!infile.eof())
{
infile >> student_name[count]>> grade[count];
count++;
}
selectSort(grade,student_name,count);
double sum=0;
for(int i=0; i<count; i++)
{
cout << student_name[i] << " " << grade[i] << endl;
sum = sum+grade[i];
}
calculate_grades(grade,grade_letter,count);
for(int i=0; i<5; i++)
{
cout <<"There were "<< grade_letter[i] <<" "<< static_cast<char> (i+65)<<" 's " << endl;
}
cout <<"Highest " << grade[count-1] << endl;
cout <<"Lowest "<< grade[0] << endl;
cout <<"Average " << sum/count << endl;
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