Está en la página 1de 6

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

Note: BOLD underline denotes users input.

Question 1
Write a program to compute and print the volume of a sphere using the formula: You may use r*r*r to compute r3. Your program will prompt the user to enter a series of radius readings 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 that, it will display the corresponding volume in a neat format as shown in the output below. Your program should also calculate the total volume of all the spheres. Enter radius of sphere (999 to end): 2.3 radius volume 2.30 38.22 Enter radius of sphere (999 to end): 4.555 radius volume 4.55 296.90 Enter radius of sphere (999 to end): 0.999 radius volume 1.00 3.13 Enter radius of sphere (999 to end): 999 The total volume is 338.26

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

Question 2
Write a program to compute and print the area of a circle using the formula: You may use r*r to compute r2. Your program will prompt the user to enter a series of radius readings and the last value read is the sentinel 999 (i.e. to end input, the user has to type 999 as the last value). Check that the radius is greater than zero. (i.e. You may terminate the program if the radius is less than or equal to zero) After that, it will display the corresponding area in a neat tabular format as shown in the output below. Your program should also calculate the average area of all the circles. Enter radius of circle (999 to end): 4 radius area 4.00 50.27 Enter radius of sphere (999 to end): 2 radius area 2.00 12.57 Enter radius of sphere (999 to end): 999 The average area is 31.42

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.

Question 3
The reactance of a capacitor Xc is given by the formula: Where =2f. 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.)

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).

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 =2f.

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.)

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

También podría gustarte