Here's the problem:
Write a 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 the type studentType, which has four components: studentFName and studentLName of the type string, test score of the type int (test score is between 0 and 100), and grade of the type char. Suppose that the class has 20 students. Use an array of 20 components of the type studentType.
Your Program must contain at least the following functions:
a. A function to read the students data into the array.
b. A function to assign the relevant grade to each student.
c. A function to find the highest test score.
d. A function to print the names of the students having the highest test score.
Your program must output each student's name in this form: last name followed by a comma, followed by a space, followed by a first name, and 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.
Here's what I've Got so far
- Code: Select all
#include<iostream> // Standard Library Of Code For Main Functions.
#include<iomanip> // Library Of Code For I/O Manipulations.
#include<string> // Library Of Code For Using Strings.
#include<fstream> // Library Of Code Used For Streaming Data Through Files.
using namespace std;
//Function For Reading Student's Data Into Array
//Function For Assigning Grade
//Function For Highest Test Score
//Function For Displaying Name Of Student With Highest Test Score
struct studentType //Structure for storing data
{
string firstname; //Firstname of student
string lastname;//Lastname of student
string newlastname; //Transfer Of Last Name Variable For Later usage
string classList[20][2][1];
int testscore;//Testscore of student
char grade;//Student's Grade
char letter; // Character read
}; // End of structure
studentType classL;//Array of structure for storing students Last Name, First Name, and Grade
studentType studentFname; //First name object Directory
studentType studentLname; // Last name object Directory
studentType character; //object of structure used in the counting of individual characters in the input file.
int main() // Beginning of Main Functin
{
ifstream infile;//Declaration of Output File
infile.open("c:\\test1.txt"); //Opening of Input File
while (!infile.eof()) //While The File Has Not Ended...
{
infile.get(character.letter); //Get The next character
if (character.letter != ' ') //if the next character isn't a space...
{
studentFname.firstname = studentFname.firstname + character.letter; //Make a string of character read so far...
}
else //But if there is a space read....
{
break; // end the reading.
}
}
while (!infile.eof())//While The File Has Not Ended...
{
infile.get(character.letter);//Get The next character
if (character.letter != ' ') //if the next character isn't a space...
{
studentLname.newlastname = studentLname.newlastname + character.letter;//Make a string of character read so far...
}
else //But if there is a space read....
{
studentLname.lastname = studentLname.newlastname; //store the last word read in this string
studentLname.newlastname = ""; //make the old string equal to no space
}
}
cout << studentLname.lastname << "," << " "; //Display The Last name
cout << studentFname.firstname << endl;//Display The First name
infile.close();//Closing of Infile
return 0;//End of Main Function
}
