Anda di halaman 1dari 3

ECE/ AE/ BME/ EE/ AVT/ CEM/ ME/ AT/ AMS/ ITE COMPUTER PROGRAMMING Revision (A) for

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

(where is the resistivity of Germanium)

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

Sample dialog 2 (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 ] : 2 Calculate Radius ================ Enter length (in m) : 10 Enter resistance (in ohms) : 0.12 The radius = 3.38 m

Sample dialog 3 (the underlined value is 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 ] : 4_ Invalid choice!

Further revisions : swi_7.c (pg 3-55), ifswi_6d.c (pg 3-19), ifswi_8b.c (pg 3-26)

Revision for Written Test, Oct Sem 2012

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.

Sample dialog (the underlined data is entered by user):


Enter initial angle, final angle and step (in degree) : 0 30 5 x (in deg) ======= 0 5 10 15 20 25 30 sin(x)*sin(x) ========= 0.00 0.01 0.03 0.07 0.12 0.18 0.25 cos(x)*cos(x) ========== 1.00 0.99 0.97 0.93 0.88 0.82 0.75 Sum of squares ============ 1.00 1.00 1.00 1.00 1.00 1.00 1.00

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)

Revision for Written Test, Oct Sem 2012

page 2 / 3

ECE/ AE/ BME/ EE/ AVT/ CEM/ ME/ AT/ AMS/ ITE COMPUTER PROGRAMMING Revision (A) for Written Test
Question 4.

Further revision exercise for Question 1: (Similar to ifswi_8b.c on page 3-26 )


Write a program to display the menu as shown below for the user to input a choice. Use a switch-case structure to check the choice and perform the necessary action. In the case of choice 0, print the word "Byebye". In the case of choice 1, input the coordinates of 2 points and calculate and print the distance between the two points. In the case of choice 2, input the coordinates of 2 points, if their x-coordinates are not equal calculate and print the slope of the line joining the two points, otherwise print message "The slope is infinity because x1=x2". In the case of choice which is out of the range, print the message "Invalid choice!".
Sample dialog 1( the underlined values are entered by user): MENU 0. Exit 1. Calculate the distance between 2 points 2. Calculate the slope of 2 points Enter your choice: 1_ 1 2 1 2 Enter the first point (x1, y1): Enter the second point (x2, y2): Sample dialog 2: MENU 0. Exit 1. Calculate the distance between 2 points 2. Calculate the slope of 2 points Enter your choice: 2_ 1 1 2 5 Enter the first point (x1, y1): Enter the second point (x2, y2):

Distance between the two points is 1.41

The slope is infinity because x1=x2.

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

Question 5 ( loop structure)


Write a C program to print a conversion table showing the Malaysia ringgit values for a given range of Singapore dollar values varying at a step value. Your program should prompt the user to input the conversion rate, the initial dollar value, final dollar value and step value. The conversion formula is given below. Malaysia ringgits = Singapore dollars * conversion rate Tip: It is easier to use a for-loop rather than a while-loop to generate table values Sample dialog (the underlined values are entered by user):
Enter the conversion rate for ringgit: 2.61 Enter initial, final and step values in Singapore $: 10 Singapore $ =========== 10.00 15.00 20.00 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 Malaysia Ringgit ================ 26.10 39.15 52.20 65.25 78.30 91.35 104.40 117.45 130.50 143.55 156.60 169.65 182.70 195.75 208.80 221.85 234.90 247.95 261.00 100 5

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

Revision for Written Test, Oct Sem 2012

Anda mungkin juga menyukai