Professional Documents
Culture Documents
Made by:
Muhammad Furqan Saad Akram
(FA18-BEE-174)
Submitted to:
Date:
21/11/2020
TASK 1 CODE:-
#include <iostream>
class Base
protected:
int m_value;
public:
Base(int value)
: m_value(value)
};
public:
Derived1(int value)
: Base(value)
};
public:
Derived2(int value)
: Derived1(value)
};
int main()
Derived1 derived(5);
Derived2 derived1(6);
cout << "derived has value " << derived.getvalue1() << '\n';
cout << "derived has value " << derived1.getvalue2() << '\n';
return 0;
}
OUTPUT:-
TASK 2 CODE:-
#include <iostream>
#include <stdio.h>
class person
{
protected:
char name[30];
int age;
char gender;
public:
void getpersonInfo(void)
cin.getline(name,30);
};
class empolyee
protected:
char Name[30];
char dailywages[30];
int time2dowork;
public:
void getempInfo(void)
//cin.ignore(1);
fflush(stdin);
cin.getline(Name,30);
fflush(stdin);
cin.getline(dailywages,30);
};
public:
void getEmployeeInfo(void){
void printEmployeeInfo(void)
cout << "Name: " << name << endl; //accessing protected data
cout << "person age: " << age << endl; //accessing protected data
cout << "Gender: " << gender << endl << endl;//accessing protected data
cout << "Employee Name: " << Name << endl; //accessing protected data
cout << "dailywages: " << dailywages << endl; //accessing protected data
cout << "Time to do work: " << time2dowork<< endl; //accessing protected data
}
};
int main()
teacher emp;
emp.getEmployeeInfo();
emp.printEmployeeInfo();
return 0;
OUTPUT:-
TASK 3 CODE:-
#include <iostream>
#include <ctime>
"Sat"};
class Date{
// Private Members
private:
std::string month;
std::string day;
int date;
int year;
// Public Members
public:
// Default Constructor
Date() {
time_t timer;
tm * time;
std::time(&timer);
time = localtime(&timer);
date = time->tm_mday;
month = months[time->tm_mon];
day = days[time->tm_wday];
void printDate(void) {
<< this->month << " " << this->day << " "
<< this->date << " " << this->year;
// Destructor
~Date() {}
};
int main()
Date d;
d.printDate();
OUTPUT:-
TASK 4 CODE:-
#include<iostream>
#include<conio.h>//header file
private://access specifie
int age;
char Address[50];
public://access specifier
void input(){ cout<<endl<<"Enter your Name "<<endl;
cin>>Name;
cin>>age;
cin>>Address;
void display()
{//function
class Writer{
private://access specifierchar
char W_name[30];
int No_Books;
public://access specifier
void input(){//function
void display(){//function
};
{private://access specifier
public://access specifier
void input()
{//function
void display(){//function
int main()
{//main function
//clrscr();
Scholar S1;//Objec
S1.input();//Function
S1.display();
getch();}
OUTPUT:-
HOME TASK :-
H1 CODE:-
#include <iostream>
class student
protected:
int rollno;
public:
void getnum()
cin>>rollno;
void putnum()
};
{
protected:
int marks;
public:
void getmarks()
cin>>marks;
void putmarks()
};
protected:
int score;
public:
void getscore()
cin>>score;
}
void putscore()
};
int total;
student s;
public:
void display()
total=marks+score;
s.getnum();
s.putnum();
};
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
result obj;
obj.getmarks();
obj.getscore();
obj.putmarks();
obj.putscore();
obj.display();
return 0;
OUTPUT:-
H2 CODE:-
#include<iostream>
#include<conio.h>
class localphone{
private:
long phone;
public:
void get()
{
cin>>phone;
void show(){
};
private:
int code;
public:
void get1(){
natphone::get1();
cin>>code;
void show(){
};
class intphone:public natphone
{private:
int country_code;
public:
void get2(){
intphone::get2();
cin>>country_code;
void show(){
natphone::show();
};
int main(){
intphone obj;
obj.get();
obj.show();
return 0;
}
OUTPUT:-
H3 CODE:-
#include <iostream>
class publication
private:
string title;
float price;
public:
void getdata()
string t;
float p;
cin>> title;
cin>> price;
void showdata()
};
class sales
private:
void getdata()
cin>>S1;
cin>>S2;
cin>>S3;
void putdata()
};
private:
int pagecount;
public:
void getdata()
publication::getdata();
sales::getdata();
cin>>pagecount;
void putdata()
publication::showdata();
sales::putdata();
};
private:
float time;
public:
void getdata()
publication::getdata();
sales::getdata();
cin>> time;
void putdata()
publication::showdata();
sales::putdata();
};
int main(void)
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
return 0;
}
OUTPUT:-
Conclusion
In this lab I learnt about class hierarchies, multiple inheritance and multilevel inheritance. How to
differentiate between public and private Inheritance and also the role of constructor and
destructors in derived classes. I implemented multilevel inheritance and multiple inheritance..