Question: Looking for help with my code, It is currently running a vector but I want the main.cpp and the inventory.h and inventory.cpp to be running

Looking for help with my code, It is currently running a vector but I want the main.cpp and the inventory.h and inventory.cpp to be running a array over a vector, is there a way to make it a array over a vector? (This is all in C++ coding format)
Inventory.h part
#ifndef INVENTORY_H_INCLUDED
#define INVENTORY_H_INCLUDED
#include
#include "Car.h"
#include "Truck.h"
class Inventory {// This is the header for the inventory class which stores ve
private:
std::vector cars;
public:
Inventory();
~ Inventory();
void loadCars(const std::string& sedanFile, const std::string& truckFile);
void searchByMake(const std::string& make) const;
void searchByModel(const std::string& model) const;
void searchByPrice(double maxPrice) const;
void searchByMiles(int maxMiles) const;
};
#endif // INVENTORY.m INCLM_LNED
Inventory.cpp part
#include
#include
#include
Inventory::Inventory(){}// This is the implementation of the Inventory.h class file and also opens and loads the Sedans and Trucks text files.
Inventory::~Inventory(){
for (Car* car : cars){
delete car;
}
-}
void Inventory::loadCars(const std::string& sefanFile, const std::string& truckFile){
// loading sedans.
std::ifstream inFile(sedanFile);
if (inFile){
std::string make, model, hybridStr;
double price;
int miles;
while(inFile >> make >> model >> price >> miles >> hybridStr){
bool isHybrid =(hybridStr == "yes");
cars.push_back(new Car(make, model, price, miles, isHybrid));
}
inFile.close();
}
// loading trucks.
inFiles.open(truckFiles);
if (inFile){
std::string make, model, engine;
double price;
int miles;
while (inFiles >> make >> model >> price >> miles >> engine){
cars.push_back(new Truck(make, model, price, miles, engine));
}
inFile.close();
}
-}
|void Inventory::searchByMake(const std::string& make) const {
for (const Car* car : cars){
if (car->getMake()== make){
car->display();
std::cout "-------------------------------n";
Main.cpp part
int main(){
Inventory inventory;
inventory.loadCars("sedans.txt", "trucks.txt");
int choice;
while(true){
displayMenu()
std::cout "Select Option"
std::cin >> choice;
if (choice ==5) break;
std::string searchText;
double price;
int miles;
switch (choice){
case 1:
std::cout "Enter Search Make: ";
std::cin >> searchText;
inventory.searchByMake(searchText);
break;
case 2:
std::cout "Enter Search Model: ";
std::cin >> searchText;
inventory.searchByModel(searchText);
break;
case 3:
std::cout "Enter Maximum Price: ";
std""cin >> price;
inventory.searchByPrice(price);
break;
case 4:
std::cout "Enter Maximum Miles: ";
std::cin >> miles;
inventory.searchByMiles(miles);
break;
default:
std::cout "Invalid choice.
";
}
}
Looking for help with my code, It is currently

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!