0% found this document useful (0 votes)
35 views2 pages

Program 2

This document defines three C++ classes - Person, Game, and Student. The Person class stores a name and age. The Game class stores a game name. The Student class inherits from Person and Game using multiple inheritance and additionally stores a roll number and total marks. The Student class defines functions to input data, calculate and output grade based on marks, and display all stored data. The main function creates a Student object and calls its member functions to input, process, and output the student's information.

Uploaded by

Tanishq Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Program 2

This document defines three C++ classes - Person, Game, and Student. The Person class stores a name and age. The Game class stores a game name. The Student class inherits from Person and Game using multiple inheritance and additionally stores a roll number and total marks. The Student class defines functions to input data, calculate and output grade based on marks, and display all stored data. The main function creates a Student object and calls its member functions to input, process, and output the student's information.

Uploaded by

Tanishq Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM 2

Program to define the classes PERSON, GAME and STUDENT & to access the
essential data using multiple inheritance.*/

#include<iostream.h> // Header files declared


#include<stdio.h>
#include<conio.h>
class person{ char name[21];
int age;
public:
void indata()
{cout<<"\n\nEnter the name of Student: " ;
gets(name);
cout<<"\n\nEnter the age : ";
cin>>age;
}
void outdata();
};
void person::outdata() // since the function contains loop so it is not made
inline
{
cout<<"\n\n";
for(int i=0; i<79; i++)
cout<<"-";
cout<<"\n\nName of the student is: "<<name;
cout<<"\n\nAge of the student is : "<<age;
}
class game {
char game_name[20];
public:
void input()
{
cout<<"\n\nEnter the game name : ";
cin.get();cin.getline(game_name,20);
}
void output()
{
cout<<"\n\nGame opted by the student is : "<<game_name;
}
};
class student: public person, public game
{ float Tmarks;
int rollno;
public:
char calgrade()
{if(Tmarks>90)
return 'A';
else if(Tmarks>80&&Tmarks<=90)
return 'B';
else if(Tmarks>70&&Tmarks<=80)
return 'C';
else if(Tmarks>60&&Tmarks<=70)
return 'D';
else
return 'E';
}
void enter()
{
indata(); // indata() of class person called here
cout<<"\n\nEnter the roll number: "; cin>>rollno;
input(); // input() of class game called here
cout<<"\n\nEnter total marks (out of 100) : ";
cin>>Tmarks;
}
void display()
{
outdata();
cout<<"\n\nRoll number : "<<rollno;
OUTPUT();
cout<<"\n\nTotal marks are : "<<Tmarks;
cout<<"\n\nGrade = "<<calgrade();
}
};
void main()
{ clrscr();
student A;
A.enter();
A.display();
getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy