Ads 468x60px

Monday 19 December 2011

C and C++ program to calculate area of rectangle and triangle using function overloading

#include "iostream.h" #include "conio.h" #include "iomanip.h" #include float area(float a, float b , float c); float area(float l, float w); float area(float r); void main() { char ch; float len, wid, n1, n2, n3, ar; float radius; int choice1; clrscr(); cout << "\n1. For area of triangle "; cout << "\n2. For area of rectangle "; cout << "\n3. For area of circle "; cin >> choice1; if (choice1 == 1) { cout << "\nEnter the three sides of triangle : "; cin >> n1 >> n2 >> n3; ar = area(n1, n2, n3); cout << "\nArea of triangle is: " << ar; } if (choice1 == 2) { cout << "\nEnter the length "; cin >> len; cout << "\nEnter the width: "; cin >> wid; cout << "\nArea of rectangle is: " << area(len, wid); } if (choice1 == 3) { cout << "\nEnter the radius "; cin >> radius; cout << "\n Area of circle " << area(radius); } }

No comments:

Post a Comment