C++ program for car dealership.

Build Specifications (35 points)

Write a C++ program to manage a Car Dealership System. The main user is an employee at the dealership.

1. The system should load a catalog of all cars in the inventory, which includes new and old cars. (include at least 5 new cars and 5 old cars).

2. A user can search the inventory: The user of the system can search the inventory by using the make of the car, model of the car, or by category (new or old cars).

3. A user can sell or lease new and old cars.
4. A user can return a leased car into the inventory. 5. Add new and old cars into the inventory.

page1image16296448 page1image16311488 page1image16307456 page1image16312256 page1image16318208

The program must have the following properties (20 points):

  • –  You should do error handling (Ex: An employee cannot add a car that already exists) (5 points)

  • –  You should use inheritance: Example: You can design a generic car class, then design derived classes for new and old cars. The car class may have the following data members: VIN (string), Make (string), Model (string), year (integer number), price (floating number), and category (string). The new car class can have warranty provider (string). Old car class can have for example mileage (integer number). (10 points)

  • –  You should use polymorphism.: Use functions overloading and overriding. (5 points)

    Also, design a menu (should still appear until the exit option is chosen) in the Main program that has the following options implemented to test your classes’ functionality (10 points):

  1. Search Inventory

  2. Sell/Lease cars

  3. Return a leased car

  4. Add cars to inventory

  5. Exit

Extra Credit: (10 points)

  • –  Save and load data from and to a file.

  • –  Show a list of cars within a given price range.

#include <iostream>
using namespace std;
#include “Functions.h”
#include “NewCar.h”
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

int main()
{
while (true) {
cout << “Welcome to Car Dealership!” << endl;
cout << setw(15) << setfill(‘-‘) << “” << endl;
cout << “Select your prefered activity from below:” << endl;
cout << “0. Display Inventory” << endl;
cout << “1. Search Inventory” << endl;
cout << “2. Sell/Lease Cars” << endl;
cout << “3. Return a Leased Car” << endl;
cout << “4. Add Cars to Inventory” << endl;
cout << “5. Exit” << endl;
cout << “\nPlease Enter a Number: “;
int InputChoice;
cin >> InputChoice;
switch (InputChoice) {
case 0:
displayInventory();
break;
case 1:
Search();
break;
case 2:
int sellorlease;
cout << “\nDo you want to sell a car or lease?” << endl;
cout << “1. Sell a car” << endl;
cout << “2. Lease a car” << endl;
cout << “\nPlease enter a number: “;
cin >> sellorlease;
if (sellorlease == 1) {
SellCar();
}
else if (sellorlease == 2) {
LeaseCar();
}
break;
case 3:
ReturnLeasedCar();
break;
case 4:
AddCar();
break;
case 5:
exit(1);
default:
cout << “\n************” << endl;
cout << “WRONG ENTRY!” << endl;
cout << “************\n” << endl;
break;
}
cout << endl;
}
}

void displayInventory();
void Search();
void SellCar();
void LeaseCar();
void ReturnLeasedCar();
void AddCar();

#include “Functions.h”
#include “NewCar.h”
#include <iostream>
using namespace std;
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>

/***************************************************
DISPLAY INVENTORY
****************************************************/

void displayInventory() {
OldCar oldprint;
NewCar newprint;
cout << “\nChoose which inventory do you want to see.” << endl;
cout << “1. New Cars Inventory” << endl;
cout << “2. Old Cars Inventory” << endl;
cout << “3. Complete Inventory” << endl;
cout << “\nPlease enter a number: “;
int displayoption;
cin >> displayoption;
if (displayoption == 1) {
newprint.printInfo();
}
else if (displayoption == 2) {
oldprint.printInfo();
}
else if (displayoption == 3) {
newprint.Car::printInfo();
}
}

/***************************************************
SEARCH INVENTORY
****************************************************/
void Search()
{
int neworoldsearch;
cout << “\nAre you search a new or an old car? ” << endl;
cout << “1. New Car” << endl;
cout << “2. Old Car” << endl;
cout << “\nPlease Enter a Number: “;
cin >> neworoldsearch;
if (neworoldsearch == 1) {
NewCar newcar;
cout << “\nHow would you like to search for a car?” << endl;
cout << “1. Search by VIN” << endl;
cout << “2. Search by Make” << endl;
cout << “3. Search by Model” << endl;
cout << “4. Search by Year” << endl;
cout << “5. Search by Price” << endl;
cout << “6. Search by Category” << endl;
cout << “7. Search by Mileage” << endl;
cout << “8. Search by Warranty Provider” << endl;
int SearchEntry;
cout << “\nPlease Enter a Number: “;
cin >> SearchEntry;
string v, mk, md, c, wp;
int y;
float p, mi;
switch (SearchEntry) {
case 1:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
newcar.Search(v);
break;
case 2:
cout << “\nPlease Enter Make: “;
cin >> mk;
transform(mk.begin(), mk.end(), mk.begin(), ::toupper);
newcar.Search(mk);
break;
case 3:
cout << “\nPlease Enter Model: “;
cin >> md;
transform(md.begin(), md.end(), md.begin(), ::toupper);
newcar.Search(md);
break;
case 4:
int yearoption;
cout << “\nHow do you want to search a car by year?” << endl;
cout << “1. By specific year” << endl;
cout << “2. By year range” << endl;
cout << “\nPlease Enter a number: “;
cin >> yearoption;
if (yearoption == 1) {
cout << “\nEnter the year: “;
cin >> y;
newcar.Search(y);
}
else if (yearoption == 2) {
int lowyr, highyr;
cout << “\nEnter the lowest year: “;
cin >> lowyr;
cout << “Enter the highest year: “;
cin >> highyr;
newcar.Search(lowyr, highyr);
}
break;
case 5:
int priceoption;
cout << “\nHow do you want to search a car by price?” << endl;
cout << “1. By specific price” << endl;
cout << “2. By price range” << endl;
cout << “\nPlease Enter a number: “;
cin >> priceoption;
if (priceoption == 1) {
cout << “\nEnter The Price: “;
cin >> p;
newcar.Search(“PRICE”, p);
}
else if (priceoption == 2) {
float lowp, highp;
cout << “\nEnter the lowest price: “;
cin >> lowp;
cout << “Enter the highest price: “;
cin >> highp;
newcar.Search(“PRICE”, lowp, highp);
}
break;
case 6:
cout << “\nPLease Enter Category: “;
cin >> c;
transform(c.begin(), c.end(), c.begin(), ::toupper);
newcar.Search(c);
break;
case 7:
int mileageoption;
cout << “\nHow do you want to search a car by mileage?” << endl;
cout << “1. By specific mileage” << endl;
cout << “2. By mileage range” << endl;
cout << “\nPlease Enter a number: “;
cin >> mileageoption;
if (mileageoption == 1) {
cout << “\nPlease Enter 0.0 in Mileage for new car: “;
cin >> mi;
newcar.Search(“MILEAGE”, mi);
}
else if (mileageoption == 2) {
float lowmi, highmi;
cout << “\nEnter the lowest mileage: “;
cin >> lowmi;
cout << “Enter the highest mileage: “;
cin >> highmi;
newcar.Search(“MILEAGE”, lowmi, highmi);
}
break;
case 8:
cout << “\nPlease Enter Warranty Provider: “;
cin >> wp;
transform(wp.begin(), wp.end(), wp.begin(), ::toupper);
newcar.Search(wp);
break;
}
}

else if (neworoldsearch == 2) {
OldCar oldcar;
cout << “\nHow would you like to search for a car?” << endl;
cout << “1. Search by VIN” << endl;
cout << “2. Search by Make” << endl;
cout << “3. Search by Model” << endl;
cout << “4. Search by Year” << endl;
cout << “5. Search by Price” << endl;
cout << “6. Search by Category” << endl;
cout << “7. Search by Mileage” << endl;
cout << “8. Search by Warranty Provider” << endl;
int SearchEntry;
cout << “\nPlease Enter a Number: “;
cin >> SearchEntry;
string v, mk, md, c, wp;
int y;
float p, mi;
switch (SearchEntry) {
case 1:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
oldcar.Search(v);
break;
case 2:
cout << “\nPlease Enter Make: “;
cin >> mk;
transform(mk.begin(), mk.end(), mk.begin(), ::toupper);
oldcar.Search(mk);
break;
case 3:
cout << “\nPlease Enter Model: “;
cin >> md;
transform(md.begin(), md.end(), md.begin(), ::toupper);
oldcar.Search(md);
break;
case 4:
int yearoption;
cout << “\nHow do you want to search a car by year?” << endl;
cout << “1. By specific year” << endl;
cout << “2. By year range” << endl;
cout << “\nPlease Enter a number: “;
cin >> yearoption;
if (yearoption == 1) {
cout << “\nEnter the year: “;
cin >> y;
oldcar.Search(y);
}
else if (yearoption == 2) {
int lowyr, highyr;
cout << “\nEnter the lowest year: “;
cin >> lowyr;
cout << “Enter the highest year: “;
cin >> highyr;
oldcar.Search(lowyr, highyr);
}
break;
case 5:
int priceoption;
cout << “\nHow do you want to search a car by price?” << endl;
cout << “1. By specific price” << endl;
cout << “2. By price range” << endl;
cout << “\nPlease Enter a number: “;
cin >> priceoption;
if (priceoption == 1) {
cout << “\nEnter The Price: “;
cin >> p;
oldcar.Search(“PRICE”, p);
}
else if (priceoption == 2) {
float lowp, highp;
cout << “\nEnter the lowest price: “;
cin >> lowp;
cout << “Enter the highest price: “;
cin >> highp;
oldcar.Search(“PRICE”, lowp, highp);
}
break;
case 6:
cout << “\nPLease Enter Category: “;
cin >> c;
transform(c.begin(), c.end(), c.begin(), ::toupper);
oldcar.Search(c);
break;
case 7:
int mileageoption;
cout << “\nHow do you want to search a car by mileage?” << endl;
cout << “1. By specific mileage” << endl;
cout << “2. By mileage range” << endl;
cout << “\nPlease Enter a number: “;
cin >> mileageoption;
if (mileageoption == 1) {
cout << “\nEnter The Mileage: “;
cin >> mi;
oldcar.Search(“MILEAGE”, mi);
}
else if (mileageoption == 2) {
float lowmi, highmi;
cout << “\nEnter the lowest mileage: “;
cin >> lowmi;
cout << “Enter the highest mileage: “;
cin >> highmi;
oldcar.Search(“MILEAGE”, lowmi, highmi);
}
break;
case 8:
cout << “\nPlease Enter NA in Warranty Provider for old car: “;
cin >> wp;
transform(wp.begin(), wp.end(), wp.begin(), ::toupper);
oldcar.Search(wp);
break;
}
} //end if 1
}

void SellCar()
{
int selloption;
string v;
cout << “\nAre you selling a new or an old car?” << endl;
cout << “1. New Car” << endl;
cout << “2. Old Car” << endl;
cout << “\nPlease enter a number: “;
cin >> selloption;
NewCar newsell;
OldCar oldsell;
switch (selloption) {
case 1:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
newsell.SellCar(v);
break;
case 2:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
oldsell.SellCar(v);
break;

}
}

void LeaseCar()
{
int leaseoption;
string v;
cout << “\nAre you selling a new or an old car?” << endl;
cout << “1. New Car” << endl;
cout << “2. Old Car” << endl;
cout << “\nPlease enter a number: “;
cin >> leaseoption;
NewCar newlease;
OldCar oldlease;
switch (leaseoption) {
case 1:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
newlease.LeaseCar(v);
break;
case 2:
cout << “\nPlease Enter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
oldlease.LeaseCar(v);
break;

}
}

void ReturnLeasedCar() {
ifstream CarsOnLeaseInventory;
string path = “CarsOnLeaseInventory.txt”;
CarsOnLeaseInventory.open(path);

ofstream temp(“temp.txt”);

ofstream outReturn;
ifstream inReturn;
inReturn.open(“OldCarInventory.txt”);
outReturn.open(“OldCarInventory.txt”, ios::in | ios::out | ios::ate); // ios::app);

string v, v1, mk1, md1, c1, wp1;
int y1;
float p1, mi, mi1;
int count = 0;

cout << “\nEnter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
cout << “Enter Current Mileage: “;
cin >> mi;

while (CarsOnLeaseInventory >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {

if (inReturn.is_open()) {
if (v == v1) {
if (mi <= mi1) {
cout << “\n*****************************************************************” << endl;
cout << “WRONG ENTRY! CURRENT MILEAGE MUST BE HIGHER THAN PREVIOUS RECORD!” << endl;
cout << “*****************************************************************\n” << endl;
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
temp << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
else {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
outReturn << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << mi << ” ” << newcar2.getWarrantyProvider() << endl;
/*inReturn.close();
outReturn.close();*/
count++;
cout << “\n**************************” << endl;
cout << “CAR RETURNED SUCCESSFULLY!” << endl;
cout << “**************************\n” << endl;
}
}

else {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
/*temp << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << newcar2.getWarrantyProvider() << endl;*/
temp << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << newcar2.getWarrantyProvider() << endl;
/*temp << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;*/
}
}
}
if (count == 0) {
cout << “\n********************************************************************************” << endl;
cout << “WRONG ENTRY! VIN MUST MATCH AND MILEAGE MUST BE HIGHER THAN THE PREVIOUS RECORD!” << endl;
cout << “********************************************************************************\n” << endl;
}

 

temp.close();
outReturn.close();
CarsOnLeaseInventory.close();


const char* pp = path.c_str();
remove(pp);
rename(“temp.txt”, pp);
}


void AddCar()
{
cout << “\nAre you adding a new or an old car?” << endl;
cout << “1. New Car” << endl;
cout << “2. Old Car” << endl;
cout << “\nPlease Enter a number: “;
int addnewold;
cin >> addnewold;
if (addnewold == 1) {
NewCar addnew;
ifstream inOld(“OldCarInventory.txt”);
ifstream inNew(“NewCarInventory.txt”);
string v, v1, mk, mk1, md, md1, c, c1, wp, wp1;
int y, y1;
float p, p1, mi, mi1;
cout << “\nEnter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1 || inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (v == v1) {
cout << “\n*******************” << endl;
cout << “CAR ALREADY EXISTS!” << endl;
cout << “*******************\n” << endl;
exit(1);
}
}
cout << “Enter Make: “;
cin >> mk;
transform(mk.begin(), mk.end(), mk.begin(), ::toupper);
cout << “Enter Model: “;
cin >> md;
transform(md.begin(), md.end(), md.begin(), ::toupper);
cout << “Enter Year: “;
cin >> y;
cout << “Enter Price: “;
cin >> p;
cout << “Enter Category: “;
cin >> c;
transform(c.begin(), c.end(), c.begin(), ::toupper);
cout << “Mileage for new car is 0.0 by default” << endl;
mi = 0.0;
cout << “Enter Warranty Provider: “;
cin >> wp;
addnew.AddCar(v, mk, md, y, p, c, mi, wp);
}
else if (addnewold == 2) {
OldCar addold;
ifstream inOld(“OldCarInventory.txt”);
ifstream inNew(“NewCarInventory.txt”);
string v, v1, mk, mk1, md, md1, c, c1, wp, wp1;
int y, y1;
float p, p1, mi, mi1;
cout << “\nEnter VIN: “;
cin >> v;
transform(v.begin(), v.end(), v.begin(), ::toupper);
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1 || inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (v == v1) {
cout << “\n*******************” << endl;
cout << “CAR ALREADY EXISTS!” << endl;
cout << “*******************\n” << endl;
exit(1);
}
}
cout << “Enter Make: “;
cin >> mk;
transform(mk.begin(), mk.end(), mk.begin(), ::toupper);
cout << “Enter Model: “;
cin >> md;
transform(md.begin(), md.end(), md.begin(), ::toupper);
cout << “Enter Year: “;
cin >> y;
cout << “Enter Price: “;
cin >> p;
cout << “Enter Category: “;
cin >> c;
transform(c.begin(), c.end(), c.begin(), ::toupper);
cout << “Enter Mileage: “;
cin >> mi;
cout << “Warranty provider for old car is not applicable!” << endl;
wp = “NA”;
addold.AddCar(v, mk, md, y, p, c, mi, wp);
}
}

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
class Car
{
private:
string VIN;
string Make;
string Model;
int Year;
float Price;
string Category;
 
public:
string getVIN();
string getMake();
string getModel();
int getYear();
float getPrice();
string getCategory();
Car();
Car(string vin, string make, string model, int year, float price, string category);
virtual void printInfo();
 
};

#include “Car.h”

string Car::getVIN()
{
return VIN;
}

string Car::getMake()
{
return Make;
}

string Car::getModel()
{
return Model;
}

int Car::getYear()
{
return Year;
}

float Car::getPrice()
{
return Price;
}

string Car::getCategory()
{
return Category;
}

Car::Car()
{
VIN = ” “;
Make = ” “;
Model = ” “;
Year = 0;
Price = 0.0;
Category = ” “;
}

Car::Car(string vin, string make, string model, int year, float price, string category)
{
VIN = vin;
Make = make;
Model = model;
Year = year;
Price = price;
Category = category;
}

void Car::printInfo() {
string v, v1;
string mk, mk1;
string md, md1;
int y = 0, y1;
float p = 0.0, p1;
string c, c1;
float mi = 0.0, mi1;
string wp, wp1;
ifstream inOld(“OldCarInventory.txt”);
ifstream inNew(“NewCarInventory.txt”);
cout << “\n*************************” << endl;
cout << “NEW CARS IN OUR INVENTORY” << endl;
cout << “*************************\n” << endl;
while (inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
cout << v1 << ” ” << mk1 << ” ” << md1 << ” ” << y1 << ” ” << p1 << ” ” << c1 << ” ” << mi1 << ” ” << wp1 << endl;
}
cout << “\n*************************” << endl;
cout << “OLD CARS IN OUR INVENTORY” << endl;
cout << “*************************\n” << endl;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
cout << v1 << ” ” << mk1 << ” ” << md1 << ” ” << y1 << ” ” << p1 << ” ” << c1 << ” ” << mi1 << ” ” << wp1 << endl;
}
}

#include “Car.h”
class OldCar :
public Car
{
private:
float Mileage;
public:
float getMileage();
OldCar();
OldCar(string vin, string make, string model, int year, float price, string category, float mileage);
void printInfo();
void Search(string Strinp);
void Search(int Intinp);
void Search(int Intinp, int Intinp2);
void Search(string choice, float Fltinp);
void Search(string choice, float Fltinp, float Fltinp2);
void SellCar(string vin);
void LeaseCar(string vin);
//void ReturnLeasedCar(string vin, float mileage);
void AddCar(string v, string mk, string md, int y, float p, string c, float mi, string wp);
};

#include “OldCar.h”
#include <fstream>

float OldCar::getMileage()
{
return Mileage;
}

OldCar::OldCar()
{
Mileage = 0.0;
}
OldCar::OldCar(string vin, string make, string model, int year, float price, string category, float mileage) :
Car(vin, make, model, year, price, category)
{
Mileage = mileage;
}

void OldCar::printInfo() {
string v, v1;
string mk, mk1;
string md, md1;
int y = 0, y1;
float p = 0.0, p1;
string c, c1;
float mi = 0.0, mi1;
string wp, wp1;
ifstream inOld(“OldCarInventory.txt”);
cout << “\n*************************” << endl;
cout << “OLD CARS IN OUR INVENTORY” << endl;
cout << “*************************\n” << endl;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
cout << v1 << ” ” << mk1 << ” ” << md1 << ” ” << y1 << ” ” << p1 << ” ” << c1 << ” ” << mi1 << ” ” << wp1 << endl;
}
}

void OldCar::Search(string Strinp)
{
ifstream inOld(“OldCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Strinp == v1 || Strinp == mk1 || Strinp == md1 || Strinp == c1 || Strinp == wp1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void OldCar::Search(int Intinp)
{
ifstream inOld(“OldCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Intinp == y1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void OldCar::Search(int Intinp, int Intinp2)
{
ifstream inOld(“OldCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Intinp <= y1 && Intinp2 >= y1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void OldCar::Search(string choice, float Fltinp)
{
ifstream inOld(“OldCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
if (choice == “PRICE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp == p1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
}
if (choice == “MILEAGE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp == mi1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void OldCar::Search(string choice, float Fltinp, float Fltinp2)
{
ifstream inOld(“OldCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
if (choice == “PRICE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp <= p1 && Fltinp2 >= p1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
}
elseif (choice == “MILEAGE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp <= mi1 && Fltinp2 >= mi1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
cout << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
count++;
}
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void OldCar::SellCar(string vin)
{
ifstream inOld;
string path = “OldCarInventory.txt”;
inOld.open(path);
ofstream temp(“temp.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (vin == v1) {
count++;
}
elseif (vin != v1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
temp << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
else {
cout << “\n***************************************” << endl;
cout << “CONGRATULATIONS! CAR SOLD SUCCESSFULLY!” << endl;
cout << “***************************************\n” << endl;
}

temp.close();
inOld.close();

constchar* pp = path.c_str();
remove(pp);
rename(“temp.txt”, pp);
}

void OldCar::LeaseCar(string vin)
{
ifstream inOld;
string path = “OldCarInventory.txt”;
inOld.open(path);

ofstream temp(“temp.txt”);

ofstream outLease;
ifstream inLease;
inLease.open(“CarsOnLeaseInventory.txt”);
outLease.open(“CarsOnLeaseInventory.txt”, ios::app);

string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (vin == v1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
if (inLease.is_open()) {
outLease << endl << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
inLease.close();
outLease.close();
}
count++;
}

elseif (vin != v1) {
OldCar oldcar2(v1, mk1, md1, y1, p1, c1, mi1);
temp << oldcar2.getVIN() << ” ” << oldcar2.getMake() << ” ” << oldcar2.getModel() << ” ” << oldcar2.getYear() << ” ” << oldcar2.getPrice() << ” ” << oldcar2.getCategory()
<< ” ” << oldcar2.getMileage() << ” ” << “NA” << endl;
}
}

if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
else {
cout << “\n*****************************************” << endl;
cout << “CONGRATULATIONS! CAR LEASED SUCCESSFULLY!” << endl;
cout << “*****************************************\n” << endl;
}
temp.close();
inOld.close();


constchar* pp = path.c_str();
remove(pp);
rename(“temp.txt”, pp);
}
 
void OldCar::AddCar(string v, string mk, string md, int y, float p, string c, float mi, string wp)
{
ofstream outAdd;
ifstream inAdd;
inAdd.open(“OldCarInventory.txt”);
outAdd.open(“OldCarInventory.txt”, ios::app);
if (inAdd.is_open()) {
outAdd << v << ” ” << mk << ” ” << md << ” ” << y << ” ” << p << ” ” << c
<< ” ” << mi << ” ” << wp << endl;
inAdd.close();
outAdd.close();
}
cout << “\n***********************” << endl;
cout << “CAR ADDED SUCCESSFULLY!” << endl;
cout << “***********************\n” << endl;
}

#include “OldCar.h”
class NewCar :
public Car
{
private:
string WarrantyProvider;
public:
string getWarrantyProvider();
NewCar();
NewCar(string vin, string make, string model, int year, float price, string category, string warrantyprovider);
void printInfo();
void Search(string Strinp);
void Search(int Intinp);
void Search(int Intinp, int Intinp2);
void Search(string choice, float Fltinp);
void Search(string choice, float Fltinp, float Fltinp2);
void SellCar(string vin);
void LeaseCar(string vin);
void AddCar(string v, string mk, string md, int y, float p, string c, float mi, string wp);
};

#include “NewCar.h”

string NewCar::getWarrantyProvider()
{
return WarrantyProvider;
}

NewCar::NewCar()
{
WarrantyProvider = ” “;
}

NewCar::NewCar(string vin, string make, string model, int year, float price, string category, string warrantyprovider)
: Car(vin, make, model, year, price, category)
{
WarrantyProvider = warrantyprovider;
}
void NewCar::printInfo() {
string v, v1;
string mk, mk1;
string md, md1;
int y = 0, y1;
float p = 0.0, p1;
string c, c1;
float mi = 0.0, mi1;
string wp, wp1;
ifstream inNew(“NewCarInventory.txt”);
cout << “\n*************************” << endl;
cout << “NEW CARS IN OUR INVENTORY” << endl;
cout << “*************************\n” << endl;
while (inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
cout << v1 << ” ” << mk1 << ” ” << md1 << ” ” << y1 << ” ” << p1 << ” ” << c1 << ” ” << mi1 << ” ” << wp1 << endl;
}
}


void NewCar::Search(string Strinp)
{
ifstream inOld(“NewCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Strinp == v1 || Strinp == mk1 || Strinp == md1 || Strinp == c1 || Strinp == wp1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void NewCar::Search(int Intinp)
{
ifstream inOld(“NewCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Intinp == y1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void NewCar::Search(int Intinp, int Intinp2)
{
ifstream inOld(“NewCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Intinp <= y1 && Intinp2 >= y1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void NewCar::Search(string choice, float Fltinp)
{
ifstream inOld(“NewCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
if (choice == “PRICE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp == p1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
}
if (choice == “MILEAGE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp == mi1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void NewCar::Search(string choice, float Fltinp, float Fltinp2)
{
ifstream inOld(“NewCarInventory.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
if (choice == “PRICE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp <= p1 && Fltinp2 >= p1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
}
else if (choice == “MILEAGE”) {
while (inOld >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (Fltinp <= mi1 && Fltinp2 >= mi1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
cout << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
count++;
}
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
}

void NewCar::SellCar(string vin)
{
ifstream inNew;
string path = “NewCarInventory.txt”;
inNew.open(path);
ofstream temp(“temp.txt”);
string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (vin == v1) {
count++;
}
else if (vin != v1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
temp << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
}
}
if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
else {
cout << “\n***************************************” << endl;
cout << “CONGRATULATIONS! CAR SOLD SUCCESSFULLY!” << endl;
cout << “***************************************\n” << endl;
}

temp.close();
inNew.close();

const char* pp = path.c_str();
remove(pp);
rename(“temp.txt”, pp);
}

void NewCar::LeaseCar(string vin)
{
ifstream inNew;
string path = “NewCarInventory.txt”;
inNew.open(path);

ofstream temp(“temp.txt”);

ofstream outLease;
ifstream inLease;
inLease.open(“CarsOnLeaseInventory.txt”);
outLease.open(“CarsOnLeaseInventory.txt”, ios::app);

string v1, mk1, md1, c1, wp1;
int y1;
float p1, mi1;
int count = 0;
while (inNew >> v1 >> mk1 >> md1 >> y1 >> p1 >> c1 >> mi1 >> wp1) {
if (vin == v1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
if (inLease.is_open()) {
outLease << endl << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << ” ” << endl;
inLease.close();
outLease.close();
}
count++;
}

else if (vin != v1) {
NewCar newcar2(v1, mk1, md1, y1, p1, c1, wp1);
temp << newcar2.getVIN() << ” ” << newcar2.getMake() << ” ” << newcar2.getModel() << ” ” << newcar2.getYear() << ” ” << newcar2.getPrice() << ” ” << newcar2.getCategory()
<< ” ” << 0.0 << ” ” << newcar2.getWarrantyProvider() << endl;
}
}

if (count == 0) {
cout << “\n************************************************” << endl;
cout << “OOPS! WE COULD NOT FIND ANY CAR WITH THIS INPUT!” << endl;
cout << “************************************************\n” << endl;
}
else {
cout << “\n*****************************************” << endl;
cout << “CONGRATULATIONS! CAR LEASED SUCCESSFULLY!” << endl;
cout << “*****************************************\n” << endl;
}
temp.close();
inNew.close();


const char* pp = path.c_str();
remove(pp);
rename(“temp.txt”, pp);

}


void NewCar::AddCar(string v, string mk, string md, int y, float p, string c, float mi, string wp)
{
ofstream outAdd;
ifstream inAdd;
inAdd.open(“NewCarInventory.txt”);
outAdd.open(“NewCarInventory.txt”, ios::app);
if (inAdd.is_open()) {
outAdd << v << ” ” << mk << ” ” << md << ” ” << y << ” ” << p << ” ” << c
<< ” ” << mi << ” ” << wp << endl;
inAdd.close();
outAdd.close();
}
cout << “\n***********************” << endl;
cout << “CAR ADDED SUCCESSFULLY!” << endl;
cout << “***********************\n” << endl;
}

4V462846G43692014 TOYOTA RAV4 2010 11000 SUV 107000 NA
4323649FEGFWG2378 TOYOTA CAMRY 2013 7000 SEDAN 168000 NA
SDF3274FGDSF38RG4 TOYOTA CAMRY 2017 14000 SEDAN 143900 NA
498TH340TG84TY200 TOYOTA TACOMA 2013 23590 TRUCK 58000 NA
48SS24720GH37502L NISSAN ALTIMA 2015 13000 SEDAN 134000 NA
EWGWEHTEPFWTEPOJG NISSAN ROGUE 2020 21990 SUV 51780 NA
SF45923TYFH0235Y8 HONDA CIVIC 2017 21590 SEDAN 40956 NA
EWNT3493285023595 HONDA CIVIC 2009 13590 SEDAN 84698 NA
FW9EFQEWOFHQOETEW HONDA CR-V 2009 17990 SUV 61334 NA
FH83452395Y203FH4 GMC SIERRA 2016 24590 TRUCK 100327 NA
WR39R324023Y02335 FORD F150 2019 45590 TRUCK 72439 NA
CJAFHWUEFGWEOGBFE FORD ESCAPE 2016 22330 SUV 20000 NA
SFHE24244657D24SS TOYOTA CAMRY 2013 7000 SEDAN 160000 NA

35720375315621056 FORD BRONCO 2022 31300 SUV 0 AAA
24Y2389TR894EHGF9 FORD EXPLORER 2022 35510 SUV 0 PROGRESSIVE
23HR3U2RI4327TRGF KIA TELLURIDE 2022 33390 SUV 0 AAA
ER9835Y29FH2308R3 KIA K5 2022 24885 SEDAN 0 PROGRESSIVE
FH34752Y380235035 KI K5 2023 26185 SEDAB 0 AAA
DFH3W7RY329R43HR7 HYUNDAI TUCSON 2022 24950 SUV 0 AAA
38Y259Y8239238Y52 HYUNDAI SANTA-FE 2022 28815 SUV 0 PROGRESSIVE
DUWETR983432035Y8 HONDA HR-V 2023 23800 SUV 0 AAA
35823FH3298FHIUEH HONDA PILOT 2022 38080 SUV 0 PROGRESSIVE
3R23YRF3HFEWH04T8 HONDA CIVIC 2023 24650 SEDAN 0 AAA
3Y542395439752340 TOYOTA CAMRY 2022 25845 SEDAN 0 PROGRESSIVE
23453956243579204 TOYOTA COROLLA 2022 20425 SEDAN 0 PROGRESSIVE
DSFG3897RGG43YGR8 TOYOTA COROLLA 2022 20425 SEDAN 0 AAA
R34Y75239530845Y3 TOYOTA PRIUS 2022 25075 SEDAN 0 AAA
35239YR43058Y3208 TOYOTA PRIUS-PRIME 28770 SEDAN 0 AAA
ADFEF3352DADFET43 AUDI A3 2023 35400 SEDAN 0 AAA

WFEWFHOFHSDOGHOWE LEXUS RC-F 2022 67470 SEDAN 0 AAA
D382R320RY203RY32 LEXUS GX 2022 72310 SUV 5230 NA
WEONIFRH20ER23P39 LEXUS GX 2022 72310 SUV 0 AAA
WHFQW0RHWOETRHWQE TESLA 3 2022 68130 SEDAN 8329 NA
R238RY23OHR2043FH TESLA 3 2023 72190 SEDAN 0 AAA