Need help writing this c++ program. You are to write a program that will read na
ID: 645665 • Letter: N
Question
Need help writing this c++ program.
You are to write a program that will read names followed by single test grade. The very first line of the file has a single number which represents the max number of points to make on a test. The name is listed first followed by a grade or the points made on a test. Have your program read in the name and grade and print out the name and the percentage grade the student made on the test. (grade/max=%). Print out the list of names and their grade in sorted order sorted by grade and a second list sorted by grade. You are to list the sorted grades from the highest grade to the lowest.
You are to use two links in your link list. One link links the names in sorted ordered and a second link to link the grades in sorted ordered.
Example input
300
jones 289
luewey 266
Or-less 178
Example output (Sorted): (Example is not accurate)
Jones 94
Luewey 90
Or-less 83
Explanation / Answer
#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
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.