Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete in C++ language. ----------------------Customer.cc----------------------- #include using namespace std; #include Customer.h int Customer::nextId = 1000; Customer::Customer(string fname, string lname, string add, string pnum) {

Please complete in C++ language.

image text in transcribed

image text in transcribed

----------------------Customer.cc-----------------------

#include using namespace std; #include "Customer.h"

int Customer::nextId = 1000;

Customer::Customer(string fname, string lname, string add, string pnum) { id = nextId++; firstName = fname; lastName = lname; address = add; phoneNumber = pnum; }

int Customer::getId() { return id; } string Customer::getFname() { return firstName; } string Customer::getLname() { return lastName; } string Customer::getAddress() { return address; } string Customer::getPhoneNumber() { return phoneNumber; } int Customer::getNumVehicles() { return vehicles.getSize(); } VehicleArray& Customer::getVehicles() { return vehicles; } int Customer::addVehicle(Vehicle* v) { return vehicles.add(v); }

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

----------------------CustomerArray.cc-----------------------

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

CustomerArray::CustomerArray() { size = 0; } CustomerArray::~CustomerArray() { for(int i = 0; i

int CustomerArray::getSize() { return size; }

int CustomerArray::add(Customer* c) { if (size == MAX_CUSTOMERS) { return C_NOK; } elements[size] = c; size++; return C_OK; }

Customer* CustomerArray::get(int i) { if ((i >= size) || (i

return elements[i]; }

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

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

----------------------main.cc-----------------------

#include "ShopController.h"

int main(int argc, char* argv[]) { ShopController control;

control.launch();

return 0; }

----------------------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; }

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

----------------------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() {

Customer* newCustomer; Vehicle* newVehicle;

newCustomer = new Customer("Maurice", "Mooney", "2600 Colonel By Dr.", "(613)728-9568"); newVehicle = new Vehicle("Ford", "Fiesta", "Red", 2007, 100000); newCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

newCustomer = new Customer("Abigail", "Atwood", "43 Carling Dr.", "(613)345-6743"); newVehicle = new Vehicle("Subaru", "Forester", "Green", 2016, 40000); newCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

newCustomer = new Customer("Brook", "Banding", "1 Bayshore Dr.", "(613)123-7456"); newVehicle = new Vehicle("Honda", "Accord", "White", 2018, 5000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("Volkswagon", "Beetle", "White", 1972, 5000); newCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

newCustomer = new Customer("Ethan", "Esser", "245 Rideau St.", "(613)234-9677"); newVehicle = new Vehicle("Toyota", "Camery", "Black", 2010, 50000); newCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

newCustomer = new Customer("Eve", "Engram", "75 Bronson Ave.", "(613)456-2345"); newVehicle = new Vehicle("Toyota", "Corolla", "Green", 2013, 80000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("Toyota", "Rav4", "Gold", 2015, 20000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("Toyota", "Prius", "Blue", 2017, 10000); newCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

newCustomer = new Customer("Victor", "Vanvalkenburg", "425 O'Connor St.", "(613)432-7622"); newVehicle = new Vehicle("GM", "Envoy", "Purple", 2012, 60000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("GM", "Escalade", "Black", 2016, 40000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("GM", "Malibu", "Red", 2015, 20000); newCustomer->addVehicle(newVehicle); newVehicle = new Vehicle("GM", "Trailblazer", "Orange", 2012, 90000); newCustomer->addVehicle(newVehicle); /ewVehicle = new Vehicle("GM", "Vue", "Blue", 2015, 20000); /ewCustomer->addVehicle(newVehicle); mechanicShop.addCustomer(newCustomer);

}

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

----------------------Vehicle.cc-----------------------

#include "Vehicle.h"

Vehicle::Vehicle(string ma, string mo, string col, int y, int m) { make = ma; model = mo; colour = col; year = y; mileage = m; }

string Vehicle::getMake() { return make; } string Vehicle::getModel() { return model; } string Vehicle::getColour() { return colour; } int Vehicle::getYear() { return year; } int Vehicle::getMilage() { return mileage; }

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

----------------------VehicleArray.cc-----------------------

#include "VehicleArray.h" #include "Vehicle.h" #include "defs.h"

VehicleArray::VehicleArray() { size = 0; } VehicleArray::~VehicleArray() { for(int i = 0; i

int VehicleArray::getSize() { return size; }

int VehicleArray::add(Vehicle* v) { if (size == MAX_VEHICLES) { return C_NOK; } elements[size] = v; size++; return C_OK; }

Vehicle* VehicleArray::get(int i) { if ((i >= size) || (i

return elements[i]; }

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

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

while (choice 1) { cout

if (choice == 0) { cout

void View::printCustomers(CustomerArray& arr) { cout

for (int i = 0; i getFname() getLname();

cout getId() getAddress() getPhoneNumber() getNumVehicles() > 0) { cout getNumVehicles()

VehicleArray& varr = cust->getVehicles(); for (int j = 0; j getMake() getModel();

cout getColour() getYear() getMilage()

cout

void View::pause() { string str;

cout

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

----------------------CustomerList.h-----------------------

//add code here

----------------------CustomerList.cc-----------------------

//add code here

----------------------VehicleList.h-----------------------

//add code here

----------------------VehicleList.cc-----------------------

//add code here

Task 2: Introduce Linked Lists In this part you will replace the CustomerArray and VehicleArray classes with new linked list classes. You will create new linked list classes called CustomerList and VehicleList which will hold the collection of customers and the collection of vehicles as a linked list, respectively. You will store the customer objects in alphabetical order based on their last name and you will store the vehicle object based on the year of the vehicle in descending order (ie. newest first) in their respective linked lists The CustomerList and VehicleList classes should hold a pointer to the head of the list, but no pointer to the tail of the list provide an add function that takes a Customer or Vehicle pointer and adds the object in its correct place in the CustomerList or VehicleList class, respectively . . Task 2: Introduce Linked Lists In this part you will replace the CustomerArray and VehicleArray classes with new linked list classes. You will create new linked list classes called CustomerList and VehicleList which will hold the collection of customers and the collection of vehicles as a linked list, respectively. You will store the customer objects in alphabetical order based on their last name and you will store the vehicle object based on the year of the vehicle in descending order (ie. newest first) in their respective linked lists The CustomerList and VehicleList classes should hold a pointer to the head of the list, but no pointer to the tail of the list provide an add function that takes a Customer or Vehicle pointer and adds the object in its correct place in the CustomerList or VehicleList class, respectively

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions