Computer Science, asked by mahe3300, 11 months ago

Write a c++ program to compute area to triangle and circle by overloading the area () function

Answers

Answered by 247him
10

#include<iostream.h>

#include<conio.h>

# define _PI_         3.14159265

// area of triangle

float area(int base, int height) {

   return 0.5*base*height;

}

// area of circle

float area(int radius) {

 return _PI_*radius*radius

}

void main() {

   float radius, base, height;

   clrscr();

  // Circle

  cout<<"Enter radius of the circle";

  cin>>radius;

  cout<<"Area of Circle: "<<area(radius);

   getch();

  // Triangle

   cout<<"Enter base of the triangle";

   cin>>base;

   cout<<"Enter height of the triangle";

   cin>>height;  

   cout<<"Area of Triangle: "<<area(base,height);

   getch();

}


Similar questions