Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iomanip>
- #include <iostream>
- #include <math.h>
- using namespace std;
- ofstream fout;
- // Bubble Sort to sort out the list of grades that were input //
- void bSort(int array[], int size) {
- bool swap = true;
- int j = 0;
- int temp;
- while (swap) {
- swap = false;
- j++;
- for (int i = 0; i < size - j; i++) {
- if (array[i] > array[i + 1]){ temp = array[i];
- array[i] = array[i + 1];
- array[i + 1] = temp;
- swap = true;
- }
- }
- }
- }
- // This function gets the mean of the array of grades //
- int getMean(int array[], int size) {
- int sum = 0;
- int count = 0;
- int mean;
- for(int k=0;k<size;k++){
- sum = sum + array[k];
- count++;
- }
- mean = sum/count;
- return mean;
- }
- // This function gets the Standard Deviation from the array of grades //
- int getSDev(int array[], int size){
- int temp [size];
- int sum = 0;
- int theMean = getMean(array, size);
- for(int k=0;k<size;k++){
- temp[k] = array[k] - theMean;
- }
- for(int m=0;m<size;m++){
- sum = sum + (temp[m]*temp[m]);
- }
- int sDev = sum / (size - 1);
- sDev = sqrt(sDev);
- return sDev;
- }
- // This function prints out the letter grade for each numeric grade in the array //
- void printRanges(int array[], int size, int m, int s){
- for(int p=0;p<size;p++){
- if((m+(4/3)*s) <= array[p] && array[p] <= 100) {
- cout << array[p] << " A\n";
- }
- else if((m+(3/3)*s) <= array[p] && array[p] < (m+(4/3)*s)){
- cout << array[p] << " A-\n";
- }
- else if((m+(2/3)*s) <= array[p] && array[p] < (m+(3/3)*s)){
- cout << array[p] << " B+\n";
- }
- else if((m+(1/3)*s) <= array[p] && array[p] < (m+(2/3)*s)){
- cout << array[p] << " B\n";
- }
- else if((m+(0/3)*s) <= array[p] && array[p] < (m+(1/3)*s)){
- cout << array[p] << " B-\n";
- }
- else if((m-(1/3)*s) <= array[p] && array[p] < (m+(0/3)*s)){
- cout << array[p] << " C+\n";
- }
- else if((m-(2/3)*s) <= array[p] && array[p] < (m-(1/3)*s)){
- cout << array[p] << " C\n";
- }
- else if((m-(3/3)*s) <= array[p] && array[p] < (m-(2/3)*s)){
- cout << array[p] << " C-\n";
- }
- else if((m-(4/3)*s) <= array[p] && array[p] < (m-(3/3)*s)){
- cout << array[p] << " D+\n";
- }
- else if((m-(5/3)*s) <= array[p] && array[p] < (m-(4/3)*s)){
- cout << array[p] << " D\n";
- }
- else {
- cout << array[p] << " F\n";
- }
- }
- }
- // main program //
- int main() {
- int size;
- cout << "Enter the number of scores\n";
- cin >> size;
- int grades [size];
- cout << "Enter the individual grades. Type -1 to end input\n";
- int grade = 0;
- int i = 0;
- while(grade != -1 && i< size) {
- cin >> grade;
- if (grade != -1) {
- grades[i] = grade;
- }
- i++;
- }
- bSort(grades, size);
- int mean = getMean(grades, size);
- int standardDev = getSDev(grades, size);
- int option = -1;
- while(option != 0) {
- cout << "What would you like to do now?\n";
- cout << "1. Print sorted list\n";
- cout << "2. Print the Mean\n";
- cout << "3. Print the Standard Deviation\n";
- cout << "4. Print the Letter Grades\n";
- cout << "0. Exit\n";
- cin >> option;
- if(option == 1){
- for(int n=0;n<size;n++){
- cout << grades[n] << "\n";
- }
- }
- else if (option == 2) {
- cout << "Mean = " << mean << "\n";
- }
- else if (option == 3) {
- cout << "Standard Deviation = " << standardDev << "\n";
- }
- else if (option == 4){
- printRanges(grades, size, mean, standardDev);
- }
- else {
- return(0);
- }
- }
- }
Add Comment
Please, Sign In to add comment