Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void getdata(char name[], double &gpa)
{
cout << "Enter students name: ";
cin >> name;
cout << "Enter GPA: ";
cin >> gpa;
}//end getdata
class nodeType
{
public:
string name;
double gpa;
nodeType *next;
};
int main()
{
nodeType *prior, *duo, *uno, *currentNode, *head;
char theName[4];
double theGpa;
theGpa = 0.0;
for (int theList=1; theList<=2; theList++)
{
getdata(theName,theGpa);
currentNode = new nodeType;
currentNode->name = string(theName);
currentNode->gpa = theGpa;
currentNode->next = NULL;
head = currentNode;
prior = head;
for (int i=2;i<=10;i++)
{
getdata(theName,theGpa);
currentNode = new nodeType;
currentNode->name = string(theName);
currentNode->gpa = theGpa;
//sorting the list
if (currentNode->gpa > head->gpa)
{
currentNode->next = head;
head = currentNode;
}
else
{
prior = head;
while ((prior->next != NULL) && (prior->gpa) > (currentNode->gpa))
{
if((prior->next->gpa)<(currentNode->gpa))
{
currentNode->next = prior->next;
prior->next=currentNode;
}
prior = prior->next;
}
if((prior->gpa)>(currentNode->gpa))
{
currentNode->next = prior->next;
prior->next=currentNode;
}
}
}//end for loop i
if(theList == 1)
{
uno = head;
currentNode = head;
// output sorted list of uno
cout << "\nSorted List of List UNO " << endl << endl;
cout << setw(5) << "Student Name " << setw(10) << "GPA " << endl;
while(currentNode != NULL)
{
cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl;
cout << setiosflags(ios::fixed|ios::showpoint|ios::right);
cout << setprecision(2);
currentNode = currentNode->next;
}//end while
} // end if
else
{
duo = head;
currentNode = head;
// output sorted list of duo
cout << "\nSorted List of List DUO " << endl << endl;
cout << setw(5) << "Student Name " << setw(10) << "GPA " << endl;
while(currentNode != NULL)
{
cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl;
cout << setiosflags(ios::fixed|ios::showpoint|ios::right);
cout << setprecision(2);
currentNode = currentNode->next;
}//end while
} // end else
}//end for loop theList to process both lists
currentNode = uno;
prior = uno;
while (currentNode->gpa > 3.0)
{
currentNode = currentNode->next;
uno = currentNode;
prior = currentNode;
}
currentNode = currentNode->next;
while (currentNode->next != NULL)
{
if (currentNode->gpa > 3.0)
{
prior->next = currentNode->next;
currentNode = currentNode->next;
}
else
{
prior = currentNode;
currentNode = currentNode->next;
}
}//end for i
if (currentNode->gpa > 3.0)
{
prior->next = NULL;
}
currentNode = uno;
cout << "\nUNO List - All GPA's above 3.0 have been deleted " << endl << endl;
cout << setw(5) << "Student Name " << setw(10) << " GPA " << endl;
while(currentNode != NULL)
{
cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl;
cout << setiosflags(ios::fixed|ios::showpoint|ios::right);
cout << setprecision(2);
currentNode = currentNode->next;
}//end while
currentNode = duo;
prior = duo;
while (currentNode->gpa < 2.00)
{
currentNode = currentNode->next;
duo = currentNode;
prior = currentNode;
}
currentNode = currentNode->next;
while (currentNode->next != NULL)
{
if (currentNode->gpa < 2.5)
{
prior->next = currentNode->next;
currentNode = currentNode->next;
}
else
{
prior = currentNode;
currentNode = currentNode->next;
}
}//end for i
if (currentNode->gpa < 2.00)
{
prior->next = NULL;
}
currentNode = duo;
cout << "\nDUO List - All GPA's under 2.00 have been deleted" << endl << endl;
cout << setw(5) << "Student Name " << setw(10) << " GPA " << endl;
while(currentNode != NULL)
{
cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl;
cout << setiosflags(ios::fixed|ios::showpoint|ios::right);
cout << setprecision(2);
currentNode = currentNode->next;
}//end while
int xx;
cout <<" to end press xx";
cin >> xx;
return 0;
}//end main
There's his code, put up on the forums.