A car manufacturer is creating a car concept. A variety of funcitons will be controlled by buttons on the dashboard
The driver can push items on a digital menu:
View speed
View speed history
Update speed history
View date
View mileage
Open windows
Close windows
Aircon
The following identifier table for global variables used in the system has been created
Identifier
Data Type
Description
currentSpeed
INTEGER
the current speed of the car
speedHistory
ARRAY[1:10] OF INTEGER
randon samples of speed during the last hour of driving
dateToday
DATE
today's date
windowStatus
BOOLEAN
the current status of the windows - open or close
airconStatus
BOOLEAN
the current status of the aircon - on or off
PROCEDURE viewSpeed() - displays the current speed
PROCEDURE viewSpeedHistory() - displays the 10 speed samples, and also displays the average speed, max speed and min speed value.
FUNCTION updateSpeedHistory(index:INTEGER, newValue:INTEGER) RETURNS BOOLEAN - updates the speedHistory array with newValue at index. If newValue is the same as the current value, it returns FALSE, otherwise it returns TRUE
PROCEDURE viewDate() - displays today's date.
PROCEDURE viewMileage() - displays the car's mileage.
FUNCTION openWindows() RETURNS BOOLEAN - The function simply returns TRUE
FUNCTION closeWindows() RETURNS BOOLEAN - The function simply returns FALSE
FUNCTION updateAircon() RETURNS STRING - updates the airconStatus and returns a sentence stating the current status eg "The aircon is now on!".
CALL displayMenu()
INPUT choice
WHILE TRUE DO
CASE OF choice
1: CALL viewSpeed()
2: CALL viewSpeedHistory()
3: INPUT newVal
INPUT index
result ← updateSpeedHistory(newVal, index)
IF result = TRUE THEN
OUTPUT "Speed History Updated"
ELSE
OUTPUT "No change in Speed History"
END IF
4: CALL viewDate()
5: CALL viewMileage()
6: windowStatus ← openWindows()
7: windowStatus ← closeWindows()
8: CALL updateAircon
Otherwise: OUTPUT "Error"
END CASE
CALL displayMenu()
INPUT choice
END WHILE
Set up the global variables.
Design each module and test your program by translating the test code into program code.
The Driving Seat
You are in the driving seat! You are the program designer. Use your skills to solve the problem.