Advertisement
Dark_Shard

LinkedList

Jul 27th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include<iostream>
  2.  
  3.  
  4.  using namespace std;
  5.  
  6.  
  7.  struct student{
  8.  
  9.      string nameData;
  10.      double grading;
  11.      student *nextNode;
  12.  
  13.  };
  14.  
  15.  student  *first_entry = NULL;
  16.  
  17.  void pushData(string naming, double gr, int size)
  18.  {
  19.      student* newData = new student;
  20.      newData->grading = gr;
  21.      newData->nameData = naming;
  22.  
  23.      //point to a blank node
  24.      newData->nextNode = first_entry;
  25.      first_entry = newData;
  26.  
  27.  
  28.  }
  29.  
  30.  
  31.  
  32.  void printData(double limit, char res)
  33.  {
  34.         student* tempPointer = first_entry;
  35.         if(toupper(res) == 'A')
  36.         {
  37.             while(tempPointer!=NULL  )
  38.             {
  39.             if( tempPointer->grading == limit)
  40.                 {
  41.                 cout << " " << tempPointer->nameData << "\t" <<  tempPointer->grading << endl;
  42.                 }
  43.             tempPointer = tempPointer ->nextNode;
  44.             }
  45.         }
  46.  
  47.         else if(toupper(res) == 'B')
  48.         {
  49.             while(tempPointer!=NULL )
  50.             {
  51.                 if( tempPointer->grading > limit)
  52.                 {
  53.             cout << " " << tempPointer->nameData << "\t" <<  tempPointer->grading << endl;
  54.             }
  55.             tempPointer = tempPointer ->nextNode;
  56.             }
  57.         }
  58.  
  59.         else if(toupper(res) == 'C')
  60.         {
  61.             while(tempPointer!=NULL  )
  62.             {
  63.             if( tempPointer->grading < limit)
  64.                 {
  65.  
  66.  
  67.             cout << " " << tempPointer->nameData << "\t" <<  tempPointer->grading << endl;
  68.             }
  69.             tempPointer = tempPointer ->nextNode;
  70.             }
  71.         }
  72.  
  73.         else if(toupper(res) == 'D')
  74.         {
  75.             while(tempPointer!=NULL)
  76.             {
  77.             cout << " " << tempPointer->nameData << "\t" <<  tempPointer->grading << endl;
  78.             tempPointer = tempPointer ->nextNode;
  79.             }
  80.         }
  81.  
  82.  
  83.  
  84.  }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  int main()
  91.  {
  92.      int lim =0 ;
  93.      int listSize = 1;
  94.      char response='Y';
  95.      char choice = ' ';
  96.  
  97.      double grade = 0.0;
  98.      string name = " ";
  99.  
  100.  
  101.      while(toupper(response) == 'Y')
  102.      {
  103.             cout << "Input name" << endl;
  104.             cin >> name;
  105.  
  106.  
  107.  
  108.             cout << "Input grade" << endl;
  109.             cin >> grade;
  110.  
  111.  
  112.             pushData(name, grade,listSize);
  113.             listSize++;
  114.  
  115.  
  116.  
  117.             cout << "More entry(Y/N)" << endl;
  118.             cin >> response;
  119.      }
  120.  
  121.      cout << endl;
  122.  
  123.  
  124.  
  125.     repeat:
  126.      cout << "Enter choice (A-D)" << endl;
  127.      cin >> choice;
  128.  
  129.  
  130.  
  131.      switch(toupper(choice))
  132.      {
  133.          case 'A':
  134.          case 'B':
  135.          case 'C':
  136.  
  137.             cout << "Input grade " << endl;
  138.             cin >> lim;
  139.             printData(lim , toupper(choice));
  140.             break;
  141.          case 'D':
  142.              printData(lim, toupper(choice));
  143.              break;
  144.  
  145.          default:
  146.             goto repeat;
  147.  
  148.  
  149.  
  150.      }
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement