So far, I have the program to read in the max number of points, students name, and total grade. I have inserted the names and grades into a link list. The names and grades are sorted in named order currently. Now, I need to have a link print the grades in sorted order. Also, I need a 3rd link in the same link list to of all students who have a grade below 200.
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
usingnamespace std;
ifstream inFile; //declare file stream
ofstream outputFile;
//define struct
class LList
{
public:
string Name;
int Number;
LList *next;
};
typedef LList *Node;
Node ListHead;
//define a newNode
LList *newNameNode()
{
LList * temp;
temp = new LList();
temp -> Name = 'a';
temp -> next = NULL;
return temp;
}
LList *newGradeNode()
{
LList * temp;
temp = new LList();
temp -> Number = 0;
temp -> next = NULL;
return temp;
}
// print list function
void printList(int max)
{
Node c;
c = ListHead; //assign c to head
int num;
int answer;
while ( c )
{
outputFile << left << c -> Name << setw(18);
outputFile << left << c -> Number * 100 / max << setw(15);
outputFile << left << c -> Number << setw(15);
outputFile << endl;
c = c -> next;
}
}
//insert a node to link list
void insert(string v, int n1)
{
Node c, p, temp;
c = ListHead;
p = NULL;
string s; //declare string variables
int g;
s = v;
g = n1;
//place items in ordered link list on item Name
while ( c != NULL && c -> Name <= s)
{
p = c;
c = c -> next;
}
if(p == NULL)
{
temp = newNameNode();
temp -> Name = s;
temp -> Number = g;
temp -> next = c;
ListHead = temp;
}
elseif(s != p->Name)
{
temp = newNameNode();
temp -> Name = s;
temp -> Number = g;
p -> next = temp;
temp -> next = c;
}
}
int main()
{
//open input and output files
inFile.open("LinkLnamesAndGrades.txt");
outputFile.open("answer.txt");
int n1;
string v;
int max;
inFile >> max;
while(inFile >> v )
{
inFile >> n1;
insert(v, n1);
}
printList(max); //call print list function
//close the files
inFile.close();
outputFile.close();
return 0;
}