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

Write a program C++ program that reads students’ names followed by their test sc

ID: 3767091 • Letter: W

Question

Write a program C++ program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores 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. 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 an array of 20 components of type studentType. A data file ("StudentData.txt") is attached for you to use in testing. Your program must output each student’s name in this form: last name followed 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. Turn in your source code.

Explanation / Answer

//This code is for 20 Students and will give some random output if value will less than 20.

#include <cstdlib>
#include <iostream>
#include <string>
#include<fstream>
#include <sstream>
using namespace std;


struct Student
{
     
string studentFName ;
string studentLName ;
int testScore ;
char grade ;
     
};

void ReadData(Student array[],string line,int i)
{


   stringstream linestream(line);
    linestream >> array[i].studentFName;
     linestream>>array[i].studentLName;
     linestream>>array[i].testScore;
     linestream>>array[i].grade;
   // cout<<array[i].studentFName;
  


}

void PrintData(Student array[])
{
int i=0;
for(i=0;i<20;i++)
{

cout<<array[i].studentLName<<", "<<array[i].studentFName<<" "<<array[i].testScore<<" "<<array[i].grade<<endl;
                
}

}
int main(int argc, char *argv[])
{
struct Student array[20];
ifstream infile;
infile.open("StudentData.txt");
string line;
int i=0;
while(getline(infile, line))
{   
    
    ReadData(array,line,i);
    i++;
}

PrintData(array);
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}

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