# ECP1016 In-Lab Assignment (Trimester 1 2012/2013

)
Note: BOLD underline denotes user’s input.

Question 1

(Note: Your answers should be fixed to 2 decimal places, and your output should look exactly like the one shown above.

1

Question 2

Enter radius of circle (999 to end): 2.66 radius area 2.66 22.23 Enter radius of sphere (999 to end): 4.789 radius area 4.79 7 2.05 Enter radius of sphere (999 to end): 0 Error!!! circle radius must be greater than zero

(Note: Your answers should be right up to 2 decimal places, and your output should look exactly like the one shown above.

2

Question 3
The reactance of a capacitor Xc is given by the formula: Where  =2f. The frequency and capacitance of the capacitor are given by f and C, respectively. Write a program to prompt the user for the frequency, f and capacitance, C of a capacitor. Then calculate the respective reactance, Xc using the formula given above for 0.1f, 0.5f, f, 5f and 10f. Display the corresponding value of  and the reactance of the capacitor in a neat tabular format as shown in the output below. Reserve 10 spaces for each column.

Enter the frequency, f: 100 Enter the Capacitance, C: 2.3 omega Xc 62.8318 0.0069 314.1590 0.0014 628.3180 0.0007 3141.5901 0.0001 6283.1802 0.0001

(Note: Your answers should be fixed to 4 decimal places, and your output should look exactly like the one shown above.)

3

Question 4
Write a program prompt the user to enter a series of integers number and the last value read is the sentinel 999 (i.e. to end input, the user has to type 999 as the last value) After input terminates, the program should report: 1. The most positive integers value, 2. The most negative integer value, 3. The total number of positive integers entered, 4. The total number of negative integers entered.

Below is how your program output should look like:

Enter an integer Enter an integer Enter an integer Enter an integer Enter an integer Enter an integer Enter an integer Enter an integer Enter an integer End of input Positive The most The most You have You have

(999 (999 (999 (999 (999 (999 (999 (999 (999

to to to to to to to to to

end):3 end):-2 end):4 end):5 end):0 end):-6 end):5 end):66 end):999

integers positive integer is 66. negative integer is -6. entered 6 positive integer(s). entered 2 negative integer(s).

4

Question 5
The inductive reactance of a circuit consisting of an inductor with inductance L in henries at a frequency f in Hz is given by the formula: Where  =2f.

Write a program to prompt the user for the frequency, f and inductance, L of an inductor. Then calculate the respective inductive reactance using the formula given above for 0.1f, 0.5f, f, 5f and 10f. Display the corresponding value of  and the reactance of the inductor in a neat tabular format as shown in the output below. Reserve 15 spaces for each column Enter the frequency, f: 100 Enter the Inductance, L: 3 omega Xc 62.8318 188.4954 314.1590 942.4770 628.3180 1884.9540 3141.5901 9424.7705 6283.1802 18849.5410

(Note: Your answers should be fixed to 4 decimal places, and your output should look exactly like the one shown above.)

5

Question 6
Write a program that simulates a simple calculator. Your program should prompt the user to enter 2 integers and a character. If the character is a ‘+’, the sum is printed; if it is a ‘-‘, the difference is printed; if it is a ‘*’, the product should be printed; if it is a ‘/’, then quotient is printed; and if it is a ‘%’, the remainder is printed. You may use switch statement. Below is how your program should look like:

Enter 2 integers: 2 3 Enter an operator: + x+y=5 Enter 2 integers: 2 3 Enter an operator: & Wrong operator

6