103k views
4 votes
Given parameters b and h which stand for the base and the height of an isosceles triangle (i.e., a triangle that has two equal sides), write a C program that calculates: The area of the triangle; The perimeter of the triangle; And The volume of the cone formed by spinning the triangle around the line h The program must prompt the user to enter b and h (both of type double) The program must define and use the following three functions: Calc Area (base, height) //calculates and returns the area of the triangle Calc Perimeter (base, height) //calculates and returns the perimeter Calc Volume(base, height) //calculates and returns the volume

User Mark Meeus
by
4.7k points

1 Answer

2 votes

Answer:

The area of the triangle is calculated as thus:


Area = 0.5 * b * h

To calculate the perimeter of the triangle, the measurement of the slant height has to be derived;

Let s represent the slant height;

Dividing the triangle into 2 gives a right angled triangle;

The slant height, s is calculated using Pythagoras theorem as thus


s = √(b^2 + h^2)

The perimeter of the triangle is then calculated as thus;


Perimeter = s + s + b


Perimeter = √(b^2 + h^2) + √(b^2 + h^2) +b


Perimeter = 2√(b^2 + h^2) + b

For the volume of the cone,

when the triangle is spin, the base of the triangle forms the diameter of the cone;


Volume = (1)/(3) \pi * r^2 * h

Where
r = (1)/(2) * diameter

So,
r = (1)/(2)b

So,
Volume = (1)/(3) \pi * ((b)/(2))^2 * h

Base on the above illustrations, the program is as follows;

#include<iostream>

#include<cmath>

using namespace std;

void CalcArea(double b, double h)

{

//Calculate Area

double Area = 0.5 * b * h;

//Print Area

cout<<"Area = "<<Area<<endl;

}

void CalcPerimeter(double b, double h)

{

//Calculate Perimeter

double Perimeter = 2 * sqrt(pow(h,2)+pow((0.5 * b),2)) + b;

//Print Perimeter

cout<<"Perimeter = "<<Perimeter<<endl;

}

void CalcVolume(double b, double h)

{

//Calculate Volume

double Volume = (1.0/3.0) * (22.0/7.0) * pow((0.5 * b),2) * h;

//Print Volume

cout<<"Volume = "<<Volume<<endl;

}

int main()

{

double b, h;

//Prompt User for input

cout<<"Base: ";

cin>>b;

cout<<"Height: ";

cin>>h;

//Call CalcVolume function

CalcVolume(b,h);

//Call CalcArea function

CalcArea(b,h);

//Call CalcPerimeter function

CalcPerimeter(b,h);

return 0;

}

User Kamilyrb
by
3.7k points