B.Sc. (Hons.) Electrical/Electronics Engineering Degree Examinations SECOND SEMESTER 2011/2012 SESSION EEG206: COMPUTER PROGRAMMING I ATTEMPT ALL QUESTIONS TIME ALLOWED: 2 Hours
PART B [140 marks]
Given the equations of motion as s = u*t + (1/2)*a*t 2, v = u + a*t and v 2 = u2 + 2*a*s, write a C++ programme that has the following functions with the tasks as stated: (i) banner: Displays information “Welcome to the Equation of Motion Application Programme” and shows the three equations in next three line in this format; 1. First Equation: s = u*t + (1/2)*a*t2, 2. Second Equation: v = u + a*t, 3. Third Equation: v 2 = u2 + 2*a*s and then followed by a new line that echo the following statement, “Choice the Equation to Solve => ”. The banner function returns the choice of equation of the user to the main function. [30 marks] (ii) input_parameter: the function receives the choice of the user and determine the appropriate variables of the equation to use and hence ask the user once again to input the three variables of the equation and assign those values to three variables var1, var2 and var3 in the main function. The decision as to the choice of variables to be assigned values to should be implemented with the if – statement. [40 marks] (iii) analysis: the function receives the choice of the user together with the values of three variables and then compute the result of the expression chosen by the user by employing the switch statement to achieve that. However, if the user’s choice is outside the predefined ones in the input_parameter function a value of -1 should be returned as a result. [40 marks] (iv) output: the function receives the three variables returned by the user and the result obtained in the analysis function and print them on the four different lines on screen. However, if the result of the analysis function is -1, the following statement should be echoed to the screen, “The Choice of Equation is not a Valid One.” [30 marks]
The programme should be able to loop back and ask the user if he/she wants to do another computation.