Answered step by step
Verified Expert Solution
Link Copied!

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::Inventory(int capacity){
// Initialize capacity if needed
}
Inventory::~Inventory(){}
Inventory::Inventory(const Inventory& obj) : v_List(obj.v_List){}
Inventory& Inventory::operator=(const Inventory& rhs){
if (this != &rhs){
v_List = rhs.v_List;
}
return *this;
}
bool Inventory::push_Back(Vehicle vehicle){
v_List.insertBack(vehicle);
return true; // Assuming always successful for simplicity
}
void Inventory::sortList(){
// Bubble sort implementation for NodeList
for (auto it1= v_List.begin(); it1!= v_List.end(); ++it1){
for (auto it2= it1; it2!= v_List.end(); ++it2){
if (*it2>*it1){// Assuming Vehicle comparison operators are defined
Vehicle temp =*it1;
*it1=*it2;
*it2= temp;
}
}
}
}
void Inventory::printList(){
for (auto it = v_List.begin(); it != v_List.end(); ++it){
std::cout *it "------------------------------------------
";
}
}
void Inventory::printReservedList(){
for (auto it = v_List.begin(); it != v_List.end(); ++it){
if (!it->status()){
std::cout *it;
}
}
}
void Inventory::printAvailableList(){
for (auto it = v_List.begin(); it != v_List.end(); ++it){
if (it->status()){
std::cout *it;
}
}
}
bool Inventory::found(int seatsNo){
bool found = false;
for (auto it = v_List.begin(); it != v_List.end(); ++it){
if (it->status() && it->getSeats()>= seatsNo){
std::cout *it;
found = true;
}
}
return found;
}
bool Inventory::reserveVehicle(int vehicleID){
int index = checkID(vehicleID);
if (index !=-1 && v_List[index].status()){// Vehicle found and available
v_List[index].reserve();
return true;
}
return false;
}
bool Inventory::returnVehicle(int vehicleID){
int index = checkID(vehicleID);
if (index !=-1 && !v_List[index].status()){// Vehicle found and reserved
v_List[index].unReserve();
return true;
}
return false;
}
int Inventory::checkID(int vehicleID){
int index =0;
for (auto it = v_List.begin(); it != v_List.end(); ++it,++index){
if (it->getID()== vehicleID){
return index;
}
}
return -1; // Vehicle not found
}
bool Inventory::saveToFile(const std::string& fileName){
std::ofstream outFile(fileName);
if (!outFile){
std::cerr "Error opening file " fileName std::endl;
return false;
}
for (auto it = v_List.begin(); it != v_List.end(); ++it){
outFile *it;
}
outFile.close();
return true;
}
std::ofstream& operator(std::ofstream& out, const Inventory& objV){
for (auto it = objV.v_List.begin(); it != objV.v_List.end(); ++it){
out *it;
}
return o#pragma once
#ifndef INVENTORY_H
#define INVENTORY_H
#include
#include
#include
#include "NodeList.h"
#include "vehicle.h"
class Inventory {
private:
NodeList v_List; // NodeList of vehicles
public:
Inventory();
Inventory(int capacity);
~Inventory();
Inventory(const Inventory& obj);
Inventory& operator=(const Inventory& rhs);
void sortList();
void printList();
void printReservedList();
void printAvailableList();
bool found(int seatsNo);
bool reserveVehicle(int vehicleID);
bool returnVehicle(int vehicleID);
int size() const { return v_List.size(); }
// Method to add vehicle to NodeList
bool push_Back(Vehicle ve);
// Method to check vehicle ID in NodeList
int checkID(int _vehicleID_);
// Method to save inventory to file
bool saveToFile(const string& fileName);
friend std::ofstream& operator(std::ofstream& outfile, const Inventory& objV);
};
#endif // INVENTORY_H
image text in transcribed

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

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

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

LO2 Identify components of workflow analysis.

Answered: 1 week ago