Академический Документы
Профессиональный Документы
Культура Документы
ASSIGNMENT 2
1. Instruction: Answer all questions
QUESTION 1: Limitless Parking
Many carparks today still operate based on the duration you park your car.The
longer you park, the more you have to pay!Write a C++ program to calculate the
total charge incurred while using a carpark. Assume that you can park in the
carpark for a maximum of 1,000 hours.
The program should prompt the user to enter the parking duration in hours, and
the total carpark charge will be displayed. The following table shows the
charge
Charge (RM)
----------------------------------------------------------------------------First 3 hours
2.00
3.00
2.50
******************************************************************
The following sample runs demonstrate the required format of display and some
possibleinput.
SampleRun1:
Parkingduration(hrs):1
Totalcarparkcharge:RM2.00
SampleRun2:
Parkingduration(hrs):3.5
Totalcarparkcharge:RM5.00
SampleRun3:
Parkingduration(hrs):6
Totalcarparkcharge:RM7.50
Jan June 2015
Page 1
Write a program that calculates a customers parking charge. It should ask the
user to enter number of hoursthe customer has parked . It should then display
the total carparkcharges for the customer.
QUESTION 2: Separate numbers by sign, compute sums and averages of
the numbers
Write a program that asks the user for ten numbers which consist of positive
and negative nonzero integer values. The program should use a loop to compute
the sum and average of all positive integers , the sum of and average of negative
numbers and the sum and average of all the number entered.
Sample run:
Enter ten numbers, I'll echo your number and compute
the sum and average of positive numbers
the sum and average of nonpositive numbers
the sum and average of all numbers
4
value 4
5
value 5
-1
value -1
3
value 3
-4
value -4
-3
value -3
9
value 9
8
value 8
7
value 7
2
value 2
Sum of Positive numbers is 38
Average of Positive numbers is 5.42857
Sum of NonPositive numbers is -8
Average of NonPositive numbers is -2.66667
Sum 30
Average is 3
Press any key to continue
Jan June 2015
Page 2
2. What To submit?
1. A printed report containing the following sections
i.
ii.
iii.
Page 3
Page 4