Advertisement
BSIT_21

LinkedList (Redondo, Mangahis)

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