SHARE
TWEET

Untitled

a guest Jun 24th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ZakAttack.cpp--A program for calculating student grades and
  2. // displaying the overall GPA
  3. // Shaheen Fathima Abdul Jamal Nazar, CISP 360
  4. // Instructor: Professor Fowler
  5. // Date: 04/27/2018
  6.  
  7. #include <iomanip>
  8. #include <iostream>
  9. #include <limits>
  10. #include <string>
  11. using namespace std;
  12.  
  13. // Variable Declarations
  14. string stName;
  15. int scores[50];
  16. int *ptr = scores;
  17. int count = 0;
  18.  
  19. // Function Prototypes
  20. void results();
  21. void gradeAdd();
  22. void mainMenu();
  23. int getUserChoice();
  24. void mainEvent();
  25.  
  26. int main() {
  27.     // Program Greeting
  28.     cout << " Hi! Welcome to the Zak Attack Program!n" << endl;
  29.     cout << " This program calculates the grades for an" << endl;
  30.     cout << " specific number of quizzes taken by a student.n" << endl;
  31.     cout << " It also displays the overall grades along withn" << endl;
  32.     cout << " the letters (A-F) based on the scores attained by the student! "
  33.          << endl;
  34.     cout << endl;
  35.  
  36.     cout << " Enter the name of the student (First and Last): ";
  37.     getline(cin, stName);
  38.     cout << endl;
  39.  
  40.     mainEvent();
  41.  
  42.     return 0;
  43. }
  44.  
  45. void mainEvent() {
  46.     int userInput;
  47.     bool task = false;
  48.  
  49.     do {
  50.         mainMenu();
  51.         cout << "nEnter your choice: ";
  52.         userInput = getUserChoice();
  53.  
  54.         if (userInput == 1) {
  55.             gradeAdd();
  56.         } else if (userInput == 2) {
  57.             results();
  58.             break;
  59.         } else if (userInput == 3) {
  60.             task = true;
  61.         }
  62.     } while (task == false);
  63. }
  64.  
  65. void results() {
  66.     // variables to be used
  67.     int tem, sNum, rNum, pNum;
  68.     bool swapNum;
  69.     int scCopy[50];
  70.     int *ptrCopy = scCopy;
  71.     int lowScore[15];
  72.     int *ptrLow = lowScore;
  73.     double gpAvg = 0;
  74.     char rChoice;
  75.  
  76.     cout << " Name of Student: " << stName << endl;
  77.  
  78.     // Copying scores[] to scCopy[] array
  79.     for (int i = 0; i < count; i++) {
  80.         *(ptrCopy + i) = *(ptr + i);
  81.     }
  82.     do {
  83.         swapNum = false;
  84.         for (int j = 0; j < count; j++) {
  85.             if (*(ptrCopy + j) > *(ptrCopy + (j + 1))) {
  86.                 tem = *(ptrCopy + j);
  87.                 *(ptrCopy + j) = *(ptrCopy + (j + 1));
  88.                 *(ptrCopy + (j + 1)) = tem;
  89.                 swapNum = true;
  90.             }
  91.         }
  92.     } while (swapNum);
  93.     sNum = (count * 0.3);
  94.     rNum = count;
  95.     pNum = sNum;
  96.  
  97.     for (int i = 0; i < sNum; i++) {
  98.         *(ptrLow + i) = *(ptrCopy + i);
  99.         *(ptrCopy + i) = 0;
  100.         pNum--;
  101.     }
  102.  
  103.     // Display the grades as letters and overall GPA
  104.     for (int i = 0; i < count; i++) {
  105.         if (*(ptrCopy + i) >= 94) {
  106.             cout << *(ptrCopy + i) << ": A " << endl;
  107.             gpAvg += 4;
  108.         } else if (*(ptrCopy + i) >= 90 && *(ptrCopy + i) < 94) {
  109.             cout << *(ptrCopy + i) << ": A- " << endl;
  110.             gpAvg += 3.7;
  111.         } else if (*(ptrCopy + i) >= 87 && *(ptrCopy + i) < 90) {
  112.             cout << *(ptrCopy + i) << ": B+ " << endl;
  113.             gpAvg += 3.3;
  114.         } else if (*(ptrCopy + i) >= 83 && *(ptrCopy + i) < 87) {
  115.             cout << *(ptrCopy + i) << ": B " << endl;
  116.             gpAvg += 3;
  117.         } else if (*(ptrCopy + i) >= 80 && *(ptrCopy + i) < 83) {
  118.             cout << *(ptrCopy + i) << ": B- " << endl;
  119.             gpAvg += 2.7;
  120.         } else if (*(ptrCopy + i) >= 77 && *(ptrCopy + i) < 80) {
  121.             cout << *(ptrCopy + i) << ": C+ " << endl;
  122.             gpAvg += 2.3;
  123.         } else if (*(ptrCopy + i) >= 73 && *(ptrCopy + i) < 77) {
  124.             cout << *(ptrCopy + i) << ": C " << endl;
  125.             gpAvg += 2;
  126.         } else if (*(ptrCopy + i) >= 70 && *(ptrCopy + i) < 73) {
  127.             cout << *(ptrCopy + i) << ": C- " << endl;
  128.             gpAvg += 1.7;
  129.         } else if (*(ptrCopy + i) >= 67 && *(ptrCopy + i) < 70) {
  130.             cout << *(ptrCopy + i) << ": D+ " << endl;
  131.             gpAvg += 1.3;
  132.         } else if (*(ptrCopy + i) >= 60 && *(ptrCopy + i) < 67) {
  133.             cout << *(ptrCopy + i) << ": D " << endl;
  134.             gpAvg += 1;
  135.         } else if (*(ptrCopy + i) > 1 && *(ptrCopy + i) < 60) {
  136.             cout << *(ptrCopy + i) << ": F " << endl;
  137.         }
  138.     }
  139.     cout << "*******************" << endl;
  140.  
  141.     // Dropped scores
  142.     for (int i = 0; i < sNum; i++)
  143.         cout << *(ptrLow + i) << " [Dropped Score] " << endl;
  144.  
  145.     // Calculation of GPA and displaying results
  146.     rNum -= sNum;
  147.     cout << fixed << setprecision(2) << endl;
  148.     gpAvg = (gpAvg / rNum);
  149.     cout << " Grade Point Average (GPA): " << gpAvg << endl;
  150.     cout << endl;
  151.  
  152.     if (gpAvg == 4) {
  153.         cout << " Grade: A" << endl << endl;
  154.         cout << " Excellent Job! " << endl;
  155.         cout << " Keep up the good progress! " << endl;
  156.     } else if (gpAvg < 4 && gpAvg > 3.67) {
  157.         cout << " Grade: A-" << endl << endl;
  158.         cout << " Good Score! " << endl;
  159.         cout << " Keep Going! " << endl;
  160.     } else if (gpAvg < 3.67 && gpAvg > 3.33) {
  161.         cout << " Grade: B+" << endl << endl;
  162.         cout << " Good Work! " << endl;
  163.         cout << " Study a little more. " << endl;
  164.     } else if (gpAvg < 3.33 && gpAvg > 3) {
  165.         cout << " Grade: B" << endl << endl;
  166.         cout << " Good " << endl;
  167.         cout << " Need to study even more! " << endl;
  168.     } else if (gpAvg < 3 && gpAvg > 2.67) {
  169.         cout << " Grade: B- " << endl << endl;
  170.         cout << " Well done " << endl;
  171.         cout << " but need to work hard, " << endl;
  172.         cout << " since you are close to a C! " << endl;
  173.     } else if (gpAvg < 2.67 && gpAvg > 2.33) {
  174.         cout << " Grade: C+ " << endl << endl;
  175.         cout << " Looks like the grades are slipping " << endl;
  176.         cout << " Need to spend more time studying! " << endl;
  177.     } else if (gpAvg < 2.33 && gpAvg > 2) {
  178.         cout << " Grade: C " << endl << endl;
  179.         cout << " Getting low! " << endl;
  180.         cout << " Need to work even harder! " << endl;
  181.     } else if (gpAvg < 2 && gpAvg > 1.67) {
  182.         cout << " Grade: C- " << endl << endl;
  183.         cout << " Risky! Gotta study even more! " << endl;
  184.     } else if (gpAvg < 1.67 && gpAvg > 1.33) {
  185.         cout << " Grade: D+ " << endl << endl;
  186.         cout << " Going low on your " << endl;
  187.         cout << " chances of passing! " << endl;
  188.         cout << " Work even more harder! " << endl;
  189.     } else if (gpAvg < 1.33 && gpAvg > 1) {
  190.         cout << " Grade: D " << endl;
  191.         cout << " Chances of passing the class " << endl;
  192.         cout << " are getting even lower! " << endl;
  193.         cout << " Concentrate and study or seek help " << endl;
  194.         cout << " from a tutor! " << endl;
  195.     } else if (gpAvg < 1 && gpAvg > 0.67) {
  196.         cout << " Grade: D- " << endl;
  197.         cout << " Nearly no chances of passing! " << endl;
  198.     } else if (gpAvg < 0.67) {
  199.         cout << " Grade: F " << endl;
  200.         cout << " Disappointing and dejecting! " << endl;
  201.         cout << " Try Again or Opt for something else " << endl;
  202.     }
  203.  
  204.     cout << " Would you like to enter the grades for another student?";
  205.     cin >> rChoice;
  206.  
  207.     if (rChoice == 'Y') {
  208.         cin.clear();
  209.         cin.ignore(numeric_limits<streamsize>::max(), 'n');
  210.         cout << " Enter name of the student (First and Last): ";
  211.         getline(cin, stName);
  212.  
  213.         cin.clear();
  214.         cin.ignore();
  215.         mainEvent();
  216.     } else if (rChoice == 'N') {
  217.         cout << " Good Bye! " << endl;
  218.     }
  219. }
  220.  
  221. void gradeAdd() {
  222.     cout << "nEnter quiz # " << (count + 1) << " score: ";
  223.     cin >> *(ptr + count);
  224.     while (*(ptr + count) > 100 || *(ptr + count) < 0) {
  225.         cout << " Sorry! Invalid Input! Please enter a value from 0-100: "
  226.              << endl;
  227.         cin.clear();
  228.         cin.ignore(numeric_limits<streamsize>::max(), 'n');
  229.         cin >> *(ptr + count);
  230.     }
  231.     count++;
  232. }
  233.  
  234. void mainMenu() {
  235.     cout << "1. Add a grade" << endl;
  236.     cout << "2. Display Results" << endl;
  237.     cout << "3. Quit" << endl;
  238. }
  239.  
  240. int getUserChoice() {
  241.     int userInput;
  242.  
  243.     cin >> userInput;
  244.  
  245.     while (userInput != 1 && userInput != 2 && userInput != 3) {
  246.         cout << " Invalid Choice! Please enter a choice from 1 to 3: " << endl;
  247.         cin.clear();
  248.         cin.ignore(numeric_limits<streamsize>::max(), 'n');
  249.         cin >> userInput;
  250.     }
  251.     return userInput;
  252. }
  253.      
  254. getline(cin, stName);
  255.  
  256.     cin.clear();
  257.     cin.ignore();
  258.     mainEvent();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top