Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you help me troubleshoot my c + + code? #include NodeList.h #include inventory.h / / Ensure correct path if in different directory
can you help me troubleshoot my c code?
#include "NodeList.h
#include "inventory.h Ensure correct path if in different directory
Inventory::Inventory
Inventory::Inventoryint capacity
Initialize capacity if needed
Inventory::~Inventory
Inventory::Inventoryconst Inventory& obj : vListobjvList
Inventory& Inventory::operatorconst Inventory& rhs
if this &rhs
vList rhsvList;
return this;
bool Inventory::pushBackVehicle vehicle
vList.insertBackvehicle;
return true; Assuming always successful for simplicity
void Inventory::sortList
Bubble sort implementation for NodeList
for auto it vList.begin; it vList.end; it
for auto it it; it vList.end; it
if itit Assuming Vehicle comparison operators are defined
Vehicle temp it;
itit;
it temp;
void Inventory::printList
for auto it vList.begin; it vList.end; it
std::cout it
;
void Inventory::printReservedList
for auto it vList.begin; it vList.end; it
if itstatus
std::cout it;
void Inventory::printAvailableList
for auto it vList.begin; it vList.end; it
if itstatus
std::cout it;
bool Inventory::foundint seatsNo
bool found false;
for auto it vList.begin; it vList.end; it
if itstatus && itgetSeats seatsNo
std::cout it;
found true;
return found;
bool Inventory::reserveVehicleint vehicleID
int index checkIDvehicleID;
if index && vListindexstatus Vehicle found and available
vListindexreserve;
return true;
return false;
bool Inventory::returnVehicleint vehicleID
int index checkIDvehicleID;
if index && vListindexstatus Vehicle found and reserved
vListindexunReserve;
return true;
return false;
int Inventory::checkIDint vehicleID
int index ;
for auto it vList.begin; it vList.end; itindex
if itgetID vehicleID
return index;
return ; Vehicle not found
bool Inventory::saveToFileconst std::string& fileName
std::ofstream outFilefileName;
if outFile
std::cerr "Error opening file fileName std::endl;
return false;
for auto it vList.begin; it vList.end; it
outFile it;
outFile.close;
return true;
std::ofstream& operatorstd::ofstream& out, const Inventory& objV
for auto it objV.vList.begin; it objV.vList.end; it
out it;
return o#pragma once
#ifndef INVENTORYH
#define INVENTORYH
#include
#include
#include
#include "NodeList.h
#include "vehicle.h
class Inventory
private:
NodeList vList; NodeList of vehicles
public:
Inventory;
Inventoryint capacity;
~Inventory;
Inventoryconst Inventory& obj;
Inventory& operatorconst Inventory& rhs;
void sortList;
void printList;
void printReservedList;
void printAvailableList;
bool foundint seatsNo;
bool reserveVehicleint vehicleID;
bool returnVehicleint vehicleID;
int size const return vList.size;
Method to add vehicle to NodeList
bool pushBackVehicle ve;
Method to check vehicle ID in NodeList
int checkIDint vehicleID;
Method to save inventory to file
bool saveToFileconst string& fileName;
friend std::ofstream& operatorstd::ofstream& outfile, const Inventory& objV;
;
#endif INVENTORYH
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