Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //for using standard i/o functions
- #include <cmath> //for using math functions
- #include <cstdlib> //for using rand functions
- #include <ctime> //for using a time function
- using namespace std;
- #define n 10 //declaring n is 10
- /* Finding Average Functions
- Input: n scores
- Output: An average score*/
- float favg (int score[n])
- {
- float sum = 0; //sum of scores
- for ( int i = 0 ; i < n ; i++ )
- {
- sum += score[i];
- }
- return sum/n;
- }
- /* Finding SD Functions
- Input: An average score and scores
- Output: A SD*/
- float fsd (float avg,int score[n])
- {
- float sum = 0; //sum of scores minus average score
- for ( int i = 0 ; i < n ; i++ )
- {
- sum += pow((score[i] - avg),2);
- }
- return sqrt(sum/n);
- }
- /* Finding Grade From Score
- Input: A score and multipliers
- Output: A grade */
- char fgrade (int score, float mul[3], float avg, float sd)
- {
- char grade;
- if( score >= avg+(mul[0]*sd) && score <= 10 )
- {
- grade = 'A';
- }
- else if ( score >= avg+(mul[1]*sd) )
- {
- grade = 'B';
- }
- else if ( score >= avg+(mul[2]*sd) )
- {
- grade = 'C';
- }
- else
- {
- grade = 'F';
- }
- return grade;
- }
- int main ()
- {
- char lc; //declaring a loop control
- float mul[] = { 1.2 , 0.6 , -1 }; //declaring default multipliers
- do
- {
- int score[n];
- char grade[n];
- int gc[] = {0,0,0,0}; //declaring grade counters that gc[0] is an A counter , so gc[3] is an F counter
- cout<<"--------------------------------------"<<endl<<"Score(grade): ";
- srand(time(NULL)); //gen a seed using current time
- for ( int j = 0 ; j < n ; j++)
- {
- score[j] = rand() % (n+1); //declaring random scores that is between 0 - n
- }
- float avg = favg(score);
- float sd = fsd(avg,score);
- for( int i = 0 ; i < n ; i ++)
- {
- grade[i] = fgrade(score[i],mul,avg,sd); //finding grade
- cout<<score[i]<<"("<<grade[i]<<"),";
- switch(grade[i])
- {
- case 'A':
- gc[0]++;
- break;
- case 'B':
- gc[1]++;
- break;
- case 'C':
- gc[2]++;
- break;
- default:
- gc[3]++;
- }
- }
- cout<<endl<<"Grade count: A("<<gc[0]<<"), B("<<gc[1]<<"), C("<<gc[2]<<"), F("<<gc[3]<<")"<<endl;
- cout<<"GPA: "<<((gc[0]*4)+(gc[1]*3)+(gc[2]*2))/n<<",\tAverage: "<<avg<<",\tSD: "<<sd<<endl;
- cout<<"Do you want to modify multipliers (y/n): ";
- cin>>lc;
- if( lc == 'y' || lc == 'Y' )
- {
- cout<<"Enter new multipliers (default: 1.2 0.6 -1 ): ";
- cin>>mul[0]>>mul[1]>>mul[2];
- }
- cout<<endl;
- } while( lc != 'n' || lc != 'N' );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement