Created
May 2, 2014 06:19
-
-
Save anonymous/34b1409dc09f4836a40b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Header file section | |
| #include "stdafx.h" | |
| #include<iostream> | |
| #include<string> | |
| using namespace std; | |
| //Funtion declaration | |
| float Average (int *scores,int number) ; | |
| void SortTestScores (int *scores,string *Names,int n) ; | |
| void main () | |
| { | |
| //Variable declaration | |
| int *testScore=new int [50] ; | |
| string +Names=new string [50] ; | |
| float averageScore ; | |
| //number to store number of test scores and i loop variable | |
| int number, I ; | |
| // Inputting values | |
| cout<<"Enternumber of test scores" ; | |
| cin>>number; | |
| for ( i=0 ; I <number; i++) | |
| { | |
| cout<<"Enter name"; | |
| cin>>Names [i] ; | |
| cout<<"Enter Test Scores"; | |
| cin>>testScores [i] ; | |
| } | |
| //Function call to sort test score | |
| Sort TestScores (testScore, Names, number0 ; | |
| //Outputing sorted testScores | |
| cout<<"Name \t"<<"TestScore"<<endl; | |
| for (i=0; I<number;i++) | |
| { | |
| cout<<Names [i]<<"\t"; | |
| cout<<testScores [i]<<endl; | |
| } | |
| //Function call to average the score and return averagescore | |
| averageScore=Average (testScores,number) ; | |
| //Outputting Average test score | |
| cout<<"Average testScore is: "<<averageScore<<end; | |
| system ("pause"); | |
| }//End of main | |
| //Sort Function definition | |
| void SortTestScores (int scores,string *Names, int number) | |
| { int temp; | |
| string tempname; | |
| int I, j;//Loop variables | |
| for (i=1;i<number; I++) | |
| { | |
| for (j=0; j <number-I;j++) | |
| { | |
| //Swapping scores | |
| temp=scores [j]; | |
| scores [j] =scores [j+1] | |
| scores [j+1]=temp; | |
| //Swapping names | |
| tempname=Names[j] | |
| Names[j]=Names [j+1]; | |
| Names[j+1]=tempname ; | |
| }//End if | |
| }//End j loop | |
| }//End I loop | |
| }//End sort function | |
| //Average function definition | |
| float Average(int *score, int n) | |
| { | |
| int I ;//loop variable | |
| float avg=0. 0; | |
| for (i=0 ; I<n; I++) | |
| { | |
| avg+=score [i] ; | |
| } | |
| avg=avg/n; | |
| retun avg; | |
| } | |
| //End average | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment