Write a program for a car dealership that has a database of information for diff
ID: 3735949 • Letter: W
Question
Write a program for a car dealership that has a database of information for different automobiles. Each automobile has one or more attributes associated with it (color, Looks sporty, etc.). The number of attributes that each automobile has is not known at this time (and can be different for each). The program needs to accept commands with the goal of providing a list of automobiles that fit your criteria Input: 1. The list of automobiles and attributes should be stored in a file called autodata.txt. This file is to be read at the beginning each time your program is run (if it exists). Your program will create this file. The format for this file shall be: NameCar1,Attribute1,Attribute2,.. NameCar2,Attribute1,Attribute2, This is just a comma separated list with the car name first followed by all of its attributes. I will also check your programs with a data file that I generate so the file MUST be in this format. 2. The input formats as well as the commands are in the table below. Also, the entire program shall not be case sensitive Output: 1. The responses to the user's commands. 2. Each time you execute the SHOW command, also place the results in a file called results.txt. This file can be any format, however, make sure it is labeled clearly. Also, this file should append these results to previous runs When new cars along with their attributes are added using the ADD command, this data must be persisted to the autodata.txt. 3. Commands: Command ADD How it is processed Adds a new automobile. Prompt user for car name and the list of attributes. Shall not work if in search mode Puts program in search mode. Prompt for name of this search (should probably be heading in the results.txt file Prompt user to enter an attribute to look for. Then process your list of current cars that match this criterion. If there is only one car left, print out the name of this car and that Search hasFeature ou have found it (this case would terminate search mode). (Search Mode Onl Input the name of an automobile and print out the attributes about it if it exists in CheckAuto search list. (Search Mode Onl Shows the current list of automobiles that match all of the features you have listed as ow criteria thus far. (Search Mode Onl Exits Search mode and resets all attributes that were entered. Save the autodata.txt file if automobiles have been added and exits the program. Exit Quit NotesExplanation / Answer
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Car
{
private:
string name;
string color;
double price;
public:
//---------------------------------------------------------------------------------------
/*
* Constructor/Destructor
*
* Handles creation and deletion of Car objects.
*
* Parameter: name_in
* The name of a new car
* Parameter: color_in
* The color of a new car
* Parameter: price_in
* The price of a new car
*/
Car(string name_in, string color_in, double price_in);
virtual ~Car();
//---------------------------------------------------------------------------------------
/*
* getName
*
* Returns the name of the car.
*
* Return:
* The name of the car
*/
string getName();
/*
* getColor
*
* Returns the color of the car.
*
* Return:
* The color of the car
*/
string getColor();
/*
* getPrice
*
* Returns the price of the car.
*
* Return:
* The price of the car
*/
double getPrice();
//---------------------------------------------------------------------------------------
/*
* paint
*
* Paints the car a new color and increases the price by $1,000.
*
* Parameter: new_color
* The color of paint to be used on the car
*/
void paint(string new_color);
//---------------------------------------------------------------------------------------
/*
* toString
*
* Returns a single string containing useful information about the car.
*
* Return:
* A data string about this car
*/
string toString();
//---------------------------------------------------------------------------------------
};
//WARNING: It is expressly forbidden to modify any part of this document, including its name
#include "car.h"
using namespace std;
//---------------------------------------------------------------------------------------
Car::Car(string name_in, string color_in, double price_in)
{
name = name_in;
color = color_in;
price = price_in;
}
Car::~Car() {}
//---------------------------------------------------------------------------------------
string Car::getName()
{
return name;
}
string Car::getColor()
{
return color;
}
double Car::getPrice()
{
return price;
}
//---------------------------------------------------------------------------------------
void Car::paint(string new_color)
{
color = new_color;
price += 1000;
}
//---------------------------------------------------------------------------------------
string Car::toString()
{
stringstream ss;
ss << "Name: " << name << endl;
ss << "Color: " << color << endl;
ss << "Price: $" << price << endl;
return ss.str();
}
//---------------------------------------------------------------------------------------
#include <iostream>
#include "car.h"
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
int option;
string name;
string color;
double price = 0;
double balance = 10000;
vector <Car> cars;
do
{
cout << "Please select an option:" << endl;
cout << "1 - Show current inventory." << endl;
cout << "2 - Show current balance." << endl;
cout << "3 - Buy a car." << endl;
cout << "4 - Sell a car." << endl;
cout << "5 - Paint a car." << endl;
cout << "6 - Load file." << endl;
cout << "7 - Save file." << endl;
cout << "8 - Quit program." << endl;
cout << " ";
cin >> option;
if (option == 1)
{
for (int i = 0; i < cars.size(); i++)
{
cout << cars[i].toString();
}
}
if (option == 2)
{
cout << "$" << balance << endl;
}
if (option == 3)
{
cout << "Please enter the name, color, and price of the car you would like to buy." << endl;
cin >> name;
cin >> color;
cin >> price;
Car newcar(name, color, price);
if (price <= balance)
{
cars.push_back(newcar);
cout << "Car has been purchased." << endl;
balance = balance - price;
}
else
{
cout << "You cannot afford that car." << endl;
option = 0;
}
}
if (option == 4)
{
cout << "Please enter the name of the car you want to sell." << endl;
cin >> name;
bool found = true;
for (int j = 0; j < cars.size(); j++)
{
if (cars[j].getName() == name)
{
found = false;
price = cars[j].getPrice();
cars.erase(cars.begin() + j);
cout << "You have sold the " << name << endl;
balance = balance + price;
}
else
{
cout << "You don't own that car." << endl;
}
}
}
if (option == 5)
{
cout << "Please enter the name of the car you want to paint." << endl;
cin >> name;
bool found = true;
for (int j = 0; j < cars.size(); j++)
{
if (cars[j].getName() == name)
{
found = false;
cout << "What color do you want to paint the " << name << "?" << endl;
cin >> color;
cars[j].paint(color);
cout << "You have painted the " << name << " " << color << "." << endl;
}
else
{
cout << "You don't own that car." << endl;
}
}
}
if (option == 6)
{
string chooseFile;
}
if (option == 7)
{
for (int i = 0; i < cars.size(); i++)
{
ofstream fout;
fout.open("Lab 8.txt");
fout << cars[i].toString() << endl;
fout << "$" << balance << endl;
}
}
if (option == 8)
{
exit(0);
}
if (option < 0 || option > 8)
{
cout << "Please enter a number from 1-8." << endl;
}
cout << " ";
} while (option < 8 || option > 8);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.