Answer to Question #310303 in C++ for Nitik

Question #310303

Write a program to print the area and parimeter of a triangle having side of 3,4 and 5 unit by creating a class named 'triangle' with the constructor having the three sides as it's parameters.


1
Expert's answer
2022-03-12T12:46:26-0500
#include <iostream>
#include<math.h>


using namespace std;


class Triangle {
private:
	double a, b, c;
public:


	Triangle(double a,double b,double c){
		this->a=a;
		this->b=b;
		this->c=c;
	}


	


	double area(){
		double s = (a+b+c)/2;
		return sqrt(s*(s-a)*(s-b)*(s-c));
	}


	double perimeter(){
		return a+b+c;
	}








};
//The start point of the program
int main(){
	double a, b, c;
	cout<<"Ente a: ";
	cin>>a;
	cout<<"Ente b: ";
	cin>>b;
	cout<<"Ente c: ";
	cin>>c;
	
	Triangle triangle(a,b,c);
	
	cout<<"Area: "<<triangle.area()<<"\n";
	cout<<"Perimeter: "<<triangle.perimeter()<<"\n";


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment