Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Design Specifications
- Write, compile and test a C program with appropriate user-defined functions (modular design)
- and comments to calculate parking fee. The program must meet the following specifications:
- a) Prompt the user to input the vehicle type. ‘c’ or ‘C’ for a car, ‘m’ or ‘M’ for a motorbike, ‘t’
- or ‘T’ for a truck. Display a message 'Wrong vehicle typewhen the input character is
- other than specified.
- b) Prompt the user to input the parking time in hours. The parking time is supposed to be a
- positive integer number greater that 0 and less or equal to 24. Therefore, one hour
- minimum charge is applied. The program should validate the input time.
- The program should display a message 'Wrong parking time when the entered time is not
- positive,or Parking time is limited to 24 hrswhen the entered parking time is >24. If the
- entered time is not an integer number (for example 5.3) it must be rounded up (to 6 in this
- example).
- c) Calculates the amount charged based upon the following rates:
- car - $3.50 p/h, motorbike - $1.50 p/h, truck - $8.00 p/h
- However, if parking time is longer than 3 hrs, a 20% discount rate is applied (after 3 hrs).
- If parking time is longer than 10 hrs, a 40% discount is applied (after 10 hrs )
- Output the parking time and the parking fee only for the defined vehicle types as shown
- in the examples.
- Coding Requirements
- Your program must meet the following coding requirements:
- a) The parking hourly rates, the discount time thresholds (3 and 10), the discount rate
- coefficients (0.2 and 0.4) have to be defined as constants
- b) Use bool type ( defined in stdbool.h) to represent logical values trueand false
- c) Your program must have at least the following user-defined functions
- inputParkingTime (…)Prompt the user to enter the parking time. If the
- entered value is not integer, round it up. Return the
- obtained integer value
- validateVechileType (…)Get the vehicle type as a parameter; validate vehicle
- type; if the type is valid, the function returns true,
- otherwise, it returns false. The function must not
- print any messages on the screen
- validateParkingTime(…)Get the parking time as a parameter; validate the
- parking time; if the time is valid (0<time<=24), the
- function returns 0; if it is ≤0 it returns -1; if it is > 24 it
- returns 1. The function must not print any messages
- on the screen
- calculateParkingFee(…)the function returns the parking fee. The function must
- not print any messages on the screen
- showParkingFee(…)the function outputs the parking fee with the two
- decimal point precision in a format shown in the
- example
- You need to define appropriate formal parameters and return type for each function.
- Make sure that you do not use global variables.
- Having been run, your program should produce output formatted as shown below
- (the actual numbers may be different ):
- Example1:
- Enter your vehicle type (C, M or T): c
- Enter parking time (hours): 2
- Car 2 hrs parking fee: $7.00
- Example2:
- Enter your vehicle type (C, M or T): K
- Wrong vehicle type
- Example3:
- Enter your vehicle type (C, M or T): t
- Enter parking time (hours): -7
- Wrong parking time
- Example4:
- Enter your vehicle type (C, M or T): T
- Enter parking time (hours): 26
- Parking time is limited to 24 hrs
- Example5:
- Enter your vehicle type (C, M or T): T
- Enter parking time (hours): 4.2
- Truck 5 hrs parking fee: $36.80
Advertisement
Add Comment
Please, Sign In to add comment