Monday, 8 June 2015

Program that takes input of students and result obtained, based on that provides rank



Code for Program that takes input of students and result obtained, based on that provides rank in C++ Programming



 



#include <iostream.h>

#include <iomanip.h>

#include <conio.h>

class rank

{

char name[20];

int marks[5],sum;

public:

void getdata(void);

void display(void);

friend void sort(rank &,rank &);

rank()

{sum=0;}

};

void rank :: getdata(void)

{

cout<<endl<<endl<<endl;

cout<<"Enter Your Name :- ";

cin>>name;

cout<<"\nEnter Marks for 5 Subjects\n";

for(int i=0;i<5;i++)

{

cin>>marks[i];

sum=sum+marks[i];

}

}

void rank :: display(void)

{

cout<<endl;

cout<<setw(10)<<name<<setw(17)<<"";

for(int j=0;j<5;j++)

cout<<setw(5)<<marks[j]; 

cout<<setw(12)<<sum;

}

void sort(rank &a,rank &b)

{

rank temp;

if(a.sum < b.sum)

{

temp = a;

a = b;

b = temp;

}

}

void main() 

{

clrscr();

rank o1[10];

int rec;

cout<<"Enter Array size of Object between 1-10:-";

cin>>rec;

for(int i=0;i<rec;i++)

{

o1[i].getdata();

}

for(i=0;i<rec;i++)

{

for(int j=i+1;j<rec;j++)

{

sort(o1[i],o1[j]);

}

}

clrscr();

cout<<"\n\t\t\tDISPLAY FUNCTION\n\n\n";

cout<<setw(10)<<"NAME OF STUDENT"<<setw(30)<<"MARKS OBTAINED"<<setw(20)<<"TOTAL"<<endl;

for(i=0;i<rec;i++)

{

o1[i].display();

}

getch();

}
 

No comments:

Post a Comment