Write a program to display area of circle and rectangle using classes with primitive data members.
Answers
This is a Java Program to Find Area of Square, Rectangle and Circle using Method Overloading. We declare three methods of same name but with different number o
Following are the program in C++ programming language given below
Explanation:
#include<iostream> // header file
using namespace std; // namespace
void cal_circle(int r1); // function prototype
void cal_rectangle(int l1,int b1); // function prototype
class Main // class
{
float ar1; // variable declaration
int ar2;// variable declaration
public: // access modifier
void cal_circle(int r1) // function definition of circle
{
float pi=3.14;
ar1=pi*r1*r1; // calculating area of circle
cout<<"Area of circle: "<<ar1; // display
}
void cal_rectangle(int l1,int b1) // function definition
{
ar2=l1*b1; // calculate the area of rectangle
cout<<"AREA OF THE RECTANGLE : "<<ar2 ; // display
}
};
int main() // main function
{
Main ob; // create object
int r1,l1,b1; // variable declaration
cout<<"Enter the radius : ";
cin>>r1; // Read the area by circle
ob.cal_circle(r1); // calling method
cout<<"\nEnter the length and breadth:";
cin>>l1>>b1; // Read length and breadth
ob.cal_rectangle(l1,b1); // calling
}
Output:
Enter the radius : 12
Area of circle: 452.16
Enter the length and breadth:
1
2
AREA OF THE RECTANGLE : 2
Description of program is given as
- Create a class Main in this class we creating the cal_circle(),cal_rectangle() function is used to calculating the area of the circle .
- In the main method we Read the value of radius r1,length l1 and breadth in b1 and call the function by create the object of Main class .
Learn More :
- brainly.in/question/15382313