Odpowiedź :
#include <iostream>
using namespace std;
float trojkat (float a, float h)
{
float p;
p=0.5*a*h;
return p;
}
float kwadrat (float a)
{
float p;
p=a*a;
return p;
}
float trapez (float a, float b, float h)
{
float p;
p=((a+b)*h)/2;
return p;
}
float prostokat (float a, float b)
{
float p;
p=a*b;
return p;
}
float rownoleglobok (float a, float h)
{
float p;
p=a*h;
return p;
}
int main()
{
int w;
float a,b,h;
cout << "1-trojkat" << endl << "2-kwadrat" << endl << "3-trapez" << endl;
cout << "4-prostokat" << endl << "5-rownloeglobok" << endl;
cout << "Wybrana opcja: ";
cin >> w;
switch (w)
{
case 1:
cout << "Podaj a: ";
cin >> a;
cout << "Podaj h: ";
cin >> h;
cout << "Wynik to: " << trojkat(a,h);
break;
case 2:
cout << "Podaj a: ";
cin >> a;
cout << "Wynik to: " << kwadrat(a);
break;
case 3:
cout << "Podaj a: ";
cin >> a;
cout << "Podaj b: ";
cin >> b;
cout << "Podaj h: ";
cin >> h;
cout << "Wynik to: " << trapez(a,b,h);
break;
case 4:
cout << "Podaj a: ";
cin >> a;
cout << "Podaj b: ";
cin >> b;
cout << "Wynik to: " << prostokat(a,b);
break;
case 5:
cout << "Podaj a: ";
cin >> a;
cout << "Podaj h: ";
cin >> h;
cout << "Wynik to: " << rownoleglobok(a,h);
break;
default:
cout << "Błędna opcja" << endl;
break;
}
return 0;
}