0% found this document useful (0 votes)
21 views3 pages

Practical No 10oop Manual

Uploaded by

shewalesiddhu73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Practical No 10oop Manual

Uploaded by

shewalesiddhu73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Default Constructor

Q.Write a program to find area of circle Q,Write a program to declare a class


using OOP the value of the radius must be measure having data member add1,add2
accepted from the user in the constructor and add3.Initialize the data member
and the class circle must have two inline using constructor and store their
function. 1.compute() 2.display() addition in third data member using
function and display the addition.
#include<iostream.h>
#include<conio.h> #include<iostream.h>
class circle #include<conio.h>
{ class measure
float r,a; {
public: private:
circle() int add1,add2,add3;
{ public:
cout<<"Enter Radius"; measure()
cin>>r; {
} add1=10;
void compute(); add2=10;
void display(); }
}; void addition()
inline void circle::compute() {
{ add3=add1+add2;
a=3.14*r*r; }
} void display()
inline void circle::display() {
{ cout<<"Addition
cout<<"area="<<a; is="<<add3;
} }
void main() };
{ void main()
clrscr(); {
circle c; clrscr();
c.compute();
measure m;
c.display();
m.addition();
getch();
m.display();
}
getch();
OUTPUT:-
}
Enter Radius:5
OUTPUT:
Area=78.5
Addition is: 20
Parameterized Constructor

Q.Write a program to find area of circle using OOP.The value of the radius must be
accepted from the user in the main program and pass to the parameterized
constructor and the class circle have two inline function. 1.compute() 2.display()

#include<iostream.h>
#include<conio.h>
class circle
{
public:
float r,a;
circle(float x)
{
r=x;
}
void compute();
void display();
};
inline void circle :: compute()
{
a=3.14*r*r;
}
inline void circle :: display()
{
cout<<"Area of circle:"<<a;
}
void main()
{
int p;
cout<<"\n Enter the radius:";
cin>>p;
circle c (p);
c.compute();
c.display();
getch();
}

OUTPUT:-

Enter the radius:5


Area of circle:78.5
Copy Constructor/ Multiple Constructor/Constructor overloading

Q.Write a program to find area of circle


using OOP the value of the radius must be void main()
accepted from the user in the main program {
and pass to the copy constructor and the float p;
class circle must have two inline function. cout<<"\n Enter the radius:";
1.compute() 2.display() cin>>p;
circle c (p);
#include<iostream.h> c.compute();
#include<conio.h> c.display();
class circle circle c1(c);
{ c1.compute();
public: c1.display();
float a,r; getch();
circle(float x) }
{
r=x;
} OUTPUT:-
circle (circle &c)
{ Enter the radius:5
r=c.r; Area of circle=78.5
}
void compute();
void display();
};
inline void circle :: compute()
{
a=3.14*r*r;
}
inline void circle :: display()
{
cout<<"Area of circle="<<a<<endl;
}

You might also like