You are on page 1of 9

Object

Oriented Assignment -2
Programmin
g
Abubakar Mahboob (Bcsm-f18-041)
Program1: Write the code for the class Car. The class 'Car' inherits its properties from the class 'Automobiles'
which inherits some of its properties from another class 'Vehicles'.

#include<iostream>

#include<string>

using namespace std;

class vehicle{

public:

string vehicletype;

public:

void setvehicle(string x){

vehicletype = x;

string getvehicle(){

return vehicletype;

};

class automobile : public vehicle{

public:

string manufacturer;

public:

void setmanufacturer(string y){

manufacturer = y;

string getmanufacturer(){

return manufacturer;

};
class car : public automobile{

public:

string carName;

string carColor;

public:

void setcarname(string z){

carName = z;

string getcarname(){

return carName;

};

int main(){

car obj;

string vt;

cout<<"Enter Vehicle Type : " << endl;

cin>>vt;

obj.setvehicle(vt);

cout <<"The Vehicle type is :"<< obj.getvehicle()<<endl;

string at;

cout<<"Enter Manufacturer : " << endl;

cin>>at;

obj.setmanufacturer(at);

cout << "The Manufacturer is :"<<obj.getmanufacturer()<<endl;

string cn;

cout<<"Enter Car Name : " << endl;


cin>>cn;

obj.setcarname(cn);

cout << "The Car Name is :"<<obj.getcarname()<<endl;

return 0;

Output:
Program 2: Person Data with Getter Setter

#include<iostream>

#include<string>

using namespace std;

class Person{

public:

string fname;

string lname;

int cnic;

string address;

int phone;

public:

void setfname(string x){

x= fname;

string getfname(){

return fname;

void setlname(string y){

y= lname;

string getlname(){

return lname;

}
void setcnic(int c){

c= cnic;

int getcnic(){

return cnic;

void setaddress(string a){

a= address;

string getaddress(){

return address;

};

class Student : public Person {

public:

string rollno;

string program;

string courses[5];

public:

void setrollno(string r){

r= rollno;

string getrollno(){

return rollno;

void setprogram(string p){


p= program;

string getprogram(){

return program;

void setcourses(){

for (int i = 0; i < 5; ++i)

cin >> courses[i];

cout << "The Courses are : "<<endl;

for (int n = 0; n < 5; ++n) {

cout << courses[n] << " ";

};

int main(){

Student myObj;

string fn;

cout<<"Enter First Name : " << endl;

cin>>fn;

myObj.setfname(fn);

cout << myObj.getfname();


string ln;

cout<<"Enter Last Name : " << endl;

cin>>ln;

myObj.setlname(ln);

cout << myObj.getlname();

int cn;

cout<<"Enter Cnic Name : " << endl;

cin>>cn;

myObj.setcnic(cn);

cout << myObj.getcnic();

string rn;

cout<<"Enter Rollno : " << endl;

cin>>rn;

myObj.setrollno(rn);

cout << myObj.getrollno();

string p;

cout<<"Enter Program : " << endl;

cin>>p;

myObj.setprogram(p);

cout << myObj.getprogram();

cout<<"Enter your Courses"<<endl;

myObj.setcourses();

return 0;

}
Output:

You might also like