Professional Documents
Culture Documents
Written Test
Question 1 Write a program to compute the value of the length (L), the Resistance (R), or the cross-sectional radius (r) of a cylindrical conductor made of Germanium according to users choice. Given that:
r2R L
R L r2
L R
The program should include the following: a) Define the resistivity of Germanium as 0.43 (ohm m). b) Declare the necessary variables. c) Print a short menu to prompt for the users choice. d) Use a switch-case structure to check the users choice and perform the necessary action. In the case of choice 0, print the word "Bye-bye". In the case of choice 1, 2 or 3, read the necessary input values, calculate and print the output. Print the message "Invalid choice!" if the users choice is out of range. Sample dialog 1 (the underlined values are entered by the user):
This program will calculate Length, Radius or Resistance of a cylindrical conductor made of Germanium given the other two values. Enter a choice [ 0=Quit, 1=Length, 2=Radius, 3=Resistance ] : 1 Calculate Length ================ Enter radius of X-section (in m) : 2.5 Enter resistance (in ohms) : 0.12 The length = 5.48 m
Further revisions : swi_7.c (pg 3-55), ifswi_6d.c (pg 3-19), ifswi_8b.c (pg 3-26)
page 1 / 3
ECE/ AE/ BME/ EE/ AVT/ CEM/ ME/ AT/ AMS/ ITE COMPUTER PROGRAMMING Revision (A) for Written Test
Question 2 Write a C program to print a table showing the squares of sine and cosine values for the angles over a given range at a regular step interval. The table should also show the sum of the two corresponding square values. Prompt the user to input the initial angle, final angle and step angle for the table. Hints: Define to be 3.1416. To convert degree to radian, use the formula, radian = degree * /180.
Further revisions : loops_4m.c (pg 4-27), wh_9.c (pg 4-41), wh_12.c (pg 4-42)
Question 3 In a simple harmonic motion, given the angular frequency () and the two coefficients (A and B), the frequency, the amplitude and the distance at a particular time (t) can be calculated as follows: Frequency = Amplitude =
A 2 B2
Distance = A Cos(t) + B Sin(t) Write a program that includes the following: a) Use the angular frequency () as 4.472, the coefficients A and B as 0.6 and 0.2 respectively. b) Calculate and display the frequency and the amplitude. c) Display a table of distance for a range of time as shown below. Allow the user to have his own range of time and interval. Also, display the average distance. Sample dialog (the underlined values are entered by user): Simple Harmonic Motion ====================== Angular Frequency, W = 4.4720 Frequency = 0.7117 Amplitude = 0.6325 Range of time and interval to tabulate: Enter the time range(sec): 10.00 10.15 Enter the time interval(sec): 0.03 TIME(sec) DISTANCE(cm) ========= ============ 10.00 0.5785 10.03 0.5391 10.06 0.4901 10.09 0.4322 10.12 0.3666 10.15 0.2943 The average distance for time from 10.00 sec to 10.15 sec is 0.45 cm
Further revisions : wh_8.c (pg 4-40), fo_3.c (pg 4-49), loops_4l.c (pg 4-27)
page 2 / 3
ECE/ AE/ BME/ EE/ AVT/ CEM/ ME/ AT/ AMS/ ITE COMPUTER PROGRAMMING Revision (A) for Written Test
Question 4.
Save your file as WT-rev4.c Submit your program to http://153.20.12.82 for marking. Click on Ceilidh relevant Course Branching WT-rev4.c
End of table. Save your file as WT-rev5.c Submit your program to http://153.20.12.82 for marking. Click on Ceilidh relevant Course Loops WT-rev5.c Further revisions on loops : wh_11.c (pg 4-42), fo_4.c (pg 4-50) page 3 / 3