SlideShare a Scribd company logo
/*
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;
}
};
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();
}

More Related Content

PPTX
Function in c program
PPTX
Call by value
DOCX
Java Programs Lab File
PDF
Function overloading ppt
PPT
Operators in C++
PDF
JAVA PROGRAMMING- Exception handling - Multithreading
PPTX
Preprocessor directives in c language
PPTX
Inheritance in java
Function in c program
Call by value
Java Programs Lab File
Function overloading ppt
Operators in C++
JAVA PROGRAMMING- Exception handling - Multithreading
Preprocessor directives in c language
Inheritance in java

What's hot (20)

ODP
Function
PPTX
User defined functions
PDF
Preprocessor
PDF
C++ STATEMENTS
PPTX
Code Optimization
PPTX
Polymorphism presentation in java
PDF
USER DEFINED FUNCTIONS IN C.pdf
PPTX
Static Members-Java.pptx
PPSX
Student Marks Analyzing System-Problem Statement, SRS, ERD, DFD, Structured C...
PPTX
Data Types In C
PPTX
Managing console i/o operation,working with files
PPTX
Recursion in c++
PPTX
Superposition theorem
PPTX
Pointers in c++
DOCX
C programming Lab 2
PPT
11_ Instruction Sets addressing modes .ppt
PPTX
Pointers,virtual functions and polymorphism cpp
PPTX
Call by value or call by reference in C++
PPTX
Data types in c++
PDF
Operator overloading
Function
User defined functions
Preprocessor
C++ STATEMENTS
Code Optimization
Polymorphism presentation in java
USER DEFINED FUNCTIONS IN C.pdf
Static Members-Java.pptx
Student Marks Analyzing System-Problem Statement, SRS, ERD, DFD, Structured C...
Data Types In C
Managing console i/o operation,working with files
Recursion in c++
Superposition theorem
Pointers in c++
C programming Lab 2
11_ Instruction Sets addressing modes .ppt
Pointers,virtual functions and polymorphism cpp
Call by value or call by reference in C++
Data types in c++
Operator overloading
Ad

Similar to Program: Inheritance in Class - to find topper out of 10 students (20)

TXT
Student search by roll no project in c++
PDF
Program 1 (Practicing an example of function using call by referenc.pdf
PDF
Student.h #include stdafx.h #include string using names.pdf
PDF
oodp elab.pdf
RTF
DOCX
#include PA3Header.h#include stdafx.h Function r.docx
TXT
C++ program using class
DOC
~ Project-student report-card.cpp[1]
PDF
#include stdafx.h#include iostream#include string#incl.pdf
PDF
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
DOCX
Investigatory Project for Computer Science
PPTX
oops practical file.pptx IT IS A PRACTICAL FILE
PDF
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
PPTX
A Deep Dive into C++ Arrays: Understanding its with Code Examples
PDF
#include iostream #include fstream #include shirtType.h.pdf
DOCX
Bubble and selection
PDF
Header #include -string- #include -vector- #include -iostream- using.pdf
PDF
Using the C++ programming language1. Implement the UnsortedList cl.pdf
PDF
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
PDF
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
Student search by roll no project in c++
Program 1 (Practicing an example of function using call by referenc.pdf
Student.h #include stdafx.h #include string using names.pdf
oodp elab.pdf
#include PA3Header.h#include stdafx.h Function r.docx
C++ program using class
~ Project-student report-card.cpp[1]
#include stdafx.h#include iostream#include string#incl.pdf
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
Investigatory Project for Computer Science
oops practical file.pptx IT IS A PRACTICAL FILE
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
A Deep Dive into C++ Arrays: Understanding its with Code Examples
#include iostream #include fstream #include shirtType.h.pdf
Bubble and selection
Header #include -string- #include -vector- #include -iostream- using.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
Ad

More from Swarup Boro (20)

DOCX
Concatenation of two strings using class in c++
DOCX
Array using recursion
DOCX
Binary addition using class concept in c++
DOCX
Study of Diffusion of solids in Liquids
TXT
Program using function overloading
TXT
Program to sort array using insertion sort
TXT
Program to find the avg of two numbers
TXT
Program to find factorial of a number
TXT
Canteen management program
TXT
Railway reservation
PDF
Boolean
PDF
Classes
PDF
Constructor & destructor
PDF
Arrays and library functions
PDF
Pointers
PDF
PDF
Structures in c++
PDF
PDF
Functions
PDF
Implementation of oop concept in c++
Concatenation of two strings using class in c++
Array using recursion
Binary addition using class concept in c++
Study of Diffusion of solids in Liquids
Program using function overloading
Program to sort array using insertion sort
Program to find the avg of two numbers
Program to find factorial of a number
Canteen management program
Railway reservation
Boolean
Classes
Constructor & destructor
Arrays and library functions
Pointers
Structures in c++
Functions
Implementation of oop concept in c++

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
Abdominal Access Techniques with Prof. Dr. R K Mishra
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Basic Mud Logging Guide for educational purpose
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

Program: Inheritance in Class - to find topper out of 10 students

  • 1. /* 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; } };
  • 2. 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(); }