Guest User

Untitled

a guest
Apr 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.79 KB | None | 0 0
  1. #include <fstream>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7. ofstream fout;
  8.  
  9. // Bubble Sort to sort out the list of grades that were input //
  10. void bSort(int array[], int size) {
  11.       bool swap = true;
  12.       int j = 0;
  13.       int temp;
  14.       while (swap) {
  15.          swap = false;
  16.          j++;
  17.          for (int i = 0; i < size - j; i++) {
  18.             if (array[i] > array[i + 1]){                                                      temp = array[i];
  19.                array[i] = array[i + 1];
  20.                array[i + 1] = temp;
  21.                swap = true;
  22.             }
  23.          }
  24.       }
  25. }
  26.  
  27.  
  28. // This function gets the mean of the array of grades //
  29. int getMean(int array[], int size) {
  30.  
  31.   int sum = 0;
  32.   int count = 0;
  33.   int mean;
  34.  
  35.   for(int k=0;k<size;k++){
  36.     sum = sum + array[k];
  37.     count++;
  38.   }
  39.  
  40.   mean = sum/count;
  41.  
  42.   return mean;
  43. }
  44.  
  45.  
  46. // This function gets the Standard Deviation from the array of grades //
  47. int getSDev(int array[], int size){
  48.   int temp [size];
  49.   int sum = 0;
  50.  
  51.   int theMean = getMean(array, size);
  52.  
  53.   for(int k=0;k<size;k++){
  54.     temp[k] = array[k] - theMean;    
  55.   }
  56.  
  57.   for(int m=0;m<size;m++){
  58.     sum = sum + (temp[m]*temp[m]);
  59.   }
  60.  
  61.   int sDev = sum / (size - 1);
  62.  
  63.   sDev = sqrt(sDev);
  64.  
  65.   return sDev;
  66. }
  67.  
  68.  
  69. // This function prints out the letter grade for each numeric grade in the array //
  70. void printRanges(int array[], int size, int m, int s){
  71.   for(int p=0;p<size;p++){
  72.     if((m+(4/3)*s) <= array[p] && array[p] <= 100) {
  73.        cout << array[p] << "  A\n";
  74.     }
  75.     else if((m+(3/3)*s) <= array[p] && array[p] < (m+(4/3)*s)){
  76.        cout << array[p] << "  A-\n";
  77.     }
  78.     else if((m+(2/3)*s) <= array[p] && array[p] < (m+(3/3)*s)){
  79.        cout << array[p] << "  B+\n";
  80.     }
  81.     else if((m+(1/3)*s) <= array[p] && array[p] < (m+(2/3)*s)){
  82.        cout << array[p] << "  B\n";
  83.     }
  84.     else if((m+(0/3)*s) <= array[p] && array[p] < (m+(1/3)*s)){
  85.        cout << array[p] << "  B-\n";
  86.     }
  87.     else if((m-(1/3)*s) <= array[p] && array[p] < (m+(0/3)*s)){
  88.        cout << array[p] << "  C+\n";
  89.     }
  90.     else if((m-(2/3)*s) <= array[p] && array[p] < (m-(1/3)*s)){
  91.        cout << array[p] << "  C\n";
  92.     }
  93.     else if((m-(3/3)*s) <= array[p] && array[p] < (m-(2/3)*s)){
  94.        cout << array[p] << "  C-\n";
  95.     }
  96.     else if((m-(4/3)*s) <= array[p] && array[p] < (m-(3/3)*s)){
  97.        cout << array[p] << "  D+\n";
  98.     }
  99.     else if((m-(5/3)*s) <= array[p] && array[p] < (m-(4/3)*s)){
  100.        cout << array[p] << "  D\n";
  101.     }
  102.     else {
  103.        cout << array[p] << "  F\n";
  104.     }
  105.   }
  106.  
  107. }
  108.  
  109.  
  110.  
  111. // main program //
  112. int main() {
  113.   int size;
  114.  
  115.   cout << "Enter the number of scores\n";
  116.   cin >> size;
  117.   int grades [size];
  118.  
  119.   cout << "Enter the individual grades. Type -1 to end input\n";
  120.  
  121.   int grade = 0;
  122.   int i = 0;
  123.   while(grade != -1 && i< size) {
  124.     cin >> grade;
  125.  
  126.     if (grade != -1) {
  127.       grades[i] = grade;
  128.     }
  129.    
  130.     i++;
  131.   }
  132.  
  133.  bSort(grades, size);
  134.  
  135.  int mean = getMean(grades, size);
  136.  int standardDev = getSDev(grades, size);
  137.  
  138.  int option = -1;
  139.  
  140.  while(option != 0) {
  141.     cout << "What would you like to do now?\n";
  142.     cout << "1. Print sorted list\n";
  143.     cout << "2. Print the Mean\n";
  144.     cout << "3. Print the Standard Deviation\n";
  145.     cout << "4. Print the Letter Grades\n";
  146.     cout << "0. Exit\n";
  147.  
  148.     cin >> option;
  149.  
  150.     if(option == 1){
  151.        for(int n=0;n<size;n++){
  152.           cout << grades[n] << "\n";
  153.        }
  154.     }
  155.     else if (option == 2) {
  156.       cout << "Mean = " << mean << "\n";
  157.     }
  158.     else if (option == 3) {
  159.       cout << "Standard Deviation = " << standardDev << "\n";
  160.     }
  161.     else if (option == 4){
  162.       printRanges(grades, size, mean, standardDev);
  163.     }
  164.     else {
  165.       return(0);
  166.     }
  167.   }
  168. }
Add Comment
Please, Sign In to add comment