Points will be deducted if you violate the the programming style guide!
|
|
The length of AC is \(\sqrt{x^2-y^2}\). The length of BD is \(\sqrt{|DC|^2+y^2}\), where \(|DC|\) is the length of DC. You are to write a program that works as follows:
|
The red text in the below examples is user input.
|
Example 1 $ ./a.out Enter length x: 3.5 Enter length y (<3.5): 1.8 Enter length z (<3.00167): 2.1 Length of BD is 2.01321 |
Example 2 $ ./a.out Enter length x: 5.1 Enter length y (<5.1): 4.8 Enter length z (<1.72337): 1.5 Length of BD is 4.80519 |
Example 3 $ ./a.out Enter length x: 3.5 Enter length y (<3.5): 1.8 Enter length z (<3.00167): 0.25 Length of BD is 3.28811 |
To explain the conditions for y and z in the above, because we have a triangle,
Hint: A great way to write a program is to get a little bit working, compile and debug, then get a little more work, compile and debug, etc. So you might start trying to get something like this working:
$ ./a.out Enter length x: 5.1 Enter length y (<5.1):
Once you've tested and debugged that, try and extend it so that the following works:
$ ./a.out Enter length x: 5.1 Enter length y (<5.1): 4.8 Enter length z (<1.72337):
Once that works, you can try to finish the whole thing off.
cout << 3/4 << endl;
cout << 20 % 7 << endl;
-0 0.0 '0' "-0.0" false
| Code | User Input | Program Output | Unread Input |
char c; cin >> c; cout << c << endl; |
103.07% 1.2% |
||
int k; cin >> k; cout << k << endl; |
103.07% 1.2% |
||
double x; cin >> x; cout << x << endl; |
103.07% 1.2% |
||
string s; cin >> s; cout << s << endl; |
103.07% 1.2% |
~/bin/submit -c=IC210 -p=hw01 hw.cpp