To write a C++ program to display area of circle and rectangle using classes with primitive data members.
Algorithm:
Step 1: Start the program.
Step 2: Create a class area and declare the variables.
Step 3: Call the appropriate functions using object in the main function.
Step 4: Stop the program.
Program Code:
#include<iostream.h>
#include<conio.h>
#define pi 3.14
class area
{
int area1,area2;
public:
void circle(int r);
void rectangle(int l,int b);
};
void area::circle(int r)
{
area1=pi*r*r;
cout<<"Area of the Circle:"<<area1;
}
void area::rectangle(int l,int b)
{
area2=l*b;
cout<<"Area of the Rectangle:"<<area2;
}
void main()
{
int r,l,b;
clrscr();
area a;
cout<<"\nEnter the radius of the circle:";
cin>>r;
a.circle(r);
cout<<"\n\nEnter the length and breadth of the rectangle:";
cin>>l>>b;
a.rectangle(l,b);
getch();
}
Output:
Enter the radius of the circle:12
Area of the circle:452
Enter the length and breadth of the rectangle:12 6
Area of the rectangle:72
Post A Comment:
0 comments: