Lab Manual Object Oriented Programming
Lab Manual Object Oriented Programming
Lab Manual
Bilal – Farhan
( 243721 )
Saim – ul – Hassan
( 243716 )
Iqra Zahid
( 243666 )
Fatima Kausar
( 243696 )
LAB – Manuals for 2nd
semester .
Contents
Array ( Pre – define )...................................................................................................................................6
Code 1: programe to show the predefined array values.......................................................6
Array ( User – defined )..............................................................................................................................7
Code 2: Program to get array values from user and display them..........................................7
Code 3: Program to get index or size of array and its values at the same thime from the user
and display them .......................................................................................................................9
Code 4: Program to display all of the even and odd numbers from the stored values in a pre
or user defined array................................................................................................................10
Code 5: Program to get name and the roll numbers of the student and stor them in arrayes
and display them on the screen in the form of a table ...........................................................12
Code 6: Program to get the size of array and its values from user and calculate its sum and
product ....................................................................................................................................13
Code 7: Program to get values from user continusly until he/she entered -1 and show the
largest number above them ....................................................................................................15
Code 8 : Program to get the array size and its values at the same time and display the
largest and smaller values stored in array to the user ...........................................................16
Functions...................................................................................................................................................19
Code 9: Program that use function to get your age and display in on screen........................19
Code 10: Program to get number of subjects their obtained and total marks and show the
percentage on the screen ........................................................................................................20
Code 11: Program to get the names and roll numbers of the different student by using
arrays and saprate the data of each student with a line on screen . each task would have to
be performed by using functions.............................................................................................22
Code 12 : Write program to take user input for an array size and values and display it on
screen also tell us the count of negative and positive values of the array and also the smallest
value of the array and perform each task by using the different function for each ................24
Functions (with parameters).....................................................................................................................29
Code 13 : Program to get the marks of 5 subjects from user by using functions and display
its total marks and percentage also by using saprate function for both..................................29
#include<iostream>
Pre- defined Arryas:
using namespace std;
The array that is defined
int main() and also initialized by the
programmer Which can
{ int i,a[5]={12,13,14,15,16}; never be change by the
user during the execution
for(i=0;i<5;i++) of the program .
cout<<"a["<<i<<"]="<<a[i]<<endl;
return 0;
Output :
#include<iostream>
int main()
int i,a[5];
for(i=0;i<5;i++)
cin>>a[i]; }
for(i=0;i<5;i++)
cout<<"a["<<i<<"]="<<a[i]<<endl;
return 0;
Output:
#include<iostream> Note :
cin>>b;
for(i=0;i<b;i++)
cin>>a[i];
for(i=0;i<b;i++)
cout<<"[a"<<i<<"]="<<a[i]<<endl;
return 0;
Output:
#include<iostream>
int main()
int i,a[10]={1,2,3,4,5,6,7,8,9,10};
for(i=0;i<10;i++)
{ cout<<"a["<<i<<"]="<<a[i]<<endl;
for(i=0;i<10;i++)
if(a[i]%2 == 0)
cout<<a[i]<<",";
for(i=0;i<10;i++)
10 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
if(a[i]%2 != 0)
cout<<""<<a[i]<<","; }
Output:
#include<iostream>
#include<string>
int main()
11 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
string name[150];
int rn[5],i;
for (i=1;i<=5;i++)
cin>>name[i];
cin>>rn[i];
cout<<"\n\tName\tRoll no."<<endl;
for (i=1;i<=5;i++)
cout<<"\t"<<name[i]<<"\t"<<rn[i]<<endl;
12 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output :
Code 6: Program to get the size of array and its values from
user and calculate its sum and product .
#include<iostream>
#include<windows.h>
int main()
int i,a[5],sum;
for(i=0;i<5;i++)
{
13 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>a[i];
sum*=a[i];
system("cls");
return 0;
Output:
14 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<iostream>
#include<windows.h>
int main()
int a,g=0;
while(1)
cin>>a;
if(a==-1)
break;
if(a>g)
g=a;
return 0;
Output:
15 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Code 8 : Program to get the array size and its values at the
same time and display the largest and smaller values stored
in array to the user .
#include<iostream>
int main()
cin>>n;
int a[n];
for(int i=0;i<n;i++)
16 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>a[i];
grt=a[0];
mini=a[0];
for(int i=0;i<n;i++)
if(a[i]<mini)
mini=a[i];
if(a[i]>grt)
grt=a[i];
Output:
17 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
18 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Functions
#include<iostream>
int a;
int input()
cin>>a;
int output()
output(); }
19 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
int output(int a)
int main()
{ double i,b=0,c,ts,tm,d;
cin>>ts;
cin>>tm;
20 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
for(i=1;i<=ts;i++)
cin>>c;
b=b+c;
d=(b/tm)*100;
output(d);
Output:
21 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Code 11: Program to get the names and roll numbers of the
different student by using arrays and saprate the data of
each student with a line on screen . each task would have to
be performed by using functions.
#include<iostream>
#include<string.h>
int name();
int line();
int main()
for(int i=1;i<=3;i++)
cout<<"\n"<<i<<".";
name();
line();
int name()
22 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
string a;
cin>>a;
int line()
cout<<"____________________________________________________
_____"<<endl;
Output:
23 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<iostream>
int b,a[1];
int input();
int output();
int countpositive();
int countnegative();
int smallest();
int main()
input();
output();
countpositive();
countnegative();
24 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
smallest();
int input()
cin>>a[i];
25 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int countpositive()
int p=0;
p++;
int countnegative()
int n=0;
This is a function named count
for(int i=0;i<b;i++) negative that is used to display the
total count of the negative numbers
{
entered in an array .
if(a[i]<0)
n++;
26 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int smallest()
{
This is a function named smallest
int s=a[0]; to show the smallest number
from all of the entered values of
for(int i=0;i<b;i++) the array on the screen .
{
if(a[i]<s)
s=a[i];
27 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
28 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include <iostream>
int subjects[numberOfSubjects];
int totalMarks = 0;
void marks() {
cout << "Invalid marks. Please enter a value between 0 and 100.\
n";
i--;
} else {
totalMarks += subjects[i];
29 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int main() {
marks();
cout << "\nTotal Marks: " << totalMarks << "/" << maxMarks << endl;
cout << "Percentage: " << percentage << "%" << endl;
return 0;
Output:
30 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<string.h>
int sum=0;
float per;
sum=sum+a[i];
per=((float)sum/total)*100;
cout<<per;
int main()
string sub[100];
int tm,s;
31 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>s;
int b[s];
cin>>tm;
for(int i=0;i<s;i++)
cin>>sub[i];
for(int i=0;i<s;i++)
cin>>b[i];
percentage( tm, b );
return 1;
32 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
int mini=a[0];
for(int i=0;i<s;i++)
if(a[i]<mini)
mini=a[i];
33 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
a[0]=a[s];
int max=a[0];
for(int i=0;i<s;i++)
if(a[i]>max)
max=a[i];
int main()
int size;
cin>>size;
int a[size];
34 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
for(int i=0;i<size;i++)
cin>>a[i];
max(a,size);
mini(a,size)
Output:
35 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Pass by Value
Code 16: Programe to show the concept of pass by value .
#include<iostream>
cout << "Inside passByValue function, value: " << num << endl;
int main()
cout << "Original value1 (before passByValue): " << value1 << endl;
cout << "Value1 after passByValue (unchanged): " << value1 << endl;
36 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
Pass by Reference
Code 17: Program that shows the working of pass by value
and pass by reference .
#include<iostream>
c=c+10;
int main()
37 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int d=20,b=20;
cout<<"value1 is : "<<d<<endl;
a(d,b);
cout<<"value2 is : "<<b<<endl;
Output:
38 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Structure
Code 18 : Program that show case the working of the
structures.
#include<iostream>
#include<string>
int main()
datamem student;
cin>>student.name;
cin>>student.age;
39 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>student.classs;
cout<<"Name : "<<student.name<<endl;
cout<<"Age : "<<student.age<<endl;
cout<<"Class : "<<student.classs<<endl;
Output:
#include<string>
struct datamem{
40 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int age;
string name;
int classs;
};
{ datamem student;
cin>>student.name;
cin>>student.age;
cin>>student.classs;
age = student.age;
classs = student.classs;
name = student.name;
int main()
int a,cl;
string n;
41 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
input(a,cl,n);
cout<<"Name : "<<n<<endl;
cout<<"Age : "<<a<<endl;
cout<<"Class : "<<cl<<endl;
Output:
42 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<string>
s1.name = "bilal";
s1.age = 19;
s1.clas = 14;
cout<<"Name : "<<s1.name<<endl;
cout<<"Age : "<<s1.age<<endl;
cout<<"Class : "<<s1.clas<<endl; }
43 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<string>
void getcgpa(){
44 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cgpa=3.41;
void display(){
cout<<"Cgpa : "<<cgpa<<endl;
}};
int main ()
student s1;
s1.name = "bilal";
s1.age = 19;
s1.clas = 14;
s1.getcgpa();
cout<<"Name : "<<s1.name<<endl;
cout<<"Age : "<<s1.age<<endl;
cout<<"Class : "<<s1.clas<<endl;
s1.display();
45 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include <iostream>
class MyClass {
public:
MyClass() {
}};
A constructor is a a function that is
int main() {
named as same as the class name
MyClass obj; and it has no return type.
Output:
MyClass() {
// Destructor
~MyClass() {
};
int main() {
MyClass obj;
return 0;
Output:
48 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Banck Account
Code 24: Programe of a BANCK ACCOUNT by using the
classes, objects and member functions .
#include<iostream>
#include<string>
#include<windows.h>
class bankaccount
private:
string accountholdername;
int accountnumber;
double balance;
public:
accountholdername = name;
accountnumber = accountno;
balance = firstbalance;
};
49 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void displayAccountInfo()
if(amount<1)
balance += amount;
cout<<"Depositing $"<<amount<<"...."<<endl;
if(amount>=balance)
50 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
else if(amount<1)
else
cout<<"withdrawing $"<<amount<<"...."<<endl;
};
int main()
{ bankaccount p1;
string name;
int accountn = 0;
51 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>name;
cin>>accountn;
cin>>firstbalance;
p1.banckaccount(name,accountn,firstbalance);
system("cls");
int pin,y=1;
cin>>pin;
system("cls");
int e;
b:
system("cls");
string a;
cout<<"To see your account info plz enter \" 1 \" "<<endl;
52 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cin>>e;
system("cls");
if(e == 1)
p1.displayAccountInfo();
cin>>a;
goto b;
else if (e == 2)
cin>>amount1;
p1.deposite(amount1);
cin>>a;
goto b;
53 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
else if (e == 3)
cin>>amount1;
p1.withdraw(amount1);
cin>>a;
goto b;
else
{ for(int i=0;i<2;i++)
cin>>pin;
system("cls");
{ goto b;
54 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
}}}
double x;
cin>>x;
if(x == firstbalance)
goto b;
} else {
system("cls");
return 0;
55 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Out puts :
Firstly the code will get us our general information and then
proceed further.
After entering our info ,it will ask us about the account number
that we have set already and If we didn’t enter the correct
number then it will give us the opportunity to enter the correct
account number 3 times by showing the following massage …..
56 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Home
57 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Depositing
Withdrawing
58 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Inheritance
#include <iostream>
#include <string>
class student {
59 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
public:
void display(){;
cout<<"student 1 "<<endl;
} };
public:
void displaysub(){
cout<<"Subject "<<endl;
} };
int main()
sub s;
s.display();
s.displaysub();
Output:
60 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Single inheritance
Code 26 : Programe that get the name and subject of an
object which are the private members of two different
classes and display them on the screenby using the functions
.
#include <iostream>
#include <string>
class student {
private:
string name;
public:
void getname(string n)
name = n;
void display(){
cout<<"student 1 : "<<name<<endl;
} };
61 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
private:
string sub;
public:
void getsub(string s)
sub = s;
void displaysub(){
cout<<"Subject : "<<sub<<endl;
} };
int main()
sub s1;
s1.getname("Bilal Farhan");
s1.getsub("Data Analytics");
s1.display();
s1.displaysub();
62 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
63 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Multiple Inheritance
Code 27 : Programe that shows the working of multiple
inheritance.
#include<iostream>
class bilal{
public:
void display1(){
cout<<"i am bilal"<<endl;
} };
class usman{
public:
void display2(){
} };
class hassan{
public:
void display3(){
} };
64 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
class Sharfa{
public:
void display4(){
cout<<"i am sharfa"<<endl;
} };
public:
void big(){
display1();
display2();
display3();
display4();
} };
int main()
{ oop d;
d.big();
return 0; }
65 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
#include<string>
class person{
public:
string name;
int age;
66 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
};
public:
name = n;
age = a;
} };
public:
void display(){
cout<<"Name : "<<name<<endl;
cout<<"Age : "<<age<<endl;
} };
int main()
manager m;
m.getdata("Bilal",19);
m.display();
return 0;
67 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<string>
class shape{
public:
void display(){
cout<<"Shaps :"<<endl;
68 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
};
class circal{
public:
void display(){
cout<<"1.Circal "<<endl;
};
public:
void display(){
shape::display();
circal::display();
cout<<"2.Cylender "<<endl;
};
int main(){
cylender c;
c.cylender::display();
69 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
#include<string>
class engine {
protected:
string enginetype;
public:
70 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
enginetype = et;
void output1() {
};
class wheel {
protected:
string wheeltype;
public:
wheeltype = wt;
void output2() {
};
public:
71 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void getcarinfo() {
input1("tyota");
void discarinfo(){
output1();
output2();
};
int main() {
car c;
c.getcarinfo();
c.discarinfo();
return 0;
Output:
72 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<iostream>
#include<string>
class person{
protected:
int id;
string name;
public:
id = ID;
name = n;
void output(){
cout<<"Name : "<<name<<endl;
73 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cout<<"Id : "<<id<<endl;
};
class acadimic{
protected:
int rollnum,totalm;
float m[4];
public:
rollnum = rn;
totalm = tm;
cin>>m[i];
void output()
74 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
}}
};
public:
void displayper()
{ float per;
int sum = 0;
sum+=m[i];
per = (sum*100)/totalm;
cout<<"percentage : "<<per<<endl;
};
int main()
75 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
student s1;
s1.acadimic::input(721,500);
s1.person::input(2345,"Bilal");
s1.person::output();
s1.acadimic::output();
s1.displayper();
Output:
76 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Method 1 :
#include <iostream>
#include <iomanip>
#include <string>
class date {
protected:
day = dd;
month = mm;
year = yyyy;
}
77 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void output() {
cout << setfill('0') << setw(2) << day << "-"<< setw(2) << month <<
"-"<< setw(4) << year << " ";
};
class time {
protected:
hour = hh;
min = mm;
sec = ss;
void output() {
cout << setfill('0') << setw(2) << hour << ":"<< setw(2) << min <<
":"<< setw(2) << sec << endl;
};
public:
78 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void inputtogather() {
void displaytogather() {
date::output();
time::output();
};
int main() {
datetime dt;
dt.inputtogather();
dt.displaytogather();
return 0;
Output:
79 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Method 2 :
#include<iostream>
class Date {
private:
public:
void input() {
void display() {
80 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
};
class Time {
private:
public:
void input() {
void display() {
81 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
};
public:
void inputAll() {
Date::input();
Time::input();
void displayAll() {
82 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Date::display();
Time::display();
};
int main() {
DateTime dt;
dt.inputAll();
dt.displayAll();
return 0;
Output:
83 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
class students{
public:
void display(){
} };
public:
void display2(){
} };
private:
void display3(){
public:
void display4(){
display3();
} };
rollnum d1;
d1.display();
d1.display2();
d1.display4();
return 0; }
85 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
class vehicle{
public:
int speed;
void displayspeed(){
86 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cout<<"Speed:"<<speed<<"km/h"<<endl;
};
public:
int doors;
void cardetails(){
cout<<"Doors:"<<doors<<endl;
};
public:
int trunk_capacity;
void displaysedan(){
cout<<"Trunk Capacity:"<<trunk_capacity<<endl;
void display(){
displayspeed();
cardetails();
87 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
displaysedan();
};
int main(){
Sedan S;
S.speed=180;
S.doors=4;
S.trunk_capacity=500;
S.display();
Output:
88 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include <iostream>
class person{
public:
void personinfo(){
};
public:
void studentinfo(){
};
89 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
public:
void graduationinfo(){
};
int main(){
graduate g;
g.personinfo();
g.studentinfo();
g.graduationinfo();
return 0;
Output:
90 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<string>
class creature{
private:
string speciesname;
public:
speciesname = name;
void display(){
};
91 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
public:
bool hasfur;
void input(bool y)
hasfur = y;
void display()
};
public:
string breed;
breed = b ;
void display(){
92 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cout<<"bread : "<<breed<<endl;
void bark(){
cout<<"Woof! Woof!"<<endl;
};
int main()
dog d;
d.creature::input("Dog");
d.mammal::input(1);
d.dog::input("Husky");
d.creature::display();
d.mammal::display();
d.dog::display();
d.bark();
93 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
#include<string>
class device{
public:
bool powerstate;
94 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void turnon(){
powerstate = 1;
cout<<"Device is on "<<endl;
void turnoff(){
powerstate = 0;
};
public:
int ram;
string processor;
ram = r;
processor = p;
void display(){
95 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cout<<"Processor : "<<processor<<endl;
};
public:
int batterylife;
double weight;
batterylife = bl;
weight = w;
void display(){
void showinfo(){
computer::display();
laptop::display();
};
96 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int main ()
laptop l;
l.turnon();
l.computer::input(16,"12-ps-2354");
l.laptop::input(90,12.5);
l.showinfo();
Output:
97 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include<iostream>
#include<string>
class country{
protected:
void display(){
cout<<"Crrency : "<<crrency<<endl;
};
protected:
98 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void display(){
cout<<"Province : "<<name<<endl;
};
protected:
public:
void display(){
void addressinfo(){
country::display();
province::display();
city::display();
} };
int main ()
city c;
c.addressinfo(); }
99 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Output:
#include<iostream>
#include<string>
class country{
protected:
void display(){
cout<<"Crrency : "<<crrency<<endl;
};
100 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
protected:
void display(){
cout<<"Province : "<<name<<endl;
};
protected:
public:
void display(){
void addressinfo(){
country::display();
province::display();
city::display();
};
101 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
int main ()
city c;
c.addressinfo();
Output:
102 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
Hierarchical inheritance
#include <iostream>
#include<string>
class animal{
public:
void displayc(){
cout<<"Info of Cat"<<endl;
void displayd(){
cout<<"Info of Dog"<<endl;
};
103 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
public:
string color;
void getcolor(){
void catinfo(){
};
public:
string breed;
void getbreed(){
breed = "Huskey";
void doginfo(){
};
int main(){
104 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
cat c;
dog d;
c.displayc();
c.getcolor();
c.catinfo();
d.displayd();
d.getbreed();
d.doginfo();
Output:
#include <iostream>
#include<string>
105 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
class course{
public:
string coursename,coursecode;
void getcourse(){
void displaycourse(){
};
public:
string teachername;
int credit;
void gettheory(){
credit = 4;
106 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void displayteory(){
};
public:
string labiq;
void getlab(){
void displaylab(){
};
int main(){
theory t;
lab l;
t.getcourse();
107 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
t.displaycourse();
t.gettheory();
t.displayteory();
l.getlab();
l.displaylab();
Output:
108 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
#include <iostream>
#include<string>
class aplince{
public:
string aplincename;
void getapplince(){
void displayaplince(){
};
public:
int capacity;
109 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
void getwasher(){
capacity = 4;
void displaywasher(){
};
public:
int volume;
void getvolume(){
volume = 10;
void displayvolume(){
};
int main(){
refrigerator r;
Washer w;
110 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
w.getapplince();
w.displayaplince();
w.getwasher();
w.displaywasher();
r.getvolume();
r.displayvolume();
Output:
#include <iostream>
class vhicle{
public:
111 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
string brand;
void getbrand(){
brand = "Suzuki";
void displayvahicle(){
cout<<"Brand : "<<brand<<endl;
};
public:
int doors;
void getcar(){
doors = 4;
void displaycar(){
cout<<"Car info"<<endl;
cout<<"Doors : "<<doors<<endl;
};
112 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
public:
string biketype;
void getbike(){
void displaybike(){
cout<<"Bike info"<<endl;
};
int main(){
car c;
bike b;
c.getcar();
c.getbrand();
c.displaycar();
c.displayvahicle();
b.getbike();
b.getbrand();
b.displaybike();
113 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
b.displayvahicle(); }
Output:
#include <iostream>
class person{
public:
void displayperson(){
114 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
};
public:
void displaystudent(){
};
public:
void displayteacher(){
};
int main(){
student s;
teacher t;
s.displayperson();
s.displaystudent();
t.displayperson();
115 | P a g e ( B y B I l a l - F a r h a n )
LAB – Manuals for 2nd
semester .
t.displayteacher();
Output:
116 | P a g e ( B y B I l a l - F a r h a n )