BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C语言代写 | COMP2401 – Assignment #3

C语言代写 | COMP2401 – Assignment #3

这个Assignment是用C语言完成一个交通工具相关的程序

COMP2401 – Assignment #3
Download the template code called PoliceDatabase.c. It contains a main() function which will serve
as your test case for the assignment. Read it over carefully to make sure that you understand what it
is doing. You will need to write the functions and procedures that are called from this main()
function. You ARE NOT ALLOWED to modify nor change the main() function.
To begin, you will need to define 4 structs that are being used. They are described below. All strings
should be char * … DO NOT allocate char [] arrays with fixed limits.
Define a typedef struct called Driver that defines the following attributes:
license – a string representing a driver’s license ID (e.g., “L0678-67825-83940”);
name – a string representing the name of the driver
street – a string representing the street name and number for this driver (e.g., “12
Elm St.”);
city – a string representing the city in which this driver lives
province – a string representing the province in which this driver lives
Define a typedef struct called Vehicle that defines the following attributes:
make – a string representing the company that made the vehicle (e.g., “Honda”)
model – a string representing the model of the vehicle (e.g., “Civic”, etc..)
color – a string representing the color of the vehicle (e.g., “red”)
plate – a string representing the license plate of the vehicle (e.g., “X5T6Y8”)
year – an unsigned short int representing the year of the vehicle (e.g., 2004)
reportedStolen – an unsigned char indicating if vehicle has been reported as stolen
owner – a Driver * representing the owner of the vehicle
Define a typedef struct called Infraction (i.e., violation) that defines the following attributes:
amount – a float indicating how much the fine was for this infraction
description – a String describing the infraction (e.g., “Not stopping for red light”)
year – an unsigned short int representing year of infraction (e.g., 2020)
month – an unsigned char representing month of infraction (e.g., 1 = Jan)
day – an unsigned char representing day of infraction (e.g., 23)
outstanding – an unsigned char indicating if infraction was paid yet
driver – a Driver * representing the driver that received the infraction
Define a typedef struct called PoliceDatabase that defines the following attributes:
drivers – an array storing all drivers (i.e., people who drive
vehicles) in the database. You should set this to be a
maximum of 2000 … create a #define for this number.
numDrivers – an unsigned short int that keeps track of how
many drivers there are in the database
vehicles – an array storing all vehicles in the database. You
should set this to be a maximum of 1000 … create a #define
for this number.
numVehicles – an unsigned short int that keeps track of how many vehicles there are in the
database
infractions – an array storing all infractions that have ever been given to drivers. You should
set this to be a maximum of 800 … create a #define for this number.
numInfractions – an unsigned short int that keeps track of how many infractions there are in
the database
You must write the following functions and procedures in order for the program to work:
• a registerDriver() function which takes a PoliceDatabase * and driver information (i.e.,
license, name, address, city, province) as parameters. It should then add the driver to the
given database … assuming that the database is not full, otherwise the driver is not to be
registered. It should return 1 if the registration was ok, otherwise 0.
• a registerVehicle() function which takes a PoliceDatabase * and vehicle information (i.e.,
make, model, year, color, plate and driver’s license) as parameters. It should then add the
vehicle to the given database … assuming that the database is not full, otherwise the vehicle is
not to be registered. Make sure to store the vehicle’s owner properly … you’ll have to find the
one with the given license. It should return 1 if the registration was ok, otherwise 0.
• a unregisterVehicle() function which takes a PoliceDatabase * and a vehicle plate as
parameters. It should then remove the vehicle with that plate from the database without
altering the order of the vehicles currently in the database and without leaving any gaps in the
array. You must copy all other vehicles back one position in the array to fill in the gap. If the
plate is not in the database, then nothing is to be done. It should return 1 if the unregistration
was ok, otherwise 0.
• a procedure called pay() which takes a single Infraction * as parameter and then pays the
infraction (hint…use the outstanding attribute).
• a changeOwner() function which takes a PoliceDatabase *, a vehicle plate and a driver’s
license as its parameters. It should then update the database by changing the owner
information for the vehicle with the given plate to the driver with the given license (i.e., this
second parameter is not the license plate of the vehicle … it is the driver’s license). If either
the plate or the driver’s license is not in the database, then nothing is to be done. It should
return 1 if the change was made, otherwise 0.
• a reportStolen() function which takes a PoliceDatabase * and a vehicle plate as its
parameters. It should then properly record that the vehicle with the given plate has been
stolen. If the plate is not in the database, then nothing is to be done. It should return 1 if the
car was found, otherwise 0.
• issueInfraction() function which takes a PoliceDatabase *, a driver’s license and the
infraction information (i.e., amount, description, year, month, day) as its parameters. It should
then cause the driver with the given driver’s license to receive an infraction for the given
amount and description (i.e., reason) on the given date … updating the database as
necessary. This function MUST return the Infraction created. If the number of infractions has
reached its limit in the database, then nothing is to be done.
• hasOutstandingInfractions() function which takes a PoliceDatabase * and a Driver * as its
parameters. It should then return 1 if the driver has any infractions that have not been paid
yet, otherwise it should return 0.
• shouldStopVehicle() function which takes a PoliceDatabase * and a vehicle plate as its
parameters. It should then decide whether or not the police should pull this vehicle over. It
should return 1 if and only if the vehicle has been reported stolen, or if the vehicle’s owner has
at least one outstanding infraction … otherwise, the function should return 0. You MUST make
use of the function hasOutstandingInfractions().
• showInfractionsFor() procedure which takes a PoliceDatabase * and a driver’s license as its
parameters. It should then display a list of all infractions that the driver with this license has
incurred showing (on successive lines) the driver’s infractions … and then finish with the total
number of outstanding infractions. Here is the format you should use … the date showing
year, month and then day … and the status of each infraction as being either PAID IN FULL or
OUTSTANDING:
$100.00 infraction on 2010/02/03 [PAID IN FULL]
$250.00 infraction on 2012/09/06 [PAID IN FULL]
$250.00 infraction on 2017/07/07 [PAID IN FULL]
$350.00 infraction on 2019/11/03 [OUTSTANDING]
$350.00 infraction on 2020/01/01 [OUTSTANDING]
Total outstanding infractions = 2
• cleanDrivers() procedure which takes a PoliceDatabase * and a double star pointer (i.e.,
Driver **) to an initially-null array of drivers as its parameters. It should determine the number
of clean drivers (i.e., all drivers who have never had any infractions) and then dynamicallyallocate
a Driver * array with that exact size and fill it in with drivers that are found to be clean.
It should then set the incoming Driver ** parameter to the newly-allocated array.
• showInfractionReport() procedure which takes a PoliceDatabase * as its parameter. It
should then list information about all drivers who have had at least one infraction. Each line in
the list should show a driver’s name (formatted to take exactly 20 spaces) followed by the
number of infractions that they received and the total amount for all infractions that they have
already paid (formatted as shown) as follows:
Bob B. Pins: 1 infractions, total paid = $ 75.00
Ilene Dover: 4 infractions, total paid = $400.00
Jim Class: 5 infractions, total paid = $600.00
Bob Upandown: 1 infractions, total paid = $ 0.00
Sam Pull: 2 infractions, total paid = $250.00

bestdaixie

评论已关闭。