Sei sulla pagina 1di 6

ATGE2053 C++ ASSIGNMENT Q1.

a) Write a program to calculate and display the value of a vehicle as its value depreciates to a minimum value as stipulated by the user. Allow the user to enter the purchase price, the rate of depreciation and the minimum value. Display the results in tabulated form as shown in Figure Q1. Display the number of year taken to depreciate to the minimum value at the end of the table. All values are to be displayed in currency format, except year.

2013

Figure Q1

Q1.b) Plastic shrinkage cracks occur when the surface of the concrete dries rapidly and shrinks before it can gain sufficient tensile strength to resist cracking. When ambient conditions and concrete temperatures combine to produce conditions that create a high evaporation rate, the chances of the surface drying prematurely and shrinkage cracks forming increases. A contractor needs to know the evaporation rate of the environment to determine how quickly initial curing procedures will have to be started. Given that the evaporation rate, E, can be estimated using the following formula, write a program to calculate E based on the environmental measurement data supplied by the contractor. E = (Tc2.5 rTa2.5)(1 + 0.4V ) 10 6 (empirical unit)

ATGE2053 C++ ASSIGNMENT

2013

where E = evaporation rate( lb/ft2/h), Tc = concrete temperature( F ), Ta = air temperature( F ), r = relative humidity in percent/100 and V = wind velocity (mph) As an example, on a day where the ambient air temperature is 80 F (27 C) , the relative humidity is 50%, the concrete temperature is 87 F (31 C ), and the wind velocity is12 mph (19 km/h), the resulting rate of evaporation is about 0.24 lb/ft2/h (1.15 kg/m2/h). Let the user choose to enter the data either in empirical or SI(metric) units. Your program should ensure the data are in the correct unit of measurement prior to calculation. When the rate of evaporation exceeds 0.2 lb/ft2/h (1 kg/m2/h), display a warning message to the contractor. Q2. a) Write a program to help the user to convert denomination in coins to ringgit. Read the quantity of coins in various denominations (5 sen, 10 sen, 20 sen, 50 sen) and convert the total amount into ringgit. Write a function to do the conversion. Sample output

Q2. b) Write a program to continuously help the user to calculate the impedance of a resistor, inductor and capacitor, given that the impedance of a resistor is always same as the resistance at all frequencies; the impedance of an inductor is ZL = 2fL while a capacitor is ZC = 1/(2fC), where f is the frequency of the sinusoidal signal applied to the component. Prompt the user to enter the value for resistors in kOhm, inductors in mHenry and capacitors i n Farad. When reading the values for capacitor, validate the values for frequency and capacitance. If the user enter 0 for either one, the program needs to remind the user and prompt for correct inputs. If the user still insists on 0, the program should not result in run -time error. Provide an option for the user to quit. All values are to be shown in scientific format with 2 decimal places. Write a separate function for each of the component

ATGE2053 C++ ASSIGNMENT

2013

type. Display the impedance in ohm.

Figure Q2

Q3.a) Write a nested for loop to display the stack triangles as shown in Figure Q3.

Figure Q3

ATGE2053 C++ ASSIGNMENT

2013

Q3.b) Write a program that prompts the user to enter customer type and total amount of electricity consumed in a month. By using the tariff rates shown in Table Q3, display the final bill to the customer. Display the bill in currency format. After displaying the bill for one customer, ask the user whether he/she wants to proceed with another customer. If the reply is positive, prompt the user for the customer type and consumption of the next customer. The program must keep track of the total number of customer in each category, the total bill accumulated in each category and the grand total of all the bills processed. At the end of entry, when the user chooses not to continue, the program must display a summary of the bills processed. Type of customer Domestic Consumption First 200 unit Next 200 unit Next 100 unit Remaining First 250 unit Next 200 unit Remaining All units Rates 20 sen/unit 30 sen/unit 40 sen/unit 50 sen/unit 40 sen/unit 55 sen/unit 70 sen/unit 55 sen/unit

Commercial

Industrial

Table Q3 Write this program in two versions, one with a multiple nested if/else structure and another with switch statements plus multiple if/else.

Q4.

Write a C++ program to read a series of k numbers and display the following: i. average of the series of numbers ii. the largest number among the series iii. the smallest number among the series iv. the total of numbers greater than the average Your program may use dynamic variables to capture a series of k numbers. Sample output:

ATGE2053 C++ ASSIGNMENT

2013

Q5.

Write a program to assign passenger seats in an airplane. Assume a small airplane with seat numberings as follow: 1ABCD 2ABCD 3ABCD 4ABCD 5ABCD 6ABCD 7ABCD The program should display the seat pattern with an 'X' to indicate the seats already taken. For example, after seats 1A, 2B, and 4C are taken, the display should look like: 1XBCD 2AXCD 3ABCD 4ABXD 5ABCD 6ABCD 7ABCD After displaying the seats available, the program should prompt for the seats desired. The user can type in a seat, and then the display of available seats should be updated. This continues until all seats are filled or until the user signals that the program should end. If the user types in a seat that is already assigned, the program should inform that that seat is occupied and ask for another choice. Sample output:

ATGE2053 C++ ASSIGNMENT Q6. Write a program to read the names and marks of 5 students from either the keyboard or file. A data file need to be created first with the following contents. Mark Jason Amy Wong Fred 56 40 82 23 93

2013

If the user chooses to read from file, the program needs to read the contents of the file. In the case of file open failure, display an error message and terminate the program. Regardless of where the data is read from, the program then needs to sort the list in alphabetical order, assign a grade to each student and display the updated list. It should then display a menu that provides the functions as shown in Figure Q6. Write a function for each item in the menu, except item 5. Call the function from main as and when necessary. The range of marks for each grade is given in Table Q6.

Figure Q6 This program can be written using multiple arrays but the most convenient approach will be using structure. Table Q6 Marks Grade 90 - 100 A 70 - 89 B 50 - 69 C 40 - 49 D less than 40 F ~ END OF ASSIGNMENT~ ~~ HAPPY WORKING ~~ . .

Potrebbero piacerti anche