QuestionQuestion

Task 1: UML Diagram
You will first study the provided code to get an understanding of how all of the classes work together. Based solely on what is provided, draw a UML diagram for this program. Refer to the lecture notes for exactly what is expected to be included and omitted on a UML diagram. This diagram (a scan of a hand drawn diagram is acceptable) will be a part of your assignment submission.

Task 2: Finish the Program
Your program must use the provided skeleton code without making any changes to the existing code, data structures or function prototypes. You will, however, add your own code to it. Below are the required changes you must make to for your program.

1. Customer and Vehicle classes

You are to implement all of the member functions declared in the respective header files for these classes. Some notes on what is expected for the Vehicle class:

The constructor simply sets all of the data members to the parameters passed in.

The getter functions are simple, one line getters.

Some notes on what is expected for the Customer class:

The static member next is used to give all of the Customer objects unique IDs. Initialize it to 1000.

The constructor sets the id member to the current value of the static member nextid,
increments next and then simply sets all of other data members to the parameters passed in. The getter functions are simple, one line getters. The addVehicle function simply called the add function in the VehicleArray class (described below). It returns what this add function returns.

2. CustomerArray and VehicleArray classes

These classes are collection classes that will store multiple Customer and Vehicle objects, respectively. Implementing this in a separate class will allow us to modify the data structure used at a later date without having to make changes to other classes (as we will do on a future assignment). These classes are very similar. Some notes on what is expected for both classes:

The constructor simply initializes the size data member properly,

The destructor must iterate over the stored objects (which are to be dynamically allocated, discussed below), freeing the allocated memory for each one.

The getSize function is a simple, one line getter.

The add function takes a pointer to a dynamically allocated object. It checks if there is room in the array of pointers for this object. If not, it returns C_NOK (defined in defs.h). If there is, it sets the appropriate pointer in the array to point at the same object as the parameter, increments the size data member and returns C_OK (also defined in defs.h).

The get function takes an index value. If this index is not valid (ie. it is outside of the range of valid objects being stored), the function returns 0. Otherwise it returns the pointer at index I.

3. ShopController class

The ShopController class contains a function called initCustomers which we will use to populate the program with data. This function will create dynamically allocated objects. It will work as follows. First it will create a Customer object followed by several Vehicle objects. You will add the Vehicle objects to the Customer using the Customer's addVehicle member function. Once a Customer object has had all of its Vehicles added, you will add the Customer to the Shop object using its addCustomer member function.

You will do this until the data fill requirements have been met.

You will add 6 Customers to the shop. All of your customers must have at least one vehicle registered. On top of this, you are to have at least one customer with 2 vehicles, at least one customer with 3 vehicles and at least one customer with 4 vehicles.

Once these three implementation tasks have been completed you should be able to compile and run the program. The main menu currently only has the option to print customers, which should work.

Constraints
-you must use the function prototypes exactly as stated
-your program must not have any memory leaks (don't worry if valgrind reports that some memory on the heap is "still reachable")
-do not use any global variables
-your program must reuse functions everywhere possible
-your program must be thoroughly commented
-your program must compile and run in the provided Virtual Machine

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "CustomerArray.h"
#include "Customer.h"
#include "defs.h"

CustomerArray::CustomerArray() {
    for (int i = 0; i < MAX_CUSTOMERS; i++) {
       elements[i] = 0;
    }
    size = 0;
}

CustomerArray::~CustomerArray() {
    for (int i = 0; i < size; i++) {
       delete elements[i];
    }
    size = 0;
}

/**
* The get function takes an index value.
* The add function takes a pointer to a dynamically allocated object.
* It checks if there is room in the array of pointers for this object.
* If not, it returns C_NOK (defined in defs.h).
* If there is, it sets the appropriate pointer in the array to point
* at the same object as the parameter, increments the size data
* member and returns C_OK
* @param cst
* @return
*/
int CustomerArray::add(Customer* cst) {
    if (size >= MAX_CUSTOMERS) {
       return C_NOK;
    }

    elements[size] = cst;
    size++;
    return C_OK;
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$34.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats