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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Global constant
const int NUM_STUDENTS=5;
const int NUM_SCORES=4;
//Function prototypes
void ascenDescen(string [],double [][NUM_SCORES],int,string []);
int main()
{
int choice;
string name[5]={"Hani","Haziq","Aiman","Farah","Sabrina"};
string mark[4]={"Test","Quiz","Assignment","Final Exam"};
double scores[NUM_STUDENTS][NUM_SCORES]={{9.0,2.7,16.0,78.0},
{7.4,2.7,19.0,88.0},
{8.9,3.5,17.5,93.7},
{10.0,3.0,19.5,64.8},
{6.3,3.0,16.0,74.2}};
cout<<"\aThis program will help you keep track of your academic record!"<<endl;
cout<<setprecision(1)<<fixed<<endl;
//Function call
ascenDescen(name,scores,NUM_STUDENTS,mark);
cout<<"\nTHANK YOU."<<endl;
return 0;
}
void ascenDescen (string NAME[],double table[][NUM_SCORES],int rows,string MARK[])
{
cout<<"\nPress ENTER to sort the students based on their marks for all tests, quizzes, assignments ";
cout<<"and final exam in ASCENDING and DESCENDING order."<<endl;
cout<<"Enter E/e if you wish to skip."<<endl;
char enter;
cin.ignore();
if(cin.get()=='\n')
{
double ascen;
string temp1[5];
temp1==NAME;
string temp2;
//for ascending
cout<<"\tASCENDING ORDER"<<endl;
for(int col=0;col<NUM_SCORES;col++)
{
for(int row=0;row<NUM_STUDENTS;row++)
{
for(int j=row+1;j<NUM_STUDENTS;++j)
{
if(table[row][col]>table[j][col])
{
ascen=table[row][col];
temp2=temp1[row];
table[row][col]=table[j][col];
temp1[row]=temp1[j];
table[j][col]=ascen;
temp1[j]=temp2;
}
}
}
cout<<MARK[col]<<" mark : \n";
for(int row=0;row<NUM_STUDENTS;row++)
{
cout<<"\t";
cout<<temp1[row]<<"\t"<<table[row][col];
cout<<endl;
}
for(int i=0;i<NUM_STUDENTS;i++)
{
temp1[i]=NAME[i];
}
}
}
}
|