0% found this document useful (0 votes)
73 views9 pages

(Oop)

The document contains 4 questions each with a C++ program that defines classes. Question 1 defines a Person class with name, id, address and a Student class that inherits from Person with additional roll number and marks attributes. Question 2 defines an Employee class with id and scale and a Manager class that inherits from Employee with additional department and manager id attributes. Question 3 defines nested inheritance with a LocalPhone class, NetPhone that inherits from LocalPhone with a city attribute, and IntPhone that inherits from NetPhone with a country attribute. Question 4 defines a Teacher class with name, address, age and a Writer class with name, address, books, and a Scholar class that inherits from both Teacher and Writer. Each program takes user input

Uploaded by

sarmad
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)
73 views9 pages

(Oop)

The document contains 4 questions each with a C++ program that defines classes. Question 1 defines a Person class with name, id, address and a Student class that inherits from Person with additional roll number and marks attributes. Question 2 defines an Employee class with id and scale and a Manager class that inherits from Employee with additional department and manager id attributes. Question 3 defines nested inheritance with a LocalPhone class, NetPhone that inherits from LocalPhone with a city attribute, and IntPhone that inherits from NetPhone with a country attribute. Question 4 defines a Teacher class with name, address, age and a Writer class with name, address, books, and a Scholar class that inherits from both Teacher and Writer. Each program takes user input

Uploaded by

sarmad
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/ 9

QUESTION#01:

#include<iostream>

#include<string>

using namespace std;

class person

int id;

string name,address;

public:

person() {}

void input()

cout<<"Enter Name: ";

cin>>name;

cout<<"Enter ID: ";

cin>>id;

cout<<"Enter Address: ";

cin>>address;

void display()

cout<<"Name: "<<name<<endl;

cout<<"ID: "<<id<<endl;

cout<<"Address: "<<address<<endl;

}
};

class student:public person

int marks;

string rollno;

public:

void set_value()

cout<<"Enter roll number: ";

cin>>rollno;

cout<<"Enter marks: ";

cin>>marks;

void show()

cout<<"Roll Number: "<<rollno<<endl;

cout<<"Marks : "<<marks<<endl;

};

int main()

student obj;

obj.input();

obj.set_value();
cout<<"\nShowing Data!"<<endl<<endl;

obj.display();

obj.show();

QUESTION#02:

#include<iostream>

#include<string>

using namespace std;

class employee

int employeeID;

int scale;

public:

void input()

cout<<"Enter Employee ID: ";

cin>>employeeID;

cout<<"Enter Employee scale: ";

cin>>scale;

void show()

cout<<"Employee's ID : "<<employeeID<<endl;

cout<<"Employee's Scale : "<<scale<<endl;


}

};

class manager:public employee

string department;

int managerID;

public:

void set_value()

cout<<"Enter manager ID: ";

cin>>managerID;

cout<<"Enter manager Department: ";

cin>>department;

void display()

cout<<"Manager ID: "<<managerID<<endl;

cout<<"Manager Department: "<<department;

};

int main()

manager obj;

obj.input();

obj.set_value();
cout<<"\nShowing Data!\n"<<endl;

obj.show();

obj.display();

QUESTION#03:

#include<iostream>

#include<string>

using namespace std;

class localphone

string phone;

public:

void InputPhone()

cout<<"Enter phone number: ";

cin>>phone;

void ShowPhone()

cout<<"Phone Number is: "<<phone<<endl;

};

class netphone: public localphone

string city;
public:

void InputCity()

cout<<"Enter city code: ";

cin>>city;

void ShowCity()

cout<<"City Code is: "<<city<<endl;

};

class intphone: public netphone

string country;

public:

void InputCountry()

cout<<"Enter country Code: ";

cin>>country;

void ShowCountry()

cout<<"Country code is: "<<country<<endl;

};
int main()

intphone obj;

obj.InputPhone();

obj.InputCity();

obj.InputCountry();

cout<<"\nShowing Data!\n"<<endl;

obj.ShowPhone();

obj.ShowCity();

obj.ShowCountry();

QUESTION#04:

#include<iostream>

#include<string>

using namespace std;

class teacher

string name,address;

int age;

public:

void set()

cout<<"Enter Data of Teacher!\n"<<endl;

cout<<"Enter name: ";

cin>>name;
cout<<"Enter age: ";

cin>>age;

cout<<"Address: ";

cin>>address;

void show()

cout<<"Name of Teacher: "<<name<<endl;

cout<<"Age of the Teacher: "<<age<<endl;

cout<<"Address of Teacher: "<<address<<endl;

};

class writer

string namew;

string address_writer;

int books;

public:

void input()

cout<<"\nEnter Data of Writer!\n"<<endl;

cout<<"Enter name: ";

cin>>namew;

cout<<"Enter books: ";

cin>>books;
cout<<"Address: ";

cin>>address_writer;

void display()

cout<<"\nName of Writer: "<<namew<<endl;

cout<<"Books of the Writer: "<<books<<endl;

cout<<"Address of Writer: "<<address_writer<<endl;

};

class scholar:public writer,public teacher

};

int main()

scholar obj;

obj.set();

obj.input();

cout<<"\nShowing Data!\n"<<endl;

obj.show();

obj.display();

You might also like