exa 15.pdf - Computer Basics 1º GITI GITT IEM ITL Name...

This preview shows 1 out of 4 pages.

Computer Basics 1º GITI, GITT, IEM, ITL Oct/2015 1 Name: Last Name: Group: FI_1 FI_3 FI_GITT_eng THE STUDENT MUST FILL OUT HIS NAME ON ALL PAGES 1. Duration: 1h30. 2. Keep all the exam sheets stapled. 3. Use of pencil is permitted. 4. Use of sentences exit, continue, break (apart from its use in switch) is not permitted. Program 1 ( pts) Program 2 ( pts) Program 3 ( pts) Total Program 1: Main program. Loops (3,5 points) A golfer has to shot repeatedly to reach the hole. The location of the hole is known, and located at the x axis between the lower limit HOLE_L and the upper limit HOLE_U, and the golfer is located initial- ly at x=0. The first time the shot will go right side. Define HOLE_L and HOLE_U as constants. The golf player will have to adjust, by try and error procedure, the initial speed (v 0 ) of the golf ball, as well and the required angle (α ) of the shot. Write a main program that will read the speed v 0 and the angle α and will calculate the new positio n of the ball in a loop. The speed v0 is read in m/s (do not validate it) and the angle is read in radians and must be between 0 and π/2 (validate it). Once v0 and α are read, the range of the shot (parabolic motion) has to be calculated, that is the di s- t ance the ball will reach from the golfer’s position in x axes. The distance dist is calculated as: Where g is 9.8 m/s 2 . You may use the sin() function that is at <math.h> library The new calculated position of the ball has to be displayed on the screen, as well as the values HOLE_L and HOLE_U If this position is not in the hole, the golfer will go to the position of the ball and will try again.
Image of page 1

Subscribe to view the full document.

Computer Basics 1º GITI, GITT, IEM, ITL Oct/2015 2 Then, the initial speed v 0 and the angle α are read again. If the ball is at the right side of the hole, the shot will go to the left side (but the angle is always read between 0 and π/2). If the ball is at the left side of the hole, the shot will go to the right side. These steps will be repeated until the ball reaches the hole. The program has to count the number of attempts required by the golfer to reach the hole, and finally display this number. /* * PROGRAM 1. GOLF PLAYER * */ #include <stdio.h> #include <math.h> #define PI 3.1415 #define G 9.8 #define HOLE_L 20.0 #define HOLE_U 30.0 int main(void) { float v0; float alpha; int n; float pos; float dist; pos=0; //initially the ball is at x=0; n=0; dist HOLE_L HOLE_U α v 0 α dist x=0
Image of page 2