0% found this document useful (0 votes)
17 views5 pages

Practical Related Questions.: SR - No:05

Uploaded by

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

Practical Related Questions.: SR - No:05

Uploaded by

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

Sr.

no:05

Practical Related Questions.

1.Write a C++ program to define a class "Student" having data members roll_no, name.
Derive a class "Marks" from "Student" having data members ml,m2,m3, total and
percentage. Accept and display data for one student.

#include <iostream.h>

#include<conio.h>

class Student //Base class

int roll_no;

char name[10];

public:

void accept_stud() //Defining member function inside the class

cout<<"\nEnter roll no of student=";

cin>>roll_no;

cout<<"\nEnter name of student=";

cin>>name;

void display_stud(); //Declaration of member function

};

void Student::display_stud() //Defining member function outside the class

cout<<"\nStudent information:";

cout<<"\nRoll no.:"<<roll_no;

cout<<"\nName:"<<name;

class Marks:public Student //Derive class Marks from base class Student

int m1,m2,m3;

float percentage,total;
public:

void accept_marks()

cout<<"\nEnter marks of m1=";

cin>>m1;

cout<<"\nEnter marks of m2=";

cin>>m2;

cout<<"\nEnter marks of m3=";

cin>>m3;

void display_marks()

total=m1+m2+m3;

percentage=(total/300)*100.0;

cout<<"\nMarks of Subject 1:"<<m1;

cout<<"\nMarks of Subject 2:"<<m2;

cout<<"\nMarks od Subject 3:"<<m3;

cout<<"\nTotal Marks:"<<total;

cout<<"\nPercentage:"<<percentage;

};

void main()

Marks M; //Creating object of derive class to access members of base class and its own.

M.accept_stud();

M.accept_marks();

M.display_stud();

M.display_marks();

getch();

}
Output:

2.Write a C++ program to implement following Multilevel Inheritance.

#include<iostream.h>

#include<conio.h>

class person //Base class

char name[20],gender[20];

int age;

public:

void input()

cout<<"\nEnter name of person=";

cin>>name;

cout<<"\nEnter gender=";

cin>>gender; cout<<"\nEnter age=";

cin>>age;

void output()

cout<<"\nDetail of employee:";

cout<<"\nName="<<name;

cout<<"\nGender="<<gender;
cout<<"\nAge="<<age;

};

//Derive class employee from base class person and base class for programmerC class employee:public person

class employee:public person

int emp_id;

char company[20];

float salary;

public:

void getdata()

cout<<"\nEnter employee id=";

cin>>emp_id;

cout<<"\nEnter company=";

cin>>company; cout<<"\nEnter salary=";

cin>>salary;

void putdata()

cout<<"\nEmployee ID:"<<emp_id;

cout<<"\nCompany:"<<company;

cout<<"\nSalary:"<<salary;

};

class programmer:public employee //Derive class programmer from base class employee

int no_of_pro_lan_known; public:

void accept()

{
cout<<"\nEnter no of programming languages the employee known=";

cin>>no_of_pro_lan_known;

void display()

cout<<"\nNo of Programming languages known:"<<no_of_pro_lan_known;

};

Void main()

programmer p;

p.input();

p.getdata();

p.accept();

p.output();

p.putdata();

p.display();

getch();

Output:

You might also like