Make your own free website on Tripod.com
« September 2018 »
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Ch 9 PC 2
Sunday, 3 February 2008
Ch 9 PC 2

/********************
* 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;
}
 
 


Posted by veronicak5678 at 8:16 PM EST
Updated: Sunday, 3 February 2008 8:18 PM EST

Newer | Latest | Older