Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE TAKE TIME TO WORK ON THIS PROGRAM AND CHECK TEH GRADING CRITERIA TO KNOW WHAT IS REQUIRED. SHOW THE CORRECT CODE AND THE OUT

PLEASE TAKE TIME TO WORK ON THIS PROGRAM AND CHECK TEH GRADING CRITERIA TO KNOW WHAT IS REQUIRED. SHOW THE CORRECT CODE AND THE OUT ON THE SCREEN SO ILL KNOW IT RUNS FINE. THANK YOU . ALL THE REQUIRED CLASSES ARE GIVEN BELOW

Instructions In this assignment you will essentially convert the program you created in Assignment 1 into a program written in C++ using classes and object oriented design principles. A large part of this program has been provided to you to build from. It was designed using the modelviewcontroller design pattern that you should be familiar with. The various classes are described below. Controller The ShopController class acts as the controller for this program. It is the only class used by our main function (in main.cc). It maintains the model as well as the view. It prompts both the user for information and displays information via the View class (described below) and modifies the various model classes as appropriate. View The View class as the view for this program. All interaction with the user (including both input and output) is done using the view. These actions are prompted by the controller who then modifies the model in response. Model The Model is made up of a number of different classes. The Shop class will collect all of the objects that make up this automotive business. Currently it will only contain a list of customers ( Customer class). Each of these customers will contain a list of vehicles ( Vehicle class). These

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 nextId 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 nextId 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 Customers 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 (dont 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

Grading [out of 25 marks] Marking components: 7 marks: UML diagram 4 marks: Customer class 1 mark: initializing static member 1 mark: constructor 1 mark: getters 2 marks: Vehicle class 1 mark: constructor 1 mark getters 5 marks: CustomerArray class 1 mark: constructor & getSize function 2 marks: destructor 1 mark: add function 1 mark: get function. 5 marks: VehicleArray class 1 mark: constructor & getSize function 2 marks: destructor 1 mark: add function 1 mark: get function 2 marks: ShopController class data fill done to specification, using dynamically allocated memory Notes: In order to get credit for a marking component, the program must prove that the marking component executes successfully. This is usually accomplished by printing out correct data.

REQUIRED CODE FOR PROGRAM VIEW.CC #include #include #include using namespace std; #include "View.h" #include "CustomerArray.h" #include "Customer.h" #include "VehicleArray.h" #include "Vehicle.h"

void View::mainMenu(int& choice) { string str; choice = -1; cout<< " **** Toby's Auto Mechanic Information Management System **** "; cout<< " MAIN MENU "; cout<< " 1. Print Customer Database "; cout<< " 0. Exit "; while (choice < 0 || choice > 1) { cout << "Enter your selection: "; choice = readInt(); } if (choice == 0) { cout << endl; } }

void View::printCustomers(CustomerArray& arr) { cout << endl << "CUSTOMERS: " << endl << endl; for (int i = 0; i < arr.getSize(); i++) { Customer* cust = arr.get(i); ostringstream name; name << cust->getFname() << " " << cust->getLname(); cout << "Customer ID " << cust->getId() << endl << endl << " Name: " << setw(40) << name.str() << endl << " Address: " << setw(37) << cust->getAddress() << endl << " Phone Number: " << setw(32) << cust->getPhoneNumber() << endl; if (cust->getNumVehicles() > 0) { cout << endl << " " << cust->getNumVehicles() << " vehicle(s): " << endl << endl; } VehicleArray& varr = cust->getVehicles(); for (int j = 0; j < varr.getSize(); j++) { Vehicle* v = varr.get(j); ostringstream make_model; make_model << v->getMake() << " " << v->getModel(); cout << "\t" << j+1 << ") " << setw(7) << v->getColour() << " " << v->getYear() << " " << setw(17) << make_model.str() << " (" << v->getMilage() << "km)" << endl; } cout << endl << endl; } } void View::pause() { string str; cout << "Press enter to continue..."; getline(cin, str); } int View::readInt() { string str; int num; getline(cin, str); stringstream ss(str); ss >> num; return num; } VIEW.H #ifndef VIEW_H #define VIEW_H #include "CustomerArray.h" class View { public: void mainMenu(int&); void printCustomers(CustomerArray&); void pause(); private: int readInt(); }; #endif VEHICLEARRAY.H #ifndef VEHICLEARRAY_H #define VEHICLEARRAY_H #include "defs.h" #include "Vehicle.h" class VehicleArray { public: VehicleArray(); ~VehicleArray(); int add(Vehicle*); Vehicle* get(int); int getSize(); private: Vehicle* elements[MAX_VEHICLES]; int size; }; #endif VEHICLEARRAY.CC #include "VehicleArray.h" #include "Vehicle.h" #include "defs.h" VEHIICLE.H #ifndef VEHICLE_H #define VEHICLE_H #include using namespace std; class Vehicle { public: Vehicle(string, string, string, int, int); string getMake(); string getModel(); string getColour(); int getYear(); int getMilage(); private: string make; string model; string colour; int year; int mileage; }; #endif VEHICLE.CC #include "Vehicle.h" SHOPCONTROLLER.H #ifndef SHOPCONTROLLER_H #define SHOPCONTROLLER_H #include "View.h" #include "Shop.h" class ShopController { public: ShopController(); void launch(); private: Shop mechanicShop; View view; void initCustomers(); }; #endif SHOPCONTROLLER.CC #include "ShopController.h" ShopController::ShopController() { initCustomers(); } void ShopController::launch() { int choice; while (1) { choice = -1; view.mainMenu(choice); if (choice == 1) { view.printCustomers(mechanicShop.getCustomers()); view.pause(); } /*else if (choice == 2) { } else if (choice == 3) { } else if (choice == 4) { } ... */ else { break; } } }

void ShopController::initCustomers() { //add data fill here } SHOP.H #ifndef SHOP_H #define SHOP_H #include "Customer.h" #include "CustomerArray.h" class Shop{ public: int addCustomer(Customer*); Customer& getCustomer(int); CustomerArray& getCustomers(); private: CustomerArray customers; }; #endif SHOP.CC #include "Shop.h" #include "defs.h" int Shop::addCustomer(Customer* c) { return customers.add(c); } Customer& Shop::getCustomer(int i) { return *(customers.get(i)); } CustomerArray& Shop::getCustomers() { return customers; } MAKEFILE OBJ = main.o ShopController.o View.o Shop.o CustomerArray.o VehicleArray.o Customer.o Vehicle.o mechanicshop: $(OBJ) g++ -o mechanicshop $(OBJ) main.o: main.cc g++ -c main.cc ShopController.o: ShopController.cc ShopController.h Shop.h View.h g++ -c ShopController.cc View.o: View.cc View.h g++ -c View.cc Shop.o: Shop.cc Shop.h CustomerArray.h g++ -c Shop.cc CustomerArray.o: CustomerArray.cc CustomerArray.h Customer.h defs.h g++ -c CustomerArray.cc VehicleArray.o: VehicleArray.cc VehicleArray.h Vehicle.h defs.h g++ -c VehicleArray.cc Customer.o: Customer.cc Customer.h g++ -c Customer.cc Vehicle.o: Vehicle.cc Vehicle.h g++ -c Vehicle.cc clean: rm -f $(OBJ) mechanicshop MAIN.CC #include "ShopController.h" int main(int argc, char* argv[]) { ShopController control; control.launch(); return 0; } DEFS.H #ifndef DEFS_H #define DEFS_H #define MAX_VEHICLES 4 #define MAX_CUSTOMERS 6 #define C_OK 0 #define C_NOK -1 #endif CUSTOMERARRAY.H #ifndef CUSTOMERARRAY_H #define CUSTOMERARRAY_H #include "Customer.h" class CustomerArray { public: CustomerArray(); ~CustomerArray(); int add(Customer*); Customer* get(int); int getSize(); private: Customer* elements[MAX_CUSTOMERS]; int size; }; #endif CUSTOMERARRAY.CC #include "CustomerArray.h" #include "Customer.h" #include "defs.h" CUSTOMER.H #ifndef CUSTOMER_H #define CUSTOMER_H #include #include "Vehicle.h" #include "VehicleArray.h" using namespace std; class Customer { public: Customer(string="", string="", string="", string=""); int getId(); string getFname(); string getLname(); string getAddress(); string getPhoneNumber(); int getNumVehicles(); VehicleArray& getVehicles(); int addVehicle(Vehicle*); private: static int nextId; int id; string firstName; string lastName; string address; string phoneNumber; VehicleArray vehicles; }; #endif CUSTOMER.CC #include using namespace std; #include "Customer.h"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions