Question

HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS.

Task 1: Enforcing const-ness throughout
Your first job will be to go through all of the code and decide which functions should be declared const.
You should find several places throughout the program where this makes sense. We will also make the id
data member in the Customer class const , as once a customer has been created their ID will never
change. You will have to alter the code to make this so. You can not alter the parameters or return type of
any function to accomplish any of this. The program should work just as it did before.
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
● provide a getSize function that returns the size of the list. This value should not be stored, it
should be calculated each time this function is called
● provide a get function in the CustomerList that takes an integer parameter (id) and returns a
pointer to the Customer object in the list with that id. If no such object exists, return null
● manage its memory to avoid memory leaks
Notes:
● DO NOT use dummy nodes! Every node in each list must correspond to an object.
● You will modify your program to use a CustomerList and VehicleList objects instead of a
CustomerArray and VehicleArray object to hold the objects.
● All classes will continue to interact with the CustomerList and VehicleList classes the same way
they did with the CustomerArray and VehicleArray classes.
● Both lists will no longer have a maximum size. This means that the add functions in both list
classes will no longer need to return an int as they should return void. You will have to change
your add functions in the Customer and Vehicle classes to reflect this change.
● The changes to the rest of the classes should be minimal.
● The order in which your datafill is added to the list must test all cases: adding to the front, back,
middle, etc.
● Your list must be stored in proper order of at all times
● You will have to update your Makefile to compile your new program.
Task 3: Modify the “Print Customer Database”
feature
Printing out the linked lists poses a new challenge in maintaining our existing design, specifically the
separation of the UI and collection classes. We are not permitted to print out data from inside the
collection class, since a collection class should not know how to interact with the outside world. We also
cannot allow the UI class to traverse the product collection in order to print it to the screen, since that
would require knowledge by the UI class of the internal configuration of the list, including the Node class,
which would also violate encapsulation rules.
Our solution here will be to implement a formatting function in the CustomerList and VehicleList classes.
These functions will have the prototype:
void toString(string& outStr)
where the outStr parameter is the result of the function concatenating all the object’s data formatted into
one long string. This long string will contain all data found by traversing the linked list. The UI class will
invoke the formatting function on the List objects, and then output the resulting formatted string to the
screen. Take a look at the current printing code in the View as a hint on how to implement these
functions. Your output does not have to be in the exact same format as before, just ensure that all of the
same information is there in a readable way.
Note: DO NOT have your UI class traverse the linked list! DO NOT print to the screen from the list class!
Task 4: Add some options to the menu
We will now add two new options to our user interface menu.
1. Option 2 on the list should now be “Add Customer ”. When the user chooses this option,
the program will prompt the use for all of the relevant information, create a customer
object and add it to the Customer list. Write the appropriate functions in the view,
controller, and shop classes (maintaining the overall proper design of the program) to do
so.
2. Option 3 on the list will now be “Add Vehicle” . When the user chooses this option the
program will prompt the user for a customer id. If it is invalid, tell the user (hint: use the
getCustomer function in the shop class mentioned at the very top of the assignment). If
not, prompt the user for all of the relevant information, create a vehicle object and add it
to the customer’s vehicle list.
In both of these cases you need to think about which classes should do the interaction with the
user, which should be creating objects, etc. You need to maintain the overall design of the
program including the separation of the view, controller and entity classes. Take a look at how
the print customer database option works and trace the code through the various classes to
understand how these functions should be implemented.
Constraints
● 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

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


View.cc
#include <sstream>
#include <iomanip>
#include <iostream>
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<< "\n\n\n         **** Toby's Auto Mechanic Information Management System ****\n\n";
    cout<< "                                 MAIN MENU\n\n";
    cout<< "        1. Print Customer Database\n\n";
    cout<< "        0. Exit\n\n";
    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;
}

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

vehichleArray.cc
#include "VehicleArray.h"
#include "Vehicle.h"
#include "defs.h"
VehicleArray::VehicleArray() { size = 0; }
VehicleArray::~VehicleArray() {
    for(int i = 0; i < size; i++) {
        delete elements[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 < 0)) {
        return 0;
    }
    return elements[i];
}

Vehichle.h
#ifndef VEHICLE_H
#define VEHICLE_H
#include <string>
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"
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; }

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() {
    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);
    //newVehicle = new Vehicle("GM", "Vue", "Blue", 2015, 20000);
    //newCustomer->addVehicle(newVehicle);
    mechanicShop.addCustomer(newCustomer);
}

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

costumerArray.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"
CustomerArray::CustomerArray() { size = 0; }
CustomerArray::~CustomerArray() {
    for(int i = 0; i < size; i++) {
        delete elements[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 < 0)) {
        return 0;
    }
    return elements[i];
}

customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <string>
#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 <iostream>
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); }


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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//main.cpp
#include "ShopController.h"

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

control.launch();

return 0;
}
--------------------------------------------------------------------------
//Customer.cpp
#include <iostream>
using namespace std;
#include "Customer.h"


int Customer::nextId = 1000;

//CONSTRUCTORS//
Customer::Customer(string firstN, string lastN, string add, string phone){
id = nextId;
nextId++; // increase id by 1
firstName = firstN;
lastName = lastN;
address = add;
phoneNumber = phone;
}

//GET/SET METHODS//
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 *newVehicle){
return vehicles.add(newVehicle);
}
----------------------------------------------------------------------------------------
//Customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H

#include <string>
#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.cpp
#include "CustomerArray.h"
#include "Customer.h"
#include "defs.h"

//CONSTRUCTOR//
CustomerArray::CustomerArray(){size = 0;}


//DESTRUCTORS//
CustomerArray::~CustomerArray(){
//no clue
}


//GET METHODS//
int CustomerArray::getSize(){return size;}

Customer*   CustomerArray::get(int custNum){
if(custNum < MAX_CUSTOMERS){return elements[custNum];}
return 0;
}

//adds a customer to the CustomerArray*/
int CustomerArray::add(Customer* newCustomer){
if(size < MAX_CUSTOMERS){
    elements[size] = newCustomer;
    size ++;
    return C_OK;
}
return C_NOK;
}
------------------------------------------------------------------------------------------------------
//Customer.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
-------------------------------------------------------------------------------------------------------
//shop.cpp
#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.cpp
#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 ONE//
Customer* c= new Customer("Star", "Man", "Solar Orbit", "(888) 518-3752");
Vehicle* v= new Vehicle("Tesla","Roadster","Cherry Red", 2008, 35462000);
c->addVehicle(v);
mechanicShop.addCustomer(c);

//CUSTOMER TWO//
c= new Customer("Maurice", "Mooney", "123 Bank Street", "(613) 123-4567");
v= new Vehicle("Subaru","Forester","Green", 2016, 40000);
c->addVehicle(v);
v= new Vehicle("Honda","Accord","White", 2018, 5000);
c->addVehicle(v);
mechanicShop.addCustomer(c);

//CUSTOMER THREE//
c= new Customer("Abigail", "Atwood", "456 Merivale Road", "(819) 111-2222");
v= new Vehicle("Volkswagon","Polo","White", 1998, 50000);
c->addVehicle(v);
mechanicShop.addCustomer(c);

//CUSTOMER FOUR//
c= new Customer("Brooke", "Banding", "1310 Alta Vista Drive", "(613) 222-1111");
v= new Vehicle("Ford","Fiesta","Red", 2007, 100000);
c->addVehicle(v);

v= new Vehicle("Honda","Accord","White", 2018, 5000);
c->addVehicle(v);

v= new Vehicle("Toyota","Prius","Blue", 2008, 5001);
c->addVehicle(v);
mechanicShop.addCustomer(c);

//CUSTOMER FIVE//
c= new Customer("Ethan", "Esser", "24 Sussex Drive", "(613) 992-4793");
v= new Vehicle("Toyota","Prius","Blue", 2008, 5000);
c->addVehicle(v);
mechanicShop.addCustomer(c);

//CUSTOMER SIX//
c= new Customer("Eve", "Engram", "420 Queen Street", "(613) 666-9837");
v= new Vehicle("Honda","Accord","White", 2018, 5000);
c->addVehicle(v);

v= new Vehicle("Ferrari", "LaFerrari", "Red", 2018, 1500);
c->addVehicle(v);

v= new Vehicle("Toyota","Prius","Blue", 2008, 5000);
c->addVehicle(v);

v= new Vehicle("Toyota","Camry","Black", 2018, 500000);
c->addVehicle(v);
mechanicShop.addCustomer(c);
}
---------------------------------------------------------------------------------------------
//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.cpp
#include "Vehicle.h"


Vehicle::Vehicle(string newMake, string newModel, string newColour, int newYear, int newMilage){
make = newMake;
model = newModel;
colour = newColour;
year = newYear;
mileage = newMilage;
}

int       Vehicle::getYear(){return year;}
int       Vehicle::getMilage(){return mileage;}
string    Vehicle::getMake(){return make;}
string    Vehicle::getModel(){return model;}
string Vehicle::getColour(){return colour;}
----------------------------------------------------------------------------------------
//Vehicle.h
#ifndef VEHICLE_H
#define VEHICLE_H

#include <string>
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.cpp
#include "VehicleArray.h"
#include "Vehicle.h"
#include "defs.h"

//CONSTRUCTORS//
VehicleArray::VehicleArray(){
size = 0;
}

///DESTRUCTORS//
VehicleArray::~VehicleArray(){
//no clue
}

//GET METHODS//
int      VehicleArray::getSize(){return size;}

Vehicle* VehicleArray::get(int vehNum){
if(vehNum < MAX_VEHICLES){return elements[vehNum];}
return 0;
}

// adds a customer to the VehicleArray*/
int VehicleArray::add(Vehicle* newVehicle){
if(size < MAX_VEHICLES){
    elements[size] = newVehicle;
    size++;
    return C_OK;
}
return C_NOK;
}
-------------------------------------------------------------------------------------
//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.cpp
#include <sstream>
#include <iomanip>
#include <iostream>
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<< "\n\n\n         **** Auto Mechanic Information Management System ****\n\n";
    cout<< "                                 MAIN MENU\n\n";
    cout<< "        1. Print Customer Database\n\n";
    cout<< "        0. Exit\n\n";

    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
----------------------------------------------------------------------------------
//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    
ShopController ShopController.cpp Run: ShopController Users/swapnil/CLionProjects/ShopControLler/cmake-build-debug/ShopContro

Add a comment
Know the answer?
Add Answer to:
HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • Requirements: Finish all the functions which have been declared inside the hpp file. Details: st...

    Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...

  • 2. In the following program an employee of a company is represented by an object of...

    2. In the following program an employee of a company is represented by an object of type employee consisting of a name, employee id, employee salary and the workday starting time. The starting time is a class time 24 object. Implement the class employee. Declaration of Employee and Time Classes /* File : employeetime.h Hlustrates composition of classes */ #ifndef EMPLOYEETIME.H #define EMPLOYEETIME.H #include <iostream> #include <string> using namespace std; class time 24 { private : int hour; int minute...

  • for the following code I need the source code and output screenshot (includes date/time) in a...

    for the following code I need the source code and output screenshot (includes date/time) in a PDF format. I keep getting an error for the #include "dayType.hpp" dayType.cpp #include"dayType.hpp" string dayType::weekday[7] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" }; //set the day void dayType::setDay(string day){ cout << "Set day to: " ; cin >> dayType::day; for(int i=0; i<7; i++) { if(dayType::weekday[i]==dayType::day) { dayType::markDay = i; } } } //print the day void dayType::printDay() { cout << "Day = "...

  • I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I...

    I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I have right now. ************city.h**************** #ifndef city_h #define city_h #include <string> using namespace std; class City{ public: City () { name = "N/A"; population = 0; } City (string nm, unsigned int pop){ name = nm; population = pop; } void setName (string name) { this -> name = name; } void setPopulation (unsigned int population){ this -> population = population; } string getName() const...

  • 10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete...

    10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...

  • PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //==...

    PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Linked-List class definition //============================================================================ /** * Define a class containing data members and methods to *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT