0% found this document useful (0 votes)
7 views4 pages

Q10 Practical

Uploaded by

asrajput9015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Q10 Practical

Uploaded by

asrajput9015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

//***********Program to calculate area of triangle by using class************

#include<iostream>

#include<math.h>

using namespace std;

class Triangle //Class Traingle

public:

float area(float base, float height, float Area);

float area(float s1,float s2,float s3,float Area);

};

/* ******* Formula of triangle *********/

float Triangle :: area(float base, float height, float Area)

cout<<"\nEnter the base of triangle ";

cin>>base;

cout<<"\nEnter the height of the triangle ";

cin>>height;

Area=0.5*base*height;

cout<<"\nThe area of triangle is "<<Area;

return 0;

/* ****** Herons Formula ********* */

float Triangle :: area(float a,float b,float c,float Area)

cout<<"\nEnter the first side of triangle ";

cin>>a;
cout<<"\nEnter the second side of triangle ";

cin>>b;

cout<<"\nEnter the third side of triangle ";

cin>>c;

// float PERI =a+b+c;

float s = (a+b+c)/2;

float x= (s)*(s-a)*(s-b)*(s-c);

Area=sqrt(x);

cout<<"\nThe area of triangle is "<<Area;

return 0;

/* *******Main Function **************/

int main()

Triangle T;

float base,height,Area,s1,s2,s3;

int k;

char ch;

while(1)

cout<<"\n------MENU------";

cout<<"\n1.To find area using it's base and height ";

cout<<"\n2.To find area using Heron's Formula ";

cout<<"\nEnter your choice :";

cin>>k;

switch (k)

{
case 1:

T.area( base, height, Area);

break;

case 2:

T.area( s1, s2, s3, Area);

break;

default:

cout<<"\nWrong choice";

cout<<"\n Again enter number";

continue;

break;

return 0;

Output:-

You might also like