' C++ Program to Find Area of a Rectangle, Circle and Triangle with Class Diagram | Infolet

C++ Program to Find Area of a Rectangle, Circle and Triangle with Class Diagram



 C++ Program to Find Area of a Rectangle, Circle and Triangle with Class Diagram

This is a C++ program to find area of a rectangle, circle and triangle. Class diagram of program also given below.
Manually we can find the area of a rectangle by using equation:


Area = Breadth * Length.

Also we can find the area of a circle by using equation:
 
Area = 3.14 * (radius)2

Also we can find the area of a triangle by using equation:

   a = length of first side
   b = length of second side
   c = length of third side
   s = (a + b+ c)/2

Area = sqrt(s*(s-a)*(s-b)*(s-c))
-where sqrt stands for square root

Class Diagram

 Class Name:areacalc
Data members:
          arr[MAX]:int
          count:int
Methods:
         area(float)
         area(int,int)
         area(float,float,float)

Program Code



#include<math.h>
#include<iostream.h>
#include<conio.h>
class areacalc
{
  private:
  public:void area(float r);
  void area(int a,int b);
void area(float a,float b,float d);
};
void areacalc::area(float r)
{ cout<<"Area of Circle="<<(3.14*r*r);
}
void areacalc::area(int a,int b)
{ cout<<"\n Area of Rectangle="<<(a*b);
}
void areacalc::area(float a,float b,float c)
{ float s,ar;
s=(a+b+c)/2;
ar= sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"\nArea of Triangle="<<ar;
}

void main()
{ clrscr();
areacalc ac;
int r,a,b,c,d;
  cout<<"\n Choose your option";
cout<<"\n...............................\n 1-rectangle\n 2-circle\n 3-triangle";
cout<<"\n Enter your choice :";
cin>>c;
          switch(c)
{
case 1:cout<<"\n enter breadth and length:";
   cin>>a>>b;
   ac.area(a,b);
   break;
case 2:cout<<"\n enter the radious of circle:";
   cin>>r;
   ac.area(r);
   break;
case 3:cout<<"\n enter  the three side of triangle:";
   cin>>a>>b>>d;
   ac.area(a,b,d);
           break;
default:cout<<"invalid choice";
        }
getch();
}

Sample Output

Choose your option
..............................
1-rectangle
2-circle
3-triangle
Enter your choice : 1

Enter Breadth and Length : 10
20
Area of rectangle = 200

C++ Program to Find Area of a Rectangle, Circle and Triangle with Class Diagram



Responses

1 Respones to "C++ Program to Find Area of a Rectangle, Circle and Triangle with Class Diagram"

Apk said...

Thanks a lot...


October 10, 2012 at 12:19 AM

Post a Comment

 

Free Updates

Enter your email address:

Delivered by FeedBurner

Learn C

About Author

Author of infolet.org
Muhammed Aslam PK, He is a MCA(Master of Computer Applications) student. See More here
Contact Us
Return to top of page Copyright © 2010 | Infolet.org Google Converted into Blogger Template by HackTutors