OOP's Programs
OOP's Programs
Practical no.1
|Excercise:
Q.1)
#include<iostream.h>
#include<conio.h>
void main()
{
int y,x;
clrscr();
cout<<"Enter the value of X: ";
cin>>x;
y=5*x-5;
cout<<"The value of Y= "<<y;
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
clrscr();
cout<<"Enter the value of a: ";
cin>>a;
if(a>10)
cout<<"\n Hii ";
else
cout<<"\n Bye ";
getch();
}
Serial no-67
Q.3)
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,large;
clrscr();
cout<<"\n Enter the value of A:";
cin>>a;
cout<<"\n Enter the value of B:";
cin>>b;
large=(a>b)?a:b;
cout<<"\n Largest no is :"<<large;
getch();
}
Serial no-67
Practical No.1
||Practical related questions
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
float x;
clrscr();
cout<<"\nEnter the value of A : ";
cin>>a;
cout<<"\nEnter the value of B : ";
cin>>b;
cout<<"\nEnter the value of C : ";
cin>>c;
x=(-b-((b*b)-4*a*c))/2*a;
cout<<"\nX = "<<x;
getch();
}
Serial no-67
Practical No.2
Q.1)
#include<iostream.h>
#include<conio.h>
class student
{
int roll_no;
char name[10];
public:
void output();
void input()
{
cout<<"\n Enter roll no: ";
cin>>roll_no;
cout<<"\n Enter name: ";
cin>>name;
}
};
void student::output()
{
cout<<"\n RollNo= "<<roll_no;
cout<<"\n Name= "<<name;
}
void main()
{
student s;
clrscr();
s.input();
s.output();
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
cout<<"Welcome"<<setw(5)<<"To"<<setw(5)<<"The"<<endl<<"World"<<setw(7)<<"Of"
<<setw(5)<<"C++"<<endl;
getch();
}
Serial no-67
Q.3)
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
*a=50;
delete a;
getch();
}
Serial no-67
Practical No.2
||Practical Related questions
Q.1)
#include<iostream.h>
#include<conio.h>
void main()
{
int a; //local variable
int sum;
clrscr();
cout<<"\n enter global variable value:: a =";
cin>>::a;
cout<<"\n enter local variable value a =";
cin>>a;
sum=::a+a;
cout<<"sum of local and global variable = "<<sum;
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Rate ="<<setw(9)<<"412354"<<endl;
cout<<"Peroid ="<<setw(9)<<"35"<<endl;
cout<<"Year ="<<setw(9)<<"2024"<<endl;
getch();
}
Serial no-67
Practical No.3
Q.1)
#include<iostream.h>
#include<conio.h>
void main()
{
double length, breadth;
float l,area;
int b;
clrscr();
cout<<"\n enter length: ";
cin>>length;
cout<<"\n enter breadth: ";
cin>>breadth;
l=(float)length;
b=(int)breadth;
area=(l*b);
cout<<"\n area of rectangle is: "<<area;
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
void main()
{
float no1,no2;
int avg,a,b;
clrscr();
cout<<"Enter A and B : ";
cin>>no1>>no2;
a=no1;
b=no2;
avg=(a+b)/2;
cout<<"Average is : "<<avg;
getch();
}
Serial no-67
Practical No.3
||Practical Related questions
Q.1)
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b;
int avg;
clrscr();
cout<<"Enter a and b : ";
cin>>a>>b;
(int)a;
(int)b;
avg=((int)a+b)/2;
cout<<"Average by Explicit Conversion: "<<avg;
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
void main()
{
float DSU,OOP,DMS;
int dsu,oop,dms,per;
clrscr();
cout<<"Enter marks in three subjects ";
cout<<"\n DSU=";
cin>>DSU;
cout<<"\n OOP=";
cin>>OOP;
cout<<"\n DMS=";
cin>>DMS;
dsu=DSU;
oop=OOP;
dms=DMS;
per=(dsu+oop+dms)/3;
cout<<"Percentage : "<<per;
getch();
}
Serial no-67
Practical No.4
Q.2)
#include<iostream.h>
#include<conio.h>
class student
{
int roll_no;
char name[10];
public:
void input()
{
cout<<"\n Enter roll no: ";
cin>>roll_no;
cout<<"\n Enter name: ";
cin>>name;
}
output()
{
cout<<"\n RollNo= "<<roll_no;
cout<<"\n Name= "<<name;
}
};
void main()
{
student s;
clrscr();
s.input();
s.output();
getch();
}
Serial no-67
Q.3)
#include<iostream.h>
#include<conio.h>
class square
{
int a,sqr;
public:
void input()
{
cout<<"Enter a number to find it's square : ";
cin>>a;
}
void output()
{
sqr=a*a;
cout<<"\nSquare of "<<a<<" is "<<sqr;
}
};
void main()
{
square s;
clrscr();
s.input();
s.output();
getch();
}
Serial no-67
||Practical Related questions
Q.1)
#include<iostream.h>
#include<conio.h>
class room
{
int length,breadth,height;
public:
void input()
{
cout<<"\n Enter length : ";
cin>>length;
cout<<"\n Enter breadth : ";
cin>>breadth;
cout<<"\n Enter height : ";
cin>>height;
}
void calculate_area()
{
int area;
area=2*(length+breadth)*height;
cout<<"\n Area of room : "<<area;
}
void calculate_volume()
{
int vol;
vol=length*breadth*height;
cout<<"\n Volume of room : "<<vol;
}
};
void main()
{
room r;
clrscr();
r.input();
r.calculate_area();
r.calculate_volume();
getch();
}
Serial no-67
Q.2
#include<iostream.h>
#include<conio.h>
class mean
{
int a,b;
public:
void calculate(int a,int b)
{
int mean;
mean=(a+b)/2;
cout<<"\n Mean of two numbers: "<<mean;
}
};
void main()
{
mean m1;
clrscr();
m1.calculate(4,8);
getch();
}
Serial no-67
Practical No.5
Q.2)
#include<iostream.h>
#include<conio.h>
class staff
{
public:
char name[20];
int basic_salary;
float DA,HRA,gross_salary;
void input()
{
cout<<"\n enter name: ";
cin>>name;
cout<<"\n enter basic salary: ";
cin>>basic_salary;
}
void calculate();
};
void staff::calculate()
{
DA=(74.5*basic_salary)/100;
HRA=(30*basic_salary)/100;
gross_salary=basic_salary+DA+HRA;
cout<<"\n gross salary is = "<<gross_salary;
}
void main()
{
staff s1;
clrscr();
s1.input();
s1.calculate();
getch();
}
Serial no-67
||Practical Related questions
Q.1)
#include<iostream.h>
#include<conio.h>
#define pi 3.14
class circle
{
float radius,area;
public:
void read()
{
cout<<"\n Enter the radius of circle: ";
cin>>radius;
}
void compute()
{
float PI=3.14;
area=PI*radius*radius;
}
void display();
};
void circle::display()
{
cout<<"\n Area of circle is : ";
cout<<area;
}
void main()
{
circle c;
clrscr();
c.read();
c.compute();
c.display();
getch();
}
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
class complex
{
public:
int real,img;
void read()
{
cout<<"\n enter real :";
cin>>real;
cout<<"\n enter imginary : ";
cin>>img;
}
friend complex write(complex,complex);
};
complex write(complex c1,complex c2)
{
complex c3; c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
return c3;
}
void main()
{
complex c1,c2,c3;
clrscr();
c1.read();
c2.read();
c3=write(c1,c2);
cout<<"\n complex number addition is = "<<c3.real<<" +
"<<c3.img<<"i";
getch();
}
Serial no-67
Practical No.6
Q.1)
#include<iostream.h>
#include<conio.h>
class number
{
public:
inline void addition(float a,float b)
{
cout<<"\nAddition : "<<a+b;
}
inline void substraction(float a,float b)
{
cout<<"\nSubstraction : "<<a-b;
}
inline void multiplication(float a, float b)
{
cout<<"\nMultiplication : "<<a*b;
}
inline void division(float a, float b)
{
cout<<"\nDivision : "<<a/b;
}
};
void main()
{
number n;
clrscr();
n.addition(4,3);
n.substraction(10,8);
n.multiplication(-8,2);
n.division(340,10);
getch();
}
Output:
Serial no-67
#include<iostream.h>
#include<conio.h>
inline void area(int len,int bre)
{
cout<<"Area : "<<len*bre;
}
void main()
{
int len,bre;
clrscr();
cout<<"Enter length and breadth : ";
cin>>len>>bre;
area(len,bre);
getch();
}
Output:
Serial no-67
Practical No.7
Q.1)
Write a C++ program to exchange the values of two variables using friend function
#include<iostream.h>
#include<conio.h>
class xyz;
class abc
{
int x;
public:
void getdata()
{
cout<<"Enter 1st value : ";
cin>>x;
}
friend void putdata(abc,xyz);
};
class xyz
{
int y;
public:
void getdata()
{
cout<<"Enter 2nd value : ";
cin>>y;
}
friend void putdata(abc,xyz);
};
void putdata(abc m,xyz n)
{
int temp;
temp=m.x;
m.x=n.y;
n.y=temp;
cout<<"1st value: "<<m.x;
cout<<"2nd value: "<<n.y;
}
void main()
{
abc A;
xyz X;
clrscr();
A.getdata();
X.getdata();
putdata(A,X);
getch();
}
Serial no-67
Output:
Q.2)
WAP to create two classes test1 and test2 which stores marks of a student. Read value
for class objects and calculate average of two tests using friend function.
#include<iostream.h>
#include<conio.h>
class test2;
class test1
{
int m1;
public:
void input()
{
cout<<"Enter marks in 1st test out of 30 : ";
cin>>m1;
}
friend void display(test1,test2);
};
class test2
{
int m2;
public:
void input()
{
cout<<"Enter marks in 2nd test out of 30 : ";
cin>>m2;
}
friend void display(test1,test2);
};
Serial no-67
void display(test1 x,test2 y)
{
int mean;
mean=(x.m1+y.m2)/2;
cout<<"\nMean of two test : "<<mean;
}
void main()
{
test1 t1;
test2 t2;
clrscr();
t1.input();
t2.input();
display(t1,t2);
getch();
}
Output:
Serial no-67
#include<iostream.h>
#include<conio.h>
class calculation2;
class calculation1
{
int a;
public:
void input()
{
cout<<"Enter the value of a : ";
cin>>a;
}
friend void c(calculation1,calculation2 )
};
class calculation2
{
int b;
public:
void input()
{
cout<<"Enter the value of b : ";
cin>>b;
}
friend void c(calculation1,calculation2);
};
void c(calculation1 m,calculation2 n)
{
int add,sub,mul,div;
add=m.a+n.b;
sub=m.a-n.b;
mul=m.a*n.b;
div=m.a/n.b;
cout<<"\n Addition : "<<add;
cout<<"\n Substraction : "<<sub;
cout<<"\n Multiplication : "<<mul;
cout<<"\n Division : "<<div;
}
Serial no-67
void main()
{
calculation1 c1;
calculation2 c2;
clrscr();
c1.input();
c2.input();
c(c1,c2);
getch();
}
Output:
Serial no-67
Practical No.8
Q.1)
Write a Program to define a class having data members principal, duration and rate of
interest. Declare rate _of_ interest as static member variable .calculate the simple
interest and display it.
#include<iostream.h>
#include<conio.h>
class loan
{
int p;
float t;
static float rate;
public:
void input()
{
cout<<"\nENter princiopal amount : ";
cin>>p;
cout<<"\nEnter time peroid : ";
cin>>t;
cout<<"\nEnter rate of intrest : ";
cin>>rate;
}
void output();
};
float loan::rate;
void loan::output()
{
float si;
si=(p*rate*t)/100.0;
cout<<"\nSimple Intrest is : "<<si;
}
void main()
{
loan l;
clrscr();
l.input();
l.output();
getch();
}
Output:
Serial no-67
Practical No.8
||Practical Related questions
Q.1) Write a Program to calculate weight of object at different planets using formula
weight=m*g Where m=mass of object G=gravitational force Declare g as static member
variable.
#include<iostream.h>
#include<conio.h>
class planet
{
float m,g,w;
public:
void getdata();
{
cout<<"\nEnter mass of planet : ";
cin>>m;
cout<<"Enter gravational force of planet : ";
cin>>g;
}
void putdata();
};
void planet::putdata()
{
w=m*g;
cout<<"Weight of planet : "<<w;
}
void main()
{
planet
p;
Serial no-67
clrscr();
p.getdata();
p.putdata();
getch();
}
Output:
Practical No.9
Q.1)
Write a C++ program to declare class ‘Account’ having data members as Account_No
and Balance. Accept this data for 10 accounts and display data of Accounts having
balance greater than 10000.
#include<iostream.h>
#include<conio.h>
#define n 10
class account
{
public:
long int accno;
float bal;
void input()
{
cout<<"\nEnter account no : ";
cin>>accno;
cout<<"Enter acc balance : ";
cin>>bal;
}
void output()
{
cout<<"\nAccount Number : "<<accno;
cout<<"\nBalance : "<<bal;
Serial no-67
}
};
void
main()
{
account a[n];
int i;
clrscr();
for(i=0;i<=n-1;i++)
a[i].input();
cout<<"\nAccpted information as follows ";
for(i=0;i<=n-1;i++)
{
if(a[i].bal>=10000)
{
a[i].output();
}
}
getch();
}
Output:
Serial no-67
Practical No.9
||Practical Related questions
Q.1)
Write a Program to declare a class birthday having data member day, month and year.
Accept this info for object using pointer to array of object and display it.
#include<iostream.h>
#include<conio.h>
class birthday
{
int date,year,month;
public:
void input()
{
Serial no-67
cout<<"\nEnter birth date: ";
cin>>date;
cout<<"Enter birth Month: ";
cin>>month;
cout<<"Enter birth year: ";
cin>>year;
}
void output();
};
void birthday::output()
{
cout<<"\nBirthday : ";
cout<<date<<"|"<<month<<"|"<<year;
}
void main()
{
birthday b[3];
int i;
clrscr();
for(i=0;i<=2;i++)
{
cout<<"\nEnter Birthday info for "<<i+1<<" details";
b[i].input();
}
cout<<"The Result : ";
for(i=0;i<=2;i++)
{
b[i].output();
}
getch();
}
Output:
Serial no-67
Practical No.10
Q.1)WAP to implement default constructor that initializes num1 and num2 as 10 and 20
and prints the values of num1 and num2.
#include<iostream.h>
#include<conio.h>
class constructor
{
int num1,num2;
public:
constructor()
{
num1=10;
num2=20;
}
void display();
};
void constructor::display()
{
cout<<"\nNumber 1 : "<<num1;
cout<<"\nNumber 2 : "<<num2;
}
void main()
{
constructor c;
Serial no-67
clrscr();
c.display();
getch();
}
Output:
Q.2) Define a class student which contain member variables as rollno ,name and course.
Write a program using constructor as "Computer Engineering" for course . Accept this
data for objects of class and display the data.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
int rollno;
char name[10],course[10];
public:
student(int rn,char n[10],char c[20]="ComputerEngineering")
{
rollno=rn;
strcpy(name,n);
strcpy(course,c);
}
void display();
};
void student::display()
{
cout<<"\nName : "<<name;
cout<<"\nRoll No : "<<rollno;
cout<<"\nDepartMent : "<<course;
}
Serial no-67
void main()
{
student s1(67,"shambhu"),s2(71,"rushi","InfoTech");
clrscr();
s1.display();
s2.display();
getch();
}
Output:
Practical No.10
||Practical Related questions
class
student
Serial no-67
{
float per;
char name[10];
public:
student(char n[10],float p)
{
strcpy(name,n);
per=p;
}
void output();
};
void student::output()
{
cout<<"\n Name : "<<name;
cout<<"\n Percentage : "<<per;
}
void main()
{
student s("shambhu",81.88);
clrscr();
s.output();
getch();
}
Output:
Serial no-67
Q.2) WAP to declare class time having data members as hrs, min,sec. Write a
constructor to accept data and display for two objects.
#include<iostream.h>
#include<conio.h>
class time
{
int hr,min,sec;
public:
time(int hour,int minutes,int second)
{
hr=hour;
min=minutes;
sec=second;
}
void output();
};
void time::output()
{
cout<<"\n Hr:"<<hr<<" min:"<<min<<" sec:"<<sec;
}
void main()
{
time t1(3,29,8),t2(4,45,18);
clrscr();
t1.output();
t2.output();
getch();
}
Output:
Serial no-67
Practical No.11
Q.1)
#include<iostream.h>
#include<conio.h>
class furniture
{
char material[20];
int price;
public:
void input()
{
cout<<"enter material:";
cin>>material;
cout<<"\n enter price of material:";
cin>>price;
}
void output()
{
cout<<"\n material="<<material;
cout<<"\n price="<<price;
}
};
class table:public furniture
{
float height;
float surface;
public:
void accept()
{
cout<<"\n enter height of furniture";
cin>>height;
cout<<"\n enter surface of furniture";
cin>>surface;
}
void display()
{
cout<<"\n height is="<<height;
cout<<"\n surface is="<<surface;
}
};
void main()
{
table t;
clrscr();
t.input();
t.accept();
t.output();
t.display();
getch();
}
Serial no-67
Output:
Q.2)
#include<iostream.h>
#include<conio.h>
class employee
{
int emp_no;
char emp_name[20]; char designation[20]; public:
void input()
{
cout<<"\n enter employee no";
cin>>emp_no;
cout<<"\n enter employee name:";
cin>>emp_name;
cout<<"\n enter employee designation:";
cin>>designation;
}
void output()
{
cout<<"\n employee no="<<emp_no; cout<<"\n employee name="<<emp_name;
cout<<"\n designtion="<<designation;
}
};
class salary:public employee
{
int basic_salary;
public:
float hra,da,gross_salary; void accept()
{
cout<<"\n enter basic salary";
cin>>basic_salary;
}
Serial no-67
void display()
{
da=(15*basic_salary)/100; hra=(14.5*basic_salary)/100;
gross_salary=basic_salary+da+hra;
}
};
void main()
{
salary s; clrscr();
s.input();
s.accept();
s.output();
s.display();
getch();
}
Output:
Practical No.11
||Practical Related questions
Q.1)
#include<iostream.h>
#include<conio.h>
class student
{
Serial no-67
int roll_no;
char name[20];
public:
void input()
{
cout<<"enter student roll no:";
cin>>roll_no;
cout<<"enter student name:";
cin>>name;
}
void output()
{
cout<<"\n roll-no="<<roll_no;
cout<<"\n name="<<name;
}
};
void accept()
{
cout<<"\n enter marks of m1=";
cin>>m1;
cout<<"enter marks of m2=";
cin>>m2;
cout<<"enter marks of m3=";
cin>>m3;
}
void display()
{
cout<<"\n m1="<<m1;
cout<<"\n m2="<<m2;
cout<<"\n m3="<<m3;
}
void calculate()
{
total=m1+m2+m3;
percentage=total/3;
cout<<"\n total marks of student="<<total;
cout<<"\n percentage of student="<<percentage<<"%";
}
Serial no-67
};
void main()
{
marks a;
clrscr();
a.input();
a.accept();
a.output();
a.display();
a.calculate();
getch();
}
Output:
Q.2)
#include<iostream.h>
#include<conio.h>
class person
{
Serial no-67
char name[20];
char gender[10];
int age;
public:
void input()
{
cout<<"\n enter name:";
cin>>name;
cout<<"\n enter gender:";
cin>>gender;
cout<<"\n enter age:";
cin>>age;
}
void output()
{
cout<<"\n name="<<name;
cout<<"\n gender="<<gender;
cout<<"\n age="<<age;
}
};
class employee:public person
{
int emp_id;
char comp[20];
long int salary;
public:
void input()
{
cout<<"\n enter emp id:";
cin>>emp_id;
cout<<"\n enter company:";
cin>>comp;
cout<<"\n enter salary:";
cin>>salary;
}
void output()
{
cout<<"\n emp id:"<<emp_id;
cout<<"\n company:"<<comp;
cout<<"\n salary:" <<salary;
}
};
void output()
Serial no-67
{
}
};
void main()
{
programmer p;
clrscr();
p.person::input();
p.employee::input();
p.input();
p.person::output();
p.employee::output();
p.output();
getch();
}
Output:
Practical No.12
Q.1)
#include<iostream.h>
#include<conio.h>
class employee
{
Serial no-67
int emp_id;
char name[20];
public:
void accept()
{
cout<<"\n enter emp_id:";
cin>>emp_id;
cout<<"enter employee name:";
cin>>name;
}
void display()
{
cout<<"\n emp id="<<emp_id;
cout<<"\n employee name="<<name;
}
};
class emp_union
{
int member_id;
public:
void accept()
{
cout<<"\n enter member id:";
cin>>member_id;
}
void display()
{
void accept()
{
cout<<"\n enter basic salary:";
cin>>basic_salary;
}
void display()
{
cout<<"\n basic salary="<<basic_salary;
}
};
void main()
{
emp_info a;
clrscr();
a.employee::accept();
a.emp_union::accept();
Serial no-67
a.emp_info::accept();
cout<<"employee information:";
a.employee::display();
a.emp_union::display();
a.emp_info::display();
getch();
}
Output :
Q.2)
#include<iostream.h>
#include<conio.h>
class student
{ int roll_no;
char name[20];
Serial no-67
public:
void input()
{
cout<<"\n enter roll no:";
cin>>roll_no;
cout<<"enter student name:";
cin>>name;
}
void output()
{
cout<<"\n roll no"<<roll_no;
cout<<"\n name="<<name;
}
};
class subject
{
public:
int OOP,PIC,BEE,DSU,DMS,DTE;
subject(int oop,int pic,int bee,int dsu,int dms,int dte)
{
OOP=oop;
PIC=pic;
BEE=bee;
DSU=dsu;
DMS=dms;
DTE=dte;
}
void get()
{
cout<<"\n OOP="<<OOP;
cout<<"\n PIC="<<PIC;
cout<<"\n BEE="<<BEE;
cout<<"\n DSU="<<DSU;
cout<<"\n DMS="<<DMS;
cout<<"\n DTE="<<DTE;
}
};
class avarage:public student,public subject
{
int total;
public:
avarage(int oop,int pic,int bee,int dsu,int dms,int dte):
subject(oop,pic,bee,dsu,dms,dte)
{
}
void accept()
{
total=(OOP+PIC+BEE+DSU+DMS+DTE)/6;
cout<<"\n avarage of six subject marks:"<<total;
}
Serial no-67
};
void main()
{
avarage a(89,87,67,90,87,80);
clrscr();
a.input();
a.output();
a.get();
a.accept();
getch();
}
Practical No.12
||Practical Related questions
Q.1)
Serial no-67
#include<iostream.h>
#include<conio.h>
class rectangle
{
public: int
length,breadth;
void input()
{
cout<<"\nenter length:";
cin>>length;
cout<<"\n enter breadth:"; cin>>breadth;
}
void output()
{
cout<<"\n length:"<<length;
cout<<"\n breadth:"<<breadth;
}
};
void main()
{
area a;
parameter p;
clrscr();
a.input();
a.output();
a.areaa();
p.input();
p.output();
Serial no-67
p.parameterr();
getch();
}
Output :
Practical No.13
Q.1)
#include<iostream.h>
#include<conio.h>
class employee
Serial no-67
{
public:
int empid;
void empcode()
{
cout<<"enter employee id:";
cin>>empid;
}
void put()
{
cout<<"employee id: "<<empid;
}
};
void putdata()
{
cout<<"\n department:"<<department;
}
};
void main()
{
Serial no-67
programmer p;
manager m;
clrscr();
p.empcode();
p.input();
m.getdata();
p.put();
p.output();
m.putdata();
getch();
Q2)
#include<iostream.h>
#include<conio.h>
class staff
{
public:
int code;
char name[20];
void input()
{
Serial no-67
cout<<"enter staff code:";
cin>>code;
cout<<"enter staff name:";
cin>>name;
}
void output()
{
cout<<"\n code:"<<code;
cout<<"\n name:"<<name;
}
};
{
cout<<"\n subject:"<<subject;
cout<<"\n publication:"<<publication;
}
};
class officer:public staff
{
char grade[20];
public:
void input2()
{
cout<<"\n enter grade:";
cin>>grade;
}
void output2()
{
cout<<"\n grade:"<<grade;
}
};
Serial no-67
class typist:public staff
{
char speed[25];
public:
void get()
{
cout<<"\n enter the speed:";
cin>>speed;
}
void put()
{
cout<<"\n speed:"<<speed;
}
};
class regular:public typist
{
};
void get1()
{
cout<<"enter daily wadges";
cin>>daily_wadges;
}
void put1()
{
cout<<"\n daily wadges="<<daily_wadges;
}
};
void main()
{
teacher t;
officer a;
casual c;
clrscr();
t.input();
t.input1();
a.input2();
c.get();
Serial no-67
c.get1();
t.output();
t.output1();
a.output2();
c.put();
c.put1();
getch();
}
Output:
Practical No.13
||Practical Related questions
Q1
#include<iostream.h>
#include<string.h>
#include<conio.h>
class batsman
{
int total_score,per_match_score[2];
Serial no-67
float avarage;
public:
void calculate_avarage()
{
cout<<"\n enter total score=";
cin>>total_score;
cout<<"enter 1st match score=";
cin>>per_match_score[0];
cout<<"enter 2nd match score=";
cin>>per_match_score[1];
total_score=(per_match_score[0]+per_match_score[1]);
avarage=total_score/2;
}
void display()
{
cout<<"avarage"<<avarage;
}
};
class bowler
{
int no_of_wickets;
public:
bowler(int i)
{
no_of_wickets=i;
}
void display()
{
cout<<"\n no of wickets are:"<<no_of_wickets;
}
};
Q2)
#include<iostream.h>
#include<conio.h>
class staff
{
int code;
public:
void input()
Serial no-67
{
cout<<"\n enter staff code:";
cin>>code;
}
void output()
{
cout<<"\n staff code"<<code;
}
};
};
void main()
{
officer o;
teacher t;
clrscr();
o.input();
t.get();
Serial no-67
o.getdata();
o.output();
t.put();
o.putdata();
getch();
}
Practical No.14
Q.1)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Cricketer
{
public:
Serial no-67
char name[10];
int age;
void input(char n[10],int a)
{
strcpy(name,n);
age=a;
}
void output()
{
cout<<"\nThe Name of cricketer= "<<name;
cout<<"\nThe age= "<<age;
}
};
class Bowler:virtual public Cricketer
{
public:
int wickets;
void getdata(int w)
{
wickets=w;
}
void putdata()
{
cout<<"\nThe wickets= "<<wickets;
}
};
};
void display()
{
cout<<"\nHe is allounder and has:";
Batsman::display();
Bowler::putdata();
cout<<"\nAnd has man of tournament="<<man_of_tournament;
}
};
void main()
{
Allrounder al;
clrscr();
al.input("Shambhuraj",21);
al.getdata(101);
al.accept(560);
al.accept1(18);
al.output();
al.display();
getch();
}
Output:
Q.2)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Master
{
char name[10];
Serial no-67
int code;
public:
void input(char n[10],int c)
{
strcpy(name,n);
code=c;
}
void output()
{
cout<<"\nThe Name="<<name;
cout<<"\nThe code="<<code;
}
};
void main()
{
Employee a;
clrscr();
a.input("Aditya",21);
a.getdata(4500);
a.accept(4);
a.accept1(7000);
a.output();
a.putdata();
a.display();
a.display1();
getch();
}
Output:
void main()
{
Result p;
clrscr();
p.input("Shambhu",42);
p.getdata(78,91);
p.accept(80);
p.output();
p.putdata();
p.display();
p.display1();
getch();
}
Output:
Q2)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Account
Serial no-67
{
char name[10];
int Account_no;
public:
void input(char n[10],int ac)
{
strcpy(name,n);
Account_no=ac;
}
void output()
{
cout<<"\nThe Name = "<<name;
cout<<"\nThe Account number = "<<Account_no;
}
};
void display()
{
cout<<"\nThe current amount account balance="<<current;
}
};
lass Fix_depo_acc:public Saving_acc,public Current_acc
Serial no-67
{
int fix_depo;
public:
void accept1(int f)
{
fix_depo=f;
}
void display1()
{
cout<<"\nThe fix deposit= "<<fix_depo;
}
};
void main()
{
Fix_depo_acc p;
clrscr();
p.input("Aditya",7707);
p.getdata(8700);
p.accept(5400);
p.accept1(21000);
p.output();
p.putdata();
p.display();
p.display1();
getch();
}
Practical No.15
Q.1)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
Serial no-67
int no;
char name[20];
public:
Practical No.16
PRACTICAL RELATED QUESTIONS
#include<iostream.h>
#include<conio.h>
Serial no-67
class book
{
char book_name[20];
char auther_name[20];
float price;
public:
void input()
{
cout<<"\n Enter book name = ";
cin>>book_name;
cout<<"\n Enter auther name = ";
cin>>auther_name;
cout<<"\n enter book price = ";
cin>>price;
}
void output()
{
cout<<"\n book name = "<<book_name;
cout<<"\n book auther = "<<auther_name;
cout<<"\n price = "<<price;
}
};
void main()
{
book b;
book *base=&b;
base->input();
base->output();
getch();
}
Output:
Q.2)
#include<iostream.h>
#include<conio.h>
class box
{
int height,breadth,width;
Serial no-67
public:
void input()
{
cout<<"\n Enter height: ";
cin>>height;
cout<<"\n Enter breadth :";
cin>>breadth;
cout<<"\n Enter idth : ";
cin>>width;
}
void area()
{
int area_;
area_=2*breadth*width+2*height*width+2*breadth*height;
cout<<"\n area of Box= "<<area_;
}
void volume()
{
int volume_;
volume_=height*breadth*width;
cout<<"\n volume of box is = "<<volume_;
}
};
void main()
{
box *bptr,b;
clrscr();
*bptr=b;
bptr->input();
bptr->area();
bptr->volume();
getch();
}
Output :
Q.3)
#include<iostream.h>
#include<conio.h>
Serial no-67
#define n 5
class birthday
{
int day;
char month[20];
int year;
public:
void input()
{
cout<<"\nEnter day : ";
cin>>day;
cout<<"Enter months : ";
cin>>month;
cout<<"Enter year: ";
cin>>year;
}
void output()
{
cout<<day<<"-"<<month<<"-"<<year;
}
};
void main()
{
birthday *bptr=new birthday[5];
birthday *bptr1,b;
*bptr=b;
bptr1=bptr;
int i;
clrscr();
for(i=0;i<n;i++)
{
cout<<"\nEnter Birthday Inormation Member : "<<i+1;
bptr->input();
bptr++;
}
for(i=0;i<n;i++)
{
cout<<"\n Birthday dates of Member "<<i+1<<":";
bptr1->output();
bptr1++;
}
getch();
}
Serial no-67
Output:
Serial no-67
Practical No.17
PRACTICAL RELATED QUESTIONS
#include<iostream.h>
#include<conio.h>
class polygon
{
public:
int width,height;
void input()
{
cout<<"\n Enter width = ";
cin>>width;
cout<<"\n Enter height = ";
cin>>height;
}
};
class rectangle : public polygon
{
public:
void area()
{
int a;
a=height*width;
cout<<"\n Area of Rectangle = "<<a;
}
};
class traingle : public polygon
{
public:
void area()
{
int a;
a=(height*width)/2;
cout<<"\n Area of traingle = "<<a;
}
};
void main()
{
polygon *ptr,b;
clrscr();
ptr->input();
((rectangle *)ptr)->area(); /*by using base class pointer invoke derived class members*/
((traingle *)ptr)->area();
getch();
}
Output :\
Serial no-67
2. Write a program which show the use of Pointer to derived class in multilevel
inheritance.
#include<iostream.h>
#include<conio.h>
class base
{
public:
int a;
void input(int r)
{
a=r;
}
void output()
{
cout<<"\n a = "<<a;
}
};
void main()
{
base *bptr,b;
clrscr();
bptr=&b;
bptr->input(12);
bptr->output();
intermideat i;
bptr=&i;
((intermideat *)bptr)->input(13);
((intermideat *)bptr)->output();
derived d;
bptr=&d;
((derived *)bptr)->input(53);
((derived *)bptr)->output();
getch();
}
Output :
Serial no-67
Practical No.18
PRACTICAL RELATED QUESTIONS
Q.1)
#include<iostream.h>
#include<conio.h>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(float *a,float *b)
{
float temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(char *a,char *b)
{
char *temp;
*temp=*a;
*a=*b;
*b=*temp;
}
void main()
{
int a,b;
float p,q;
char s,c;
clrscr();
Output :
Q.2)
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
double p,q;
clrscr();
getch();
}
Serial no-67
Output :
Q.3)
#include<iostream.h>
#include<conio.h>
#define pi 3.14
void area(int r)
{
float area_of_circle;
area_of_circle=pi*r*r;
cout<<"\n Area of circle is = "<<area_of_circle;
}
void circumference(int r)
{
float cir_of_circle;
cir_of_circle=2*pi*r;
cout<<"\n Circumference of circle = "<<cir_of_circle;
}
Output :
Serial no-67
Practical No.19
2.1Overload the unary operator –(minus) using member function
#include<iostream.h>
#include<conio.h>
class minus
{
int x,y;
public :
minus(int a,int b)
{
x=a;
y=b;
}
void operator -();
void display();
};
void minus :: operator -()
{
x=-x;
y=-y;
}
void minus :: display()
{
cout<<"\n X = "<<x;
cout<<"\n y = "<<y;
}
void main()
{
minus m(-20,30);
clrscr();
cout<<"\n Befor ovearloading : ";
m.display();
-m; //m.operator –()
cout<<"\n After overloading : ";
m.display();
getch();
}
Output:
Serial no-67
class minus
{
int x,y;
public :
minus(int a,int b)
{
x=a;
y=b;
}
friend void operator -(minus &);
void display();
};
void main()
{
minus m(40,-50);
clrscr();
cout<<"\n Befor ovearloading : ";
m.display();
operator -(m); //-m
cout<<"\n After overloading : ";
m.display();
getch();
}
Serial no-67
Output:
Serial no-67
1.2 Write a C++ program to overload unary operators (++) increment and (--)
decrement by using member function
#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int m,int n)
{
a=m;
b=n;
}
a=++a; //pre-increement
b=++b;
cout<<"\n After increment value \n A = "<<a<<"\n B = "<<b;
}
void main()
{
number a(10,20);
clrscr();
a.display();
a.operator ++(); //a++
a.operator --(); //a—
getch();
}
Serial no-67
1.2 Write a C++ program to overload unary operators (++) increment and (--)
decrement by using member function friend function
#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int p,int q)
{
a=p;
b=q;
}
friend void operator ++(number s)
{
s.a=++s.a; //pre_increment
s.b=s.b++; //post-increment
cout<<"\n After increment value \n A = "<<s.a<<"\n B ="<<s.b;
}
void display()
{
cout<<"\n before overloading Value of \n A = "<<a<<"\n B = "<<b;
}
};
void main()
{
number a(45,23);
clrscr();
a.display();
operator ++(a); //++a
operator --(a); //--a
getch();
}
Serial no-67
Practical No.20
PRACTICAL RELATED QUESTIONS
Q.1)
#include<iostream.h>
#include<conio.h>
class complex
{
public:
int real,img;
complex(int r,int i)
{
real=r;
img=i;
}
friend complex operator +(complex &,complex &);
void display();
};
void complex :: display()
{
cout<<"\n"<<real<<" + "<<img<<"i";
}
void main()
{
complex c4(12,13),c3(3,5);
clrscr();
complex c=c4+c3;
cout<<"\n Complex number addition are : "<<endl;
c.display();
getch();
}
Output:
Serial no-67
Q.2)
#include<iostream.h>
#include<conio.h>
class complex
{
public:
int real,img;
complex(int r,int i)
{
real=r;
img=i;
}
complex operator -(complex &);
void display();
};
void complex :: display()
{
cout<<" \n"<<real<<" - "<<img<<"i";
}
complex complex :: operator -(complex &c1)
{
return complex(real - c1.real,img - c1.img);
}
void main()
{
complex c4(12,13),c3(3,5);
clrscr();
complex c=c4.operator -(c3);
cout<<"\n Complex number subtraction are : "<<endl;
c.display();
getch();
}
Output :
Serial no-67
Q.3)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char s[20];
public:
string(char a[20])
{
strcpy(s,a);
}
void operator ==(string &m)
{
if(strcmp(m.s ,s) == 0 )
cout<<"\n string are equal ";
else
cout<<"\n string are not equal ";
}
void display()
{
cout<<"\n string = "<<s;
}
};
void main()
{
string s1("shambhuraj"),s2("Rushi"); // s1(“shambhuraj),s2(“shambhuraj”);
clrscr();
s1.display();
s2.display();
s1 == s2;
getch();
}
Output :
Serial no-67
Practical No.21
PRACTICAL RELATED QUESTIONS
#include<iostream.h>
#include<conio.h>
#include<string.h>
class parent
{
char name[20];
public:
virtual void input(char n[20])
{
strcpy(name,n);
}
virtual void read()
{
cout<<"\n Name in parent class = "<<name;
}
};
class child : public parent
{
public :
char name[20];
void input(char na[20])
{
strcpy(name,na);
}
void read()
{
cout<<"\n Name in child class : "<<name;
}
};
void main()
{
parent *bptr,b;
child c;
clrscr();
bptr=&b;
bptr->input("Rushi");
bptr->read();
bptr=&c;
bptr->input("Raj");
bptr->read();
getch();
}
Output :
Serial no-67
class base
{
public:
void show()
{
cout<<"\n Show in base clss ";
}
virtual void display()
{
cout<<"\n Display in base class virtual function ";
}
};
bptr=&d;
bptr->show(); //this invoke to base class function show()
bptr->display(); //this invoke to derived class function
d.show(); // this invoke to derived class function show()
getch();
}
Output:
Serial no-67
Practical No.22
PRACTICAL RELATED QUESTIONS
#include<iostream.h>
#include<conio.h>
class super
{
public:
virtual void show()=0;
void display()
{
cout<<"\n display in super class " ;
}
};
void main()
{
sub s;
clrscr();
getch();
Output :