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

<p>C++ Programming: From Problem Analysis to Program Design (5th)</p> <p><br />

ID: 3624711 • Letter: #

Question

<p>C++ Programming: From Problem Analysis to Program Design (5th)</p>
<p><br /> <br /></p>
<p>Ch. 11 #2 <br />Write a program that reads students' names followed by their test scores. The program should output each student's name followed by the tests and the relevant grade. it should also find and print the highest test score and the name of the students having the highest test score.<br />Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use and array of 20 components of type studentType</p>
<p><br /> <br /></p>
<p>Your program must contain at least the following functions:</p>
<p><br /> <br /></p>
<p>a.&#160; A function to read the student's data into the array</p>
<p><br /> <br /></p>
<p>b.&#160; A function to assign the relevant grade to each student</p>
<p><br /> <br /></p>
<p>c.&#160; A function to find the highest test.</p>
<p><br /> <br /></p>
<p>d.&#160; A function to print the names of the students having the highest test score.</p>
<p><br /> <br /></p>
<p>Your program must output each student's name in this form: last name following by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.</p>

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct studentType
{string studentFName;
string studentLName;
int testScore;
char grade;
};
void input(ifstream&,studentType[],int);
void calculate(studentType[],int);
int gethighest(studentType[],int);
void output(ofstream&,studentType[],int);
int main()
{ifstream in;
ofstream out;
studentType stu[20];
char filename[30];
cout<<"what is the name of the input file you are using? ";
cin>>filename;
in.open(filename);           //open file
if(in.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        return 1;
        }
cout<<"what is the name of the output file you are using? ";
cin>>filename;
out.open(filename);
input(in, stu, 20);
calculate(stu, 20);
output(out, stu, 20);
out.close();
in.close();
return 0;
}
void input(ifstream& in,studentType stu[],int n)
{int i;
for(i=0;i<n;i++)
in>>stu[i].studentFName>>stu[i].studentLName>>stu[i].testScore;

}
void calculate(studentType stu[], int n)
{int i;
for(i=0;i<n;i++)
    {switch(stu[i].testScore/10)
        {case 10:
        case 9:
            stu[i].grade = 'A';
            break;
        case 8:
            stu[i].grade = 'B';
            break;
        case 7:
            stu[i].grade = 'C';
            break;
        case 6:
            stu[i].grade = 'D';
            break;
        default:
            stu[i].grade = 'F';
        }
    }
}
int gethighest(studentType stu[], int n)
{int i,h;
h=stu[0].testScore;
for(i=1;i<n;i++)
   if(h<stu[i].testScore)
       h=stu[i].testScore;
return h;
}
void output(ofstream& out,studentType stu[],int n)
{int max,i;
max=gethighest(stu, n);
out<<"Student Name Test Score Grade ";
for(i=0;i<n;i++)
out<<left<<setw(25)<< stu[i].studentLName + ", " + stu[i].studentFName
                <<right<<" "<<setw(5)<<stu[i].testScore<<setw(15)<<" "<<stu[i].grade<<endl;
out<<"Highest Test Score: "<<max<<endl;
out<<"Students having the highest test score:"<< endl;
for (i = 0; i < n; i++)
     if (stu[i].testScore == max)
       out<< stu[i].studentLName + ", " + stu[i].studentFName<< endl;
}


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