1. Homepage
  2. Programming
  3. DPST1091 Programming Fundamentals - Assignment 1 - CS Carpark

DPST1091 Programming Fundamentals - Assignment 1 - CS Carpark

Engage in a Conversation
UNSWDPST1091Programming FundamentalsCS Carpark

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! CourseNana.COM

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: CourseNana.COM

struct car_space CourseNana.COM

  • 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 definition.
    • int parking_rate
      • The rate (given in $/hr) associated with a particular parking space. Note that CARWASH_BAYs 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: CourseNana.COM

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. CourseNana.COM

A definition of the provided enum is given below: CourseNana.COM

enum space_type CourseNana.COM

  • 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 N 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 defined as CourseNana.COM

struct car_space carpark[CARPARK_ROWS][CARPARK_COLUMNS];, CourseNana.COM

where CARPARK_ROWS is 8 and CARPARK_COLUMNS is 6. CourseNana.COM

This means that we have a 2D array of struct car_spaces. CourseNana.COM

TODO: implementation model CourseNana.COM

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. CourseNana.COM

Each car space is referred 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. CourseNana.COM

How To Get Started

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

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

mkdir ass1
cd ass1

CourseNana.COM

Download cs_carpark.c here, or copy it to your CSE account using the following command: CourseNana.COM

cp -n /import/reed/A/dp1091/public_html/23T3/activities/cs_carpark/cs_carpark.c .

CourseNana.COM

CourseNana.COM

1091 autotest cs_carpark

Read through Stage 1. CourseNana.COM

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

1091 cs_carpark

CourseNana.COM

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

Start coding! CourseNana.COM

About the Starter Code

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

Before the main function, the starter code has: CourseNana.COM

  1. Imported some libraries, including stdio.h and math.h.
  2. Defined some initial #define's and enums.
  3. Defined the struct described above.

In the main function, the starter code: CourseNana.COM

  1. Creates a 2D array of struct car_spaces 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. CourseNana.COM

  Stage 1

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_spaces and initialises them using the provided initialise_carpark() function. Currently, all of these car spaces are of type NORMAL. CourseNana.COM

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. CourseNana.COM

Welcome to CS Carpark!

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

Assumptions/Restrictions/Clarifications

  • row_no will always be a valid row in the carpark array. It will never be out of bounds.
  • The first 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

CourseNana.COM

CourseNana.COM

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 wil 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. Once all cars a placed, you should print the carpark once again. CourseNana.COM

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]
...

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/Clarifications

  • licence_plate_no is unique for all initial cars. There is no need to check for duplicate licence plates in this stage.
  • 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 specifies 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

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

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: CourseNana.COM

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: CourseNana.COM

The carpark is now closed. Bye!

Command

P

Note that the above command is a capital P. CourseNana.COM

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). CourseNana.COM

This means that scanf("%d %c %lf", &input1, &input2, &input3) will return 3 if all inputs are successfully scanned in. In the case that CTRL+D was entered instead, it will not return 3. Use this idea to terminate your command loop! CourseNana.COM

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. CourseNana.COM

Examples

CourseNana.COM

CourseNana.COM

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: CourseNana.COM

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:
Car space is already occupied!

Assumptions/Restrictions/Clarifications

  • Errors should be checked in the order that they are outlined above. In the case where multiple invalid conditions hold true, only the very first error should be printed.
  • 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

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

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: CourseNana.COM

There are currently [number of total cars] cars and [number of empty spaces] empty car spaces in the carpark.

Examples

CourseNana.COM

CourseNana.COM




Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UNSW代写,DPST1091代写,Programming Fundamentals代写,CS Carpark代写,UNSW代编,DPST1091代编,Programming Fundamentals代编,CS Carpark代编,UNSW代考,DPST1091代考,Programming Fundamentals代考,CS Carpark代考,UNSWhelp,DPST1091help,Programming Fundamentalshelp,CS Carparkhelp,UNSW作业代写,DPST1091作业代写,Programming Fundamentals作业代写,CS Carpark作业代写,UNSW编程代写,DPST1091编程代写,Programming Fundamentals编程代写,CS Carpark编程代写,UNSWprogramming help,DPST1091programming help,Programming Fundamentalsprogramming help,CS Carparkprogramming help,UNSWassignment help,DPST1091assignment help,Programming Fundamentalsassignment help,CS Carparkassignment help,UNSWsolution,DPST1091solution,Programming Fundamentalssolution,CS Carparksolution,