Question #27746

Use the while loop to aggregate students marksstored in an array. Use an enum to indicate in the array which student got which student got which mark and apply object oriented principles.

Expert's answer

# include <iostream>
# include <string>
using namespace std;


int main(){

enum mark{Fail, Pass, Exelent};

string s[20];

s[0]="e";
int m[20];
int i=0;
while (1){

cout<<"Enter name: ";
getline(cin, s[i], '\n');
if (s[i]=="") break;

cout<<"Enter mark : ";
cin>>m[i];
i++;
cin.ignore();
}

for (int j=0;j<i;j++){
for (int k=0;k<i-j-1;k++){
if ( m[k] > m[k+1] )
{
string temp = s[k];
s[k] = s[k+1];
s[k+1] = temp;

int tem = m[k];
m[k] = m[k+1];
m[k+1] = tem;
}
}

}
cout<<"sorted\n";

for (int j=0;j<i;j++){
cout<<s[j]<<" mark:"<<m[j]<<endl;
}


system("PAUSE");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS