Page 1
Homework 3 Decision statements and Repetition statements
Don’t forget: Paper record to be presented before the end of next class
Task 1. (Decisions) Write a program that requests the user to enter coordinates of three 2D points A, B and C of a triangle with sides a. b, c and computes and displays the triangle angles in degrees. The formulas to compute angles
A, B and C are as follows:
Angle A = arccos( (a*a – b*b – c*c) / (–2 * b * c ) )
Angle B = arccos( (b*b – a*a – c*c) / (–2 * a * c ) )
Angle C = arccos( (c*c – b*b – a*a) / (–2 * a * b ) )
The formulas to compute sides a, b and c are as follows:
Side a =
2
√(π
πΆ
− π
π΅
) 2 + (π
πΆ
− π
π΅
) 2
Side b =
2
√(π
π΄
− π
πΆ
) 2 + (π
π΄
− π
πΆ
) 2
Side c =
2
√(π
π΅
− π
π΄
) 2 + (π
π΅
− π
π΄
) 2
You should design your own functions to compute and return the triangle sides and the triangle angles.
In order to compose secure and reliable program you must insert decision/selection if statements for data validation to test the computed values as valid sides of a realistic triangle. This will help you to avoid undesired side effects as run time errors.
Task 2. (Repetition).
Use a for loop to Write a program to find the largest integer n such that n 3 / pow(n,3) or n*n*n/ is less than 12000. Use a do….while loop to Write a program to find the smallest integer n such that n 2 / pow(n,2) or n*n/ is greater than 12000.
Instructions for paper report preparation:
The report should include header page and sections according the SDM:
ΠΠΎΠΊΡΠΌΠ΅Π½Ρ1 Page 2 of 2
ο·
Analyses (10% of grade)
ο·
Design: Flowchart and Pseudo Code (30% of grade)
ο·
Implementation: Source Code and Comments (50% of grade)
ο·
Testing: Evidence of working program (10% of grade)
Prepare, please the paper record using the following template for the header page:
The text of the task to be displayed here