Embed presentation
Downloaded 11 times
![/* Write a program that has a class student to store details of the students in a class; Derive another class topper from student that store records of only top three students of the class */ #include<iostream> #include<string.h> using namespace std; class student { public: char name[20]; int rollno; int percentage; void getdata() { cout<<"n Enter the name of the student"; cin>>name; cout<<"n Enter the roll no."; cin>>rollno; cout<<"n Enter the percentage of the student"; cin>>percentage; } }; class topper : public student { public: void display() { cout<< "n Name : "<<name; cout<<"n Roll. No. : "<<rollno; cout<<"n Percentage : "<<percentage; } };](https://image.slidesharecdn.com/classinheritancetopper-170514083316/75/Program-Inheritance-in-Class-to-find-topper-out-of-10-students-1-2048.jpg)
![main() { int j,k,l,i; student s[10]; for( i=0;i<10;i++) s[i].getdata(); for( i=0;i<10;i++) { if(s[i].percentage>s[i+1].percentage) j=i; } topper t[3]; strcpy(t[0].name,s[j].name); t[0].rollno=s[j].rollno; t[0].percentage=s[j].percentage; for(i=0;i<10;i++) { if((s[i].percentage>s[i+1].percentage) && i!=j) k=i; } strcpy(t[1].name,s[k].name); t[1].rollno=s[k].rollno; t[1].percentage=s[k].percentage; for(i=0;i<10;i++) { if((s[i].percentage>s[i+1].percentage) && i!=j && i!=k) l=i; } strcpy(t[2].name,s[l].name); t[2].rollno=s[l].rollno; t[2].percentage=s[l].percentage; cout<<"n The top three scorers are :n "; for(i=0;i<3;i++) t[i].display(); }](https://image.slidesharecdn.com/classinheritancetopper-170514083316/75/Program-Inheritance-in-Class-to-find-topper-out-of-10-students-2-2048.jpg)

The document presents a C++ program that defines a class 'student' to store details of students, including their name, roll number, and percentage. A derived class 'topper' captures the records of the top three students based on percentages. The program collects student data, identifies the top three scorers, and displays their information.
![/* Write a program that has a class student to store details of the students in a class; Derive another class topper from student that store records of only top three students of the class */ #include<iostream> #include<string.h> using namespace std; class student { public: char name[20]; int rollno; int percentage; void getdata() { cout<<"n Enter the name of the student"; cin>>name; cout<<"n Enter the roll no."; cin>>rollno; cout<<"n Enter the percentage of the student"; cin>>percentage; } }; class topper : public student { public: void display() { cout<< "n Name : "<<name; cout<<"n Roll. No. : "<<rollno; cout<<"n Percentage : "<<percentage; } };](https://image.slidesharecdn.com/classinheritancetopper-170514083316/75/Program-Inheritance-in-Class-to-find-topper-out-of-10-students-1-2048.jpg)
![main() { int j,k,l,i; student s[10]; for( i=0;i<10;i++) s[i].getdata(); for( i=0;i<10;i++) { if(s[i].percentage>s[i+1].percentage) j=i; } topper t[3]; strcpy(t[0].name,s[j].name); t[0].rollno=s[j].rollno; t[0].percentage=s[j].percentage; for(i=0;i<10;i++) { if((s[i].percentage>s[i+1].percentage) && i!=j) k=i; } strcpy(t[1].name,s[k].name); t[1].rollno=s[k].rollno; t[1].percentage=s[k].percentage; for(i=0;i<10;i++) { if((s[i].percentage>s[i+1].percentage) && i!=j && i!=k) l=i; } strcpy(t[2].name,s[l].name); t[2].rollno=s[l].rollno; t[2].percentage=s[l].percentage; cout<<"n The top three scorers are :n "; for(i=0;i<3;i++) t[i].display(); }](https://image.slidesharecdn.com/classinheritancetopper-170514083316/75/Program-Inheritance-in-Class-to-find-topper-out-of-10-students-2-2048.jpg)