Switch conditional statement

Theory

Floor-space of the room

Report a typo

Citizens of the country named Malevia often experiment with the shapes of their rooms. The rooms can be triangular, rectangular, and round.

Write a program that calculates the floor area of the rooms.

Input data format: The type of the room shape and the relevant parameters.

Output data format: The area of the resulting room.

Note that in Malevia they use the value of 3.14 instead of the number π .

Input format used by the Malevians:

triangle
a
b
c

where a, b, and c are the lengths of the triangle sides.

[HINT] To find the area (triangle), you need to find the semi-perimeter: p = (a + b + c) / 2
Now you can find the area using the formula: S = √(p * (p - a) * (p - b) * (p - c))

[/HINT]

rectangle
a
b

where a and b are lengths of the rectangle sides.

[HINT] To find the area (rectangle), you can use the formula: S = length * width

[/HINT]

circle
r

where r is the radius of the circle.

[HINT] To find the area (circle), you can use the formula: S = π * r^2

And remember what π is in this country

[/HINT]

Note that the input values (a, b, c, r) are doubles, and your answer should be too.

Sample Input 1:

rectangle
4
10

Sample Output 1:

40.0
Write a program in C++





Create a free account to access the full topic