a2 + b2 = c2
| \
| \
| \
| \
| \ c
a | \
| \
|__ \
|__|______ \
b
2.Create a function that will compute for c given that there are inputs for a and b
3.Create a function that will compute for a given that there are inputs for c and b
4.Create a function that will compute for b given that there are inputs for c and a
SCREEN LAYOUT / DESIGN
(Home Screen when programs runs. User can choose a, b, or c.)
Pythagorean Theorem
Compute for
[a] altitude
[b] base
[c] hypotenuse
Input [a| b |c]:_
(When c is clicked this screen/ layout below will be shown. If Y is inputted in the Try Another control, go back to screen 1 else program will exit.)
Pythagorean Theorem
Function 1 (find c)
Input a: 4
Input b: 3
Computed value of c: 5
Try Another [Y/N]:
(When a is clicked, do function 2, If b is clicked do function 3)
Pythagorean Theorem
Function 2 (find a)
Input c: 5
Input b: 3
Computed value of a: 4
Try Another [Y/N]:
Pythagorean Theorem
Function 3 (find b)
Input c: 5
Input a: 4
Computed value of b: 3
Try Another [Y/N]:
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
//print our equation
cout<<"\nOur equation is a2 + b2 = c2"<<endl;
int terminate_condition = 1;
while(terminate_condition==1)
{
//propmt the user to enter the parameter he/she wants to find
cout<<"\nCompute for: "<<endl;
cout<<"[a] altitude"<<endl;
cout<<"[b] base"<<endl;
cout<<"[c] hypotenuse"<<endl;
cout<<"Enter the parameter to find: ";
string parameter;
cin>>parameter;
if(parameter == "a")
{
cout<<"Enter value of b: ";
double b;
cin>>b;
cout<<"Enter value of c: ";
double c;
cin>>c;
double a = (c*c)-(b*b);
a = sqrt(a);
cout<<"Computed value of a: "<<a<<endl;
}
else if(parameter == "b")
{
cout<<"Enter value of a: ";
double a;
cin>>a;
cout<<"Enter value of c: ";
double c;
cin>>c;
double b = (c*c)-(a*a);
b = sqrt(b);
cout<<"Computed value of b: "<<b<<endl;
}
else if(parameter == "c")
{
cout<<"Enter value of a: ";
double a;
cin>>a;
cout<<"Enter value of b: ";
double b;
cin>>b;
double c = (a*a)+(b*b);
c = sqrt(c);
cout<<"Computed value of c: "<<c<<endl;
}
else
{
cout<<"Invalid option, please try again"<<endl;
}
cout<<"Try another condition:"<<endl;
cout<<"Enter Y for yes or N for No: ";
string continue_option;
cin>>continue_option;
if(continue_option=="Y")
{
terminate_condition = 1;
}
else
{
cout<<"Program successfully exited"<<endl;
terminate_condition = 0;
}
}
return 0;
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment