Question
SHOW THE CODE RUNS AND EVERYTHING IS CORRECT. HELLO, PLEASE ANSWER THE QUESTION CORRECTLY AND SHOW THAT THE CODE RUNS ON THE SCREEN. THANKS Task
SHOW THE CODE RUNS AND EVERYTHING IS CORRECT. HELLO, PLEASE ANSWER THE QUESTION CORRECTLY AND SHOW THAT THE CODE RUNS ON THE SCREEN. THANKS
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.
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
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started