Testpaper Arrangement in Decreasing Order
A system maintains a set of testpapers and arranges those papers in decreasing order either by registration number or by name.
Develop suitable algorithm and C++ code to create a generic class for maintaining the testpapers and arranging them.
Input format:
Enter the no. of testpapers,n
Enter the registration number of testpaper1
Enter the registration number of testpaper2
…
Enter the registration number of testpapern
Enter the name of testpaper1
Enter the name of testpaper2
Enter the name of testpaper3
Output format:
Registration number arranged in decreasing order (one in each line)
Name arranged in decreasing order (one in each line)
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
char name[10][10];
int regNum[10][2];
cout<<"Enter the number of students:";
int i,j,n;
cin>>n;
for(i=0;i<n;i++){
cout<<"Name : ";
cin>>name[i];
cout<<"Registration number : ";
cin>>regNum[i][0];
}
for(i=0;i<n;i++){
regNum[i][1]=0;
for(j=0;j<n;j++)
if(regNum[i][0]<regNum[j][0])
regNum[i][1]++;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(regNum[j][1]==i)
cout<<"Name : "<<setw(5)<<name[j]<<" ,Registration number : "<<regNum[j][0]<<endl;
return 0;
}
Comments
Leave a comment