0% found this document useful (0 votes)
7 views

Practical No 4S OOP

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)
7 views

Practical No 4S OOP

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/ 5

Q.Write a program to find area of circle Q.

Write a program to find area of


using OOP such that the class circle must rectangle using OOP such that the class
have 3 member function namely: rectangle must have 3 member function
1.read() to accept the radius from the user namely:
2.compute() for calculating the area 1.read() to accept the radius from the user
3.display() for display the result 2.compute() for calculating the area
3.display() for display the result
#include<iostream.h>
#include<conio.h> class #include<iostream.h> #include<conio.h>
circle { class rectangle
float { float
r,a; l,w,a;
public: public:
void read() void read()
{ {
cout<<"Enter the radius:"; cout<<"Enter the length and width:";
cin>>r; cin>>l>>w;
} }
void compute() void compute()
{ {
a=3.14*r*r; a=l*w;
} }
void display() void display()
{ {
cout<<"Area="<<a; cout<<"\n Area="<<a;
} }
}; };
void main() void main()
{ { clrscr();
clrscr(); rectangle r;
circle c; r.read();
c.read(); r.compute();
c.compute(); r.display();
c.display(); getch();
getch(); }
} OUTPUT:-
OUTPUT:- Enter the length and width:3
Enter the radius:5 3
Area=78.5 Area=9
Q.Write a program to find area of triangle using Q. Write a program to define a class student having
OOP such that the class triangle must have 3 data members roll no,name,branch, grade.Accept &
member function namely: display data for one object. Define the member
1.read() 2.compute() 3.display() function inside the class

#include<iostream.h> #include<iostream.h>
#include<conio.h> #include<conio.h>
class circle class student
{ { public:
float b,h,a; int rollno;
public: char name[10],branch[10],grade; void
void read() read()
{ {
cout<<"Enter the base and height:"; cout<<"Enter roll no:"; cin>>rollno;
cin>>b>>h; cout<<"Enter the name:";
} cin>>name;
void compute() cout<<"Enter the branch:";
{ cin>>branch;
a=0.5*b*h; cout<<"Enter the grade:";
} cin>>grade;
void display() }
{ void display()
cout<<"Area of Triangle="<<a; {
} cout<<"\n\t \t Student Details\n"<<endl;
}; cout<<"Roll No\t \t Name \t \t Branch\t
void main() \t Grade"<<endl;
{ clrscr(); cout<<"\n------------------------\n"
triangle t; cout<<rollno<<"\t \t"<<name<<"\t
t.read(); \t"<<branch<<"\t
t.compute(); \t"<<grade<<endl;
t.display(); }
getch(); };
} void main()
{
student s; s.read();
OUTPUT:- s.display();
getch();
Enter the base and height: 3 }
4
Area of triangle=6 OUTPUT:
Enter roll no:10
Enter the name:Siddhesh
Enter the branch:SYIF
Enter the grade:A

Student Details
Roll No Name Branch Grade
10 Siddhesh SYIF A

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy