Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Assignment 1 - CS Carpark

Overview

CS Carpark is a carpark management system for your very own carpark business! It will model all the typical comings and goings you would expect in a carpark, including parking cars into car spaces, calculating parking fees and more!

Assignment Structure

This assignment will test your ability to create, use and manipulate 2D arrays and structs to solve problems. To do this, the carpark has been implemented as a 2D array. These tiles are each represented by a struct  car_space , which is outlined below:

struct  car_space

Purpose:

To store information about each parking space in the carpark.

Contains:

enum  space_type  type


The type of parking space.

All space types are found in the

enum  space_type

deinition.


int  parking_ rate

The rate (given in $/hr) associated with a particular parking space. Note that CARWASH_BAY s are an exception and are charged $/use rather than $/hr.     All default rates are listed below.

int  licence_plate

The licence plate of the car that is currently being parked in the space. Has the value  EMPTY  if no car is currently parked in the space.

int  occupied_since

The time at which the current car entered the current parking space. Has the value  EMPTY  if no car is currently parked in the space.

An important note on time:

Time in this assignment is represented hourly using integers between 0 and 23 inclusive. If a car   parks in a space at time 0 and leaves the space at time 3, then the car was parked for 3 hours. You can safely assume that commands will always be given in chronological time order.

A deinition of the provided enum is given below:

enum  space_type

Purpose:

Represent the type of car space.

Possible values:

NORMAL

Represents a normal car space. It has a parking rate of $10/hr. This is denoted by on the printed carpark.

PREMIUM

Represents a premium car space. It has a parking rate of $50/hr. This is denoted by P  on the printed carpark.

CARWASH_BAY

Represents a carwash bay. Cars can park inside a carwash bay. Using a carwash costs $15/use. This is denoted by W  on the printed carpark.

ELECTRIC_CHARGING_STATION

Represents an electric charging station. Cars cannot park on a charging station.  Using a charger costs $7/hr. This is denoted by  CHARGER  on the printed carpark.

Implementation Model

In this assignment, you will be need to manipulate an array provided which is deined as

struct  car_space  carpark[CARPARK_ROWS][CARPARK_COLUMNS]; ,

where CARPARK_ROWS  is 8 and CARPARK_COLUMNS  is 6.

This means that we have a 2D array of struct  car_space s.

Here is an interactive model to play around with. It follows this example carpark.

Note that the indices indicate which struct in the array you are accessing, and the word after the  . indicates which member of that struct that you are accessing.

Each car space is referred to in the following format: (row, column). For example car space (0, 0) is the car space in the top left hand corner. Note that the row number and column number start from 0.

Getting Started

There are a few steps to getting started with CS Carpark.

1. Create a new folder for your assignment work and move into it.

? mkdir ass1

? cd ass1

2. Download cs_carpark.c here

Or, copy these ile(s) to your CSE account using the following command:

? 1511 fetch-activity cs_carpark

3. Run

上己上上  6u才o才92才  O2_O6)q6)训

to make sure you have correctly downloaded the ile.

? 1511 autotest cs_carpark

4. Read through Stage 1.

5. Spend a few minutes playing with the reference solution -- get a feel for how the assignment works.

? 1511 cs_carpark

6. Think about your solution, draw some diagrams, write some pseudocode to help you get started.

7. Start coding!

About the Starter Code

The provided starter code has done some setup for you. This is explained below.

Before the main function, the starter code has:

1.  Imported some libraries, including stdio.h and math.h.

2.  Deined some initial  #b9个rn9 's and enums.

3.  Deined the struct described above.

In the main function, the starter code:

1.  Creates a 2D array of struct  car_space s called  carpark .

2.  Initialises this  carpark with some default values.

3.  Prompts you to write your own code!

Your Tasks

This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.

Stage 1.1: Carpark Setup

Before CS Carpark is ready for business, you will need to initialise some basic information. The starter code currently creates a 2D array of struct  car_space s and initialises them using the provided         initialise_carpark() function. Currently, all of these car spaces are of type  NORMAL .

The carpark will have one single row of premium car spaces. Your job is to take input from the user, asking them where they would like to place the row of  PREMIUM  car spaces. The carpark should be  printed once after premium parking is reserved using the provided  print_carpark() function.

Welcome  to  CS  Carpark!

Which  row  of  the  carpark  would  you  like  to  reserve  for  premium  parking?  [row_no]

Assumptions/Restrictions/Clariications

row_no will always be a valid row in the  carpark  array. It will never be out of bounds. The irst row of the carpark has a  row_no  of 0 .

PREMIUM  parking spaces have a higher parking rate compared to  NORMAL  parking spaces. The premium parking rate is $50/hr.

Examples

Example 1.1.1: Simple setup

Stage 1.2: Initial Cars

We are now ready for initial cars to be added to the carpark! The user will input the number of cars that will be initially parked in the carpark. You will need to scan in a licence plate, and the row and column in which to place that car.

Add  all  current  cars  to  the  carpark .  How  many  cars  would  you  like  to  add?  [num_cars]

Where  would  you  like  to  park  each  car?

[licence_plate_no]  [row]  [col]

[licence_plate_no]  [row]  [col]

...

Once all cars are placed, you should print the carpark once again, followed by the message:

carpark

is

now

ready

for

business!

Error Handling

If  row  or  column  entered by the user is outside the bounds of the carpark, the below error message should be printed:

Invalid  car  space!

Assumptions/Restrictions/Clariications

licence_plate_no  is unique for all initial cars. There is no need to check for duplicate licence plates/

The licence_plate_no will always be a 4 digit integer number.

Initial cars all have a time of entry of 0 .

You will always be given the correct number of inputs, ie. if the user speciies 3 cars to be parked, you should expect exactly 3 rows of input.

num_cars will always be 0  or greater.

Any invalid cars are ignored, and subsequent cars are still scanned in and parked.

You can assume that no two cars will be parked onto the same space in this stage.

Examples

Example 1.2.1: Standard initialisation

Example 1.2.2: Out of bounds car

Stage 1.3: Printing the Carpark Map

From this stage onwards, the carpark is ready for business! This means that user commands are to be read in a loop, until the user presses  Ctrl  +  D  on the keyboard. This is known as a command loop,   and looks something like this:

The  carpark  is  now  ready  for  business!

Enter  a  command:  [command]

[execute  command]

Enter  a  command:  [command]

[execute  command]

Enter  a  command:  [command]

[execute  command]

Enter  a  command: [Ctrl+D]The  carpark  is  now  closed .  Bye!

Note that once

Ctrl  +  D

is pressed, the program should print the following message, before ending:

The  carpark  is  now  closed .  Bye!

Command

P

Note that the above command is a capital P.

Description

This stage is focussed on providing the ability to visualise the car park. When the  P  command is        executed, your program should call the provided  print_carpark() function (the same function used to print the carpark in stage 1.1 and 1.2).


Functions are extremely important from this stage onwards (and before, if you were able to write some) to ensure your code is easier to maintain and read by both yourself and others.

Examples

Example 1.3.1: Print

Stage 1.4: Parking More Cars

Command

p  [licence_plate_no]  [row]  [col]  [time_of_entry]

Description

Now we're ready to park some more cars! The user will input the parking command  p , followed by a licence plate, the row and column of the intended parking space, as well as the entry time of the car.  Remember that, like the print command in stage 1.3, the  p  command should be implemented in the command loop. If the car is added successfully, the following message should be printed:

Car  [licence_plate_no]  was  added  into  car  space  ([row],  [col])  at  time  [time_of_entry]!

Error Handling

Out of bounds error handling like in Stage 1.2 is also required here.

If the car space is already occupied by another car, then the below error message should be printed:

space

is

already

occupied!

Assumptions/Restrictions/Clariications

Errors should be checked in the order that they are outlined above. In the case where multiple invalid conditions hold true, only the very irst error should be printed.

licence_plate_no  is unique for all cars. There is no need to check for duplicate licence plates. The licence_plate_no will always be a 4 digit integer number.

The time_of_entry will always be a number between  0  and 23

Examples

Example 1.4.2: Park out of bounds

Example 1.4.3: Parking in occupied space error

Stage 1.5 - Total Occupancy

Command

o

Description

Sometimes, there is a digital sign near the entry of carparks to let everyone know how full the carpark is. Your job is to implement this feature by determining the total occupancy of the carpark by              counting how many total cars are currently parked in the carpark, as well as how many empty spaces there are remaining. You should print these values out in the following format:

There  are  currently  [number  of  total  cars]  cars  and  [number  of  empty  spaces]  empty  car  spaces  in  th

Examples

Example 1.5.1: Simple occupancy

Stage 1 Testing and Submission

Are you inished with this stage? If so, you should make sure to do the following:

Run  1511  style , and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!

Autotest for this stage of the assignment by running the  autotest-stage  command as shown below.

Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?

$ 1511 style cs_carpark .c

$ 1511 autotest-stage 01 cs_carpark

$ give cs1511 ass1_cs_carpark cs_carpark .c

Stage 2.1: Free Spaces Remaining

Command

F

Description

Have you ever driven around an almost full carpark trying to ind parking? Wouldn't life have been much easier if you had known which spaces were free? That is exactly the functionality you will be implementing in this stage. You should print free spaces and the parking rate associated with that space in the following format:

The  normal  car  spaces  that  are  still  available  are:

([row],  [col]):  $[parking  rate]

([row],  [col]):  $[parking  rate]

([row],  [col]):  $[parking  rate]

...

The  premium  car  spaces  that  are  still  available  are:

([row],  [col]):  $[parking  rate]

([row],  [col]):  $[parking  rate]

([row],  [col]):  $[parking  rate]

...

Assumptions/Restrictions/Clariications

The spaces should be listed in ascending order of row number, and then in ascending order of column number.

If there are no spaces of a certain type available,  NONE  should be displayed.

CARWASH_BAY s and  ELECTRIC_CHARGING_STATION s are not considered free spaces and should not be printed here.

Examples

Example 2.1.1: Simple free spaces


Stage 2.2: Discount Empty Spaces

Command

d

Description

As this carpark is a business, the goal is to encourage as many customers to park in the carpark as     possible. In this stage, you will be implementing a command which applies a discount of 10% to the   parking rate of all empty spaces inside the carpark. Once the discount is applied, you should print the following message:

A 10% discount

has

been

applied

to

all

empty

spaces!

Assumptions/Restrictions/Clariications

The discount can be applied to parking spaces multiple times.

Only empty spaces get an applied discount.

As in stage 2.1,  CARWASH_BAY s and  ELECTRIC_CHARGING_STATION s are not considered free spaces and hence, the discount should not be applied to them.

Parking rates must be integer values, so values should be rounded down after discounts are applied i.e. if 10% discount is applied to $6, the discounted value is $5.4, which is rounded  down to give a inal parking rate of $5.

Examples

Example 2.2.1: Discount

Example 2.2.2: Multi Discount

Stage 2.3: Find a Car

Command

f  [licence_plate_no]

Description

Sometimes, people forget where they've parked their car! In this stage, you will implement the ability to igure out which car space a car is parked in, given its licence plate number. If found, you should   print the following message:

Car  [licence_plate_no]  is  parked  in  car  space  ([row],  [col]) .

Error Handling

If licence_plate_no  does not match any of the licence plates of cars inside the parking lot, the following error message should be printed:

car

with

licence

plate

number [licence_plate_no] could

be

found .

Examples

Example 2.3.1: Found Car

Example 2.3.2: Could Not Find Car

Stage 2.4: Leaving the Carpark

Command

l  [licence_plate_no]  [time_of_exit]

Description

A carpark is not a carpark if no cars are allowed to leave! In this stage, your job is to remove speciied cars from the carpark, and to calculate the parking fee associated with the car's stay. If the speciied   car successfully leaves the carpark, the parking space should return back to its original state ie. it        should be empty once again, and its parking rate should return to the original non-discounted rate.

On successful leave, the following message is printed:

Car [licence_plate_no