0% found this document useful (0 votes)
119 views29 pages

Lab Report 8 Oop

1) The document contains code snippets from multiple lab tasks and home tasks related to OOP concepts like classes, inheritance, polymorphism etc. 2) The tasks involve creating classes for base, derived and multiple inheritance scenarios. Methods are used to get and display data from the classes. 3) Code snippets also demonstrate polymorphism through virtual functions to get and display data from derived classes.

Uploaded by

Atyia Javed
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)
119 views29 pages

Lab Report 8 Oop

1) The document contains code snippets from multiple lab tasks and home tasks related to OOP concepts like classes, inheritance, polymorphism etc. 2) The tasks involve creating classes for base, derived and multiple inheritance scenarios. Methods are used to get and display data from the classes. 3) Code snippets also demonstrate polymorphism through virtual functions to get and display data from derived classes.

Uploaded by

Atyia Javed
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/ 29

LAB REPORT 8 :

HASNAIN AHMAD:

FA18-BCE-068-4B:

OOP:

LAB TASKS
Lab Task 5.1:
#include <iostream>

using namespace std;

class base

protected:

int A;

public:

int B;

public:

void getdata1()

cout<<"\nEnter First Value Of Base Class: ";

cin>>A;

cout<<"Enter Second Value Of Base Class: ";

cin>>B;

void displaydata1()

cout<<"\n1) Base Class Value 1: "<<A<<endl<<"\n2) Base Class Value 2: "<<B<<endl;

};

class derived1: public base

public:
int C;

public:

void getdata2()

base::getdata1();

cout<<"Enter Value Of Derived1 Class: ";

cin>>C;

void displaydata2()

base::displaydata1();

cout<<"\n3) Value Of Derived1 Class: "<<C<<endl;

};

class derived2: public derived1

public:

void getdata3()

derived1::getdata2();

void displaydata3()

derived1::displaydata2();
}

};

int main()

derived2 D2;

D2.getdata3();

D2.displaydata3();

return 0;

Output:

Lab Task 5.2:


#include<iostream>

#include<string>

using namespace std;

class Person
{

protected:

string name,gender; int age;

public:

void getdata1()

cout<<"\nEnter The Name: ";

cin>>name;

cout<<"Enter The Age: ";

cin>>age;

cout<<"Enter The Gender: ";

cin>>gender;

void setdata1()

cout<<"\nName: "<<name<<"\nAge: "<<age<<"\nGender: "<<gender;

};

class Employee

protected:

string empl_name; int dailywages;

public:

void getdata2()
{

cout<<"\nEnter THe Employee Name: ";

cin>> empl_name;

cout<<"Enter The Employee Daily WAGES: ";

cin>>dailywages;

void setdata2()

cout<<"\nEmployee Name: "<<empl_name<<"\nEmployee Daily Wages: "<<dailywages;

};

class Teacher:public Employee,public Person

private:

string tech_name; int grade;

public:

void getdata3()

Person::getdata1();

Employee::getdata2();

cout<<"\nEnter The Techer Name: ";

cin>> tech_name;

cout<<"Enter The Teacher grade: ";

cin>>grade;
}

void setdata3()

Person::setdata1();

Employee::setdata2();

cout<<"\nTeacher Name: "<<tech_name<<"\nTeacher Grade: "<<grade;

};

int main() {

Teacher T1;

T1.getdata3();

T1.setdata3();

return 0;

Output:
Lab Task 5.3:
#include <iostream>

using namespace std;

class Date

protected:

int day;

int month;

int year;

public:

Date():day(0),month(0),year(0){

cout << "\nDay:" << day << endl << "Month:" << month << endl << "Year:" << year << endl;
}

void display(){

cout << "\nDay:" << day << endl << "Month:" << month << endl << "Year:" << year << endl;

} // displays the date

Date get(){

Date :: set();

Date :: display();

} // accesses the date members

void set(){

cout<<"\nEnter the day, month, year: "<<endl;

cin >> day >> month >> year;

} // sets the date members

};

class Time

protected:

int hour;

int minute;

int second;

public:

Time():hour(0),minute(0),second(0){

cout << "\nHour:" << hour << endl << "Minute:" << minute << endl << "Second:" << second <<
endl;

void display(){
cout << "\nHour:" << hour << endl << "Minute:" << minute << endl << "Second:" << second <<
endl;

} // displays the time

Time get(){

Time :: set();

Time :: display();

} // accesses the time members

void set(){

cout<<"\nEnter the hours, minutes, seconds: "<<endl;

cin >> hour >> minute >> second;

}// sets the time members

};

class DateAndTime : public Date, public Time

int digital;

public:

void display(){

Date::get();

Time::get();

} // prints date and time

};

int main()

DateAndTime Watch;

Watch.display();
return 0;

Output:

Lab Task 5.4:


#include<iostream>

#include<conio.h>

#include <string>

using namespace std;

class Teacher{

private:

string Name;
int age;

string Address;

public:

void getdata1()

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

cin>>Name;

cout<<"Enter Teacher Age: "<<endl;

cin>>age;

cout<<"Enter Teacher Address: "<<endl;

cin>>Address;

void showdata1()

cout<<"\nTeacher Name: "<<Name;

cout<<"\nTeacher Age: "<<age;

cout<<"\nTeacher Address: "<<Address;

};

class Auther{

private:

string W_name;

string W_address;

int No_Books;
public:

void getdata2()

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

cin>>W_name;

cout<<"Enter Writer Address: "<<endl;

cin>>W_address;

cout<<"Enter Number of Books written by Writer: "<<endl;

cin>>No_Books;}

void showdata2()

cout<<"\nWriter Name: "<<W_name;

cout<<"\nWriter Address: "<<W_address;

cout<<"\nNumber of Books: "<<No_Books;

};

class Scholar:public Teacher,public Auther{

private:

public:

void getdata()

Teacher::getdata1();

Auther::getdata2();

}
void showdata(){

Teacher::showdata1();

Auther::showdata2();

};

int main()

Scholar S;

S.getdata();

S.showdata();

getch();

Output:
POST LAB/ Home TASKS
Home Task 6.1:
#include<iostream>

#include<conio.h>

#include<string>

using namespace std;

class Employee{

string e_name;

int e_no;

public:

Employee(): e_name(""),e_no(0){}

void getdata(){

cout<<endl<<"Enter Name OF Employee: ";


cin>>e_name;

cout<<endl<<"Enter Employee Number: ";

cin>>e_no;

void salary(){

cout<<endl<<"Employee Number: "<<e_no<<'\t'<<"\nEmployee Name: "<<e_name;

~Employee(){}

};

class Regular : public Employee{

float Basic;

public:

Regular(float bs){

Basic=bs;}

void getdata(){

Employee::getdata();

void salary(){

Employee::salary();

cout<<endl<<"Basic = "<<Basic;

cout<<endl<<"DA = "<<Basic*0.1;

cout<<endl<<"HRA = "<<Basic*0.3;

cout<<endl<<"Total Payble = "<<(Basic + (Basic*0.1) + (Basic*0.3));

}
~Regular(){}

};

class Adhoc : public Employee{

float wage;

int number;

public:

Adhoc(float wg){

wage=wg;

number=0;

void days(int n){ number+=n; }

void salary(){

Employee::salary();

cout<<endl<<"Total Payble = "<<wage*number;

void getdata(){

Employee::getdata();

~Adhoc(){}

};

int main(){

class Regular robj(5000);

class Adhoc aobj(65);

robj.getdata();
aobj.getdata();

aobj.days(25);

cout<<endl<<"\nDetails of Regular Employee1: \n";

robj.salary();

cout<<endl<<"\nDetails of Adhoc Employee1: \n";

aobj.salary();

getch();

Output:

Home Task 6.2:


#include<iostream>
#include<conio.h>

using namespace std;

class student {

int rno;

public:

void getnumber() {

cout << "Enter Roll Number: ";

cin>>rno;

void putnumber() {

cout << "\n\n\tRoll Number: " << rno << "\n";

};

class test : virtual public student {

public:

int part1, part2;

void getmarks() {

cout << "Enter Marks:\n";

cout << "1) ";

cin>>part1;

cout << "2) ";

cin>>part2;

void putmarks() {
cout << "\tMarks Obtained:\n";

cout << "\n\tPart1:" << part1;

cout << "\n\tPart2:" << part2;

};

class sports : public virtual student {

public:

int score;

void getscore() {

cout << "Enter Sports Score: ";

cin>>score;

void putscore() {

cout << "\n\tSports Score is: " << score;

};

class result : public test, public sports {

int total;

public:

void display() {

total = part1 + part2 + score;

putnumber();

putmarks();

putscore();
cout << "\n\tTotal Score: " << total;

};

int main() {

result obj;

obj.getnumber();

obj.getmarks();

obj.getscore();

obj.display();

getch();

Output:

Home Task 6.3:


#include<iostream>

#include<conio.h>
using namespace std;

class locphone{

private:

long phone;

public:

locphone(){

phone=0;}

void in(){

cout<<"Enter Local Phone Number: "<<endl;

cin>>phone;

void show(){

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

};

class natphone:public locphone

private:

int ccod;

public:

natphone(){

locphone();

ccod=0;}

void in(){
locphone::in();

cout<<"Enter City Code: "<<endl;cin>>ccod;}

void show(){

locphone::show();

cout<<"City code Is: "<<ccod<<endl;

};

class intphone:public natphone

private:

int cncod;

public:

intphone(){

natphone();

cncod=0;}

void in(){

natphone::in();

cout<<"Enter Country Code"<<endl;cin>>cncod;

void show(){

natphone::show();

cout<<"Country Code Is :"<<cncod<<endl;

};
int main(){

intphone obj;

obj.in();

obj.show();

getch();

Output:

Home Task 6.4:


#include <iostream>

#include <string>

#include <conio.h>

using namespace std;

class publication

private:

string title;

float price;

public:
void getdata(void)

string t;

float p;

cout << "Enter Title Of Pulication: ";

cin >> t;

cout << "Enter Price Of Publication: ";

cin >> p;

title = t;

price = p;

void putdata(void)

cout << "Publication Title: " << title << endl;

cout << "Publication Price: " << price << endl;

};

class sales

private:

float s1, s2, s3;

public:

void getdata(void)

{
cout << "Enter Month 1 Sale: $";

cin >> s1;

cout << "Enter Month 2 Sale: $";

cin >> s2;

cout << "Enter Month 3 Sale: $";

cin >> s3;

void putdata(void)

cout << "Month 1 Sale: $" << s1 << endl;

cout << "Month 2 Sale: $" << s2 << endl;

cout << "Month 3 sale: $" << s3 << endl;

};

class book :public publication,public sales

private:

int pagecount;

public:

void getdata(void)

publication::getdata();

sales::getdata();

cout << "Enter Book Page Count: ";


cin >> pagecount;

void putdata(void)

publication::putdata();

sales::putdata();

cout << "Book Page Count: " << pagecount << endl;

};

class tape :public publication,public sales

private:

float ptime;

public:

void getdata(void)

publication::getdata();

sales::getdata();

cout << "Enter Tap's Playing Time: ";

cin >> ptime;

void putdata(void)

publication::putdata();
sales::putdata();

cout << "Tap's Playing Time: " << ptime << endl;

};

int main(void)

book b;

tape t;

b.getdata();

t.getdata();

b.putdata();

t.putdata();

getch();

Output:

You might also like