CISP 400 Assignments

Welcome graphic

/********************

* Veronica Kaufman *

* Assignment 1 *

* CISP 400 *

********************/

#include <iostream>

#include <cstdio>

using namespace std;

 

void sort( double arr[], int sz ); //function declarations

void display( double arr[], int sz );

void average( double arr[], int sz );

 

int main(){ //main function

double *scores;

int count, amount;

bool notValid;

cout << "Test Scores Program\n\n";

do{ //validation loop for input

notValid=false;

cout <<"How many scores would you like to enter?\n";

cin >> amount;

if (amount<1){

cout << "Invalid entry.\n";

notValid=true;

}

}while (notValid);

scores = new double[amount]; //dynamic array

cout << "Please enter in your test scores below.\n"; //user input

for ( count = 0; count < amount; count++ ){

cout << "Test Score " << (count + 1) << ": ";

cin >> scores[count];

}

sort( scores, amount ); //calls sort function

display( scores, amount ); //calls display function

average(scores, amount); //calls average function

system ("pause");

delete [] scores; //frees array

return 0;

}

void sort( double arr[], int s ){

double temp = 0;

for ( int i = 0; i < s - 1; i++ ){ //ascending sort

for ( int j = ( i + 1 ); j < s; j++ ){

if ( arr[i] < arr[j] ){

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}

}

void display( double arr[], int s ){

cout << endl; //displays sorted array

cout << "\nThe sorted scores are as follows: \n\n";

cout << "====================================\n\n";

for ( int i = 0; i < s; i++ ){

cout << ( i + 1 ) << ": " ;

cout << arr[i] << endl;

}

cout << "====================================\n\n";

}

void average(double arr[], int s){ //averages scores

double sum = 0.0;

for ( int i = 0; i < s; i++ ){

sum += arr[i];

}

double average = sum / s;

cout << "\n\nThe average all test scores is " << average << endl<<endl;

}

Keyboard