Question

c++ problem You are asked to implement a car ordering system for Bobcats Auto Dealership. This...

c++ problem

You are asked to implement a car ordering system for Bobcats Auto Dealership. This dealership is brand new and only sells one brand of cars with three different models. However, a buyer can add options if they choose. Write a C++ program that allows the user to order a single car with different options. All the options available will be stored in a file called "options.txt" along with their cost. You may assume that the file will not contain more than 30 options. The user should be able to select the car model, display options and prices, add options, remove options, or cancel the order. Allow the user to see all the available options and their prices. The program should always display the car model, cost, and the options ordered so far. If the user has not selected a car model, then an error message should be displayed indicating that the order has not started yet (e.g. NO MODEL SELECTED). A user should not be able to add more than 6 options to the car. The base prices of the three models: E ($10,000.00), L ($12,000.00), and X ($18,000.00). Implement the following menu options in separate functions: 1. Select a model (E, L, X) The user should enter either E, L, or X (either in lower or upper case). If the wrong character is entered, the user should be prompted repeatedly until the user enters a valid model. Update the order information after this selection. 2. Display available options and prices List all the options 3 per line. See below. 3. Add an option The user should enter an option such as "DVD System", "10 Speakers", etc. The option entered must be one of the options available. If it's not, the user should be prompted repeatedly until the user enters a valid option or enter "cancel". After the selection, the order information should be updated. (see sample input/output below). Duplicate options should not be allowed. 4. Remove an option Allow the user to remove one of the option from the list of options added earlier. Update the order information. If the option name is not in the list of options, then it should be ignored. 5. Cancel order Start over. Update the order information. 6. Quit

Hints: • Use an array/vector to store all the options along with an integer for the number of options read. • Use an array/vector to store all the options' prices. • Use an array/vector of strings for the options added along with an integer for the number of options ordered. • Write a function to convert a string to lowercase for comparison. • Write a function that returns true if an option is valid

Sample input/output: NO MODEL SELECTED 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 3 NO MODEL SELECTED 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 2 Prices for model E, L, & X: $10000.00, $12000.00, $18000.00 Available Options Leather Seats ($5000) DVD System ($1000) 10 Speakers ($800) Navigation System($1400) CarPlay ($500) Android Auto ($500) Lane Monitoring ($2000) 3/36 Warranty ($800) 6/72 Warranty ($999) Dual Climate ($1500) Body Side Molding($225) Cargo Net ($49) Cargo Organizer ($87) 450W Audio ($700) Heated Seats($1000) NO MODEL SELECTED 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 1 Enter the model (E, L, X): l Model: L, $12000.00, Options: None CS 2400 HW 6, Bobcat Auto Dealership (60 points) Due: Wednesday June 19, 2019 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 3 Enter option: 450w aUdIO Model: L, $12700.00, Options: 450W Audio 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 3 Enter option: carplay Model: L, $13200.00, Options: 450W Audio, CarPlay 1. Select a model (E, L, X) 2. Display available options and prices 3. Add an option 4. Remove an option 5. Cancel order 6. Quit Enter choice: 4 Enter option to remove: carplay Model: L, $12700.00, Options: 450W Audio

0 0
Add a comment Improve this question Transcribed image text
Answer #1

screenshot

Ouick Launch (Ct SimplevectorlnCpp Micesoft Visual Studio View Pmjert Ruild Dehu Team Tocls oo ug a6 Analyre Winclew deepthio----------------------------------------------

program

//Header files
#include <iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
using namespace std;
//constants
#define E 10000.00
#define L 12000.00
#define X 18000.00
#define MAX_OPTIONS 6
//function prototypes
void selectModel(char&,bool&);
void displayAvailableOpt(vector<string>, vector<float>);
int displayUserOptions();
void addOption(string*,int& i,vector<string>);
bool optMatch(string, string);
string convertSmall(string);
void deleteOption(string*, int& i);
void orderSummary(char, string[],int,vector<string>,vector<float>);
int main()
{
    //file read object
   ifstream inFile("options.txt");
   //File read error check
   if(!inFile) {
       cout << "File not found!!!" << endl;
       exit(0);
   }
   //Line read variable
   string line;
    //Vector for storing options and corresponding values
   vector<string> options;
   vector<float> costs;
    //Read file data and store corresponding vectors
   while (getline(inFile, line)) {
       string str = "",val="";
       int i=0;
       for (i = 0; i < line.length(); i++) {
           if (line[i] != ',') {
               str += line[i];
           }
           else {
               break;
           }
       }
       while (i < line.length()) {
           val += line[i];
           i++;
       }
       //for removing coma
       val.erase(0, 1);
       options.push_back(str);
       costs.push_back(stof(val));
   }
   bool optSelected = false;
   char model;
   //loop unti quit
   while (true) {
       //Each time for new order
       optSelected = false;
       if (optSelected == false) {
           cout << "\nNO MODEL SELECTED" << endl;
       }
       selectModel(model, optSelected);
       cout << "\nAvailable options and their prices: " << endl;
       displayAvailableOpt(options, costs);
       cout << endl;
       int ch = displayUserOptions();
       int cnt = 0;
       string userOptions[6];
       //option not quit
       while (ch != 4) {
           if (ch == 1) {
               addOption(userOptions, cnt, options);
           }
           else if (ch == 2) {
               deleteOption(userOptions, cnt);
           }
           else {
               optSelected = false;
               break;
           }
           ch = displayUserOptions();
       }
       if (ch == 4) {
           orderSummary(model, userOptions,cnt,options,costs);
           break;
       }
   }
}
//Function to get user model selection
void selectModel(char& model, bool& optSelected) {
   cout << "Select a model(E, L, X): ";
   cin >> model;
   model = toupper(model);
   while (model != 'E' && model != 'L' && model != 'X') {
       cout << "\nNO MODEL SELECTED" << endl;
       cout << "Select a model(E, L, X): ";
       cin >> model;
       model = toupper(model);
   }
   optSelected = true;
}
//function to display all available options
void displayAvailableOpt(vector<string> options, vector<float> costs) {
   for (int i = 0; i < options.size(); i++) {
       cout << options.at(i) << " ($" << costs.at(i) << ")" << endl;
   }
}
//Function to display user options
int displayUserOptions() {
   int ch;
   cout << "User choice: " << endl;
   cout << "1 - Add an option\n2 - Remove an option\n3 - Cancel order\n4 - Quit" << endl;
   cout << "Enter your choice: ";
   cin >> ch;
   while (ch < 1 || ch>4) {
       cout << "\nUser choice: " << endl;
       cout << "1 - Add an option\n2 - Remove an option\n3 - Cancel order\n4 - Quit" << endl;
       cout << "Enter your choice: ";
       cin >> ch;
   }
   return ch;
}
void addOption(string* userOptions, int& i,vector<string> options) {
   string opt;
   cin.ignore();
   if (i < MAX_OPTIONS) {
       cout << "Enter option: ";
       getline(cin, opt);
       for (int j = 0; j < options.size(); j++) {
           if (optMatch(opt, options.at(j))) {
               userOptions[i].assign(opt);
               i++;
               break;
           }
       }
   }
   else {
       cout << "Your added options filled!!!" << endl;
   }
}
//Function to check user otpion and available options
bool optMatch(string user, string available) {
   if (convertSmall(user) == convertSmall(available)) {
       return true;
   }
   return false;
}
//convert to sall
string convertSmall(string s) {
   string str = "";
   for (int i = 0; i < s.length(); i++) {
       if (isalpha(s[i])) {
           str += tolower(s[i]);
       }
       else {
           str += s[i];
       }
   }
   return str;
}
//function to delete an option
void deleteOption(string* userOption, int& i) {
   string opt;
   cin.ignore();
   cout << "Enter option to delete: ";
   getline(cin, opt);
   for (int j = 0; j <= i; j++) {
       if (optMatch(opt, userOption[j])) {
           for (int k = j; k < i; k++) {
               userOption[k] = userOption[k + 1];
           }
           i--;
           return;
       }
   }
   cout << "No match found to delete!!!" << endl;
}
//Print user order details
void orderSummary(char model, string userOptions[], int i,vector<string> options,vector<float> costs) {
   cout << "Model: " << model << ", ";
   float total = 0;
   if (model == 'E') {
       total += E;
   }
   else if (model == 'L') {
       total += L;
   }
   else if (model == 'X') {
       total += X;
   }
   for (int j = 0; j <= i; j++) {
       for (int k = 0; k < options.size(); k++) {
           if (optMatch(userOptions[j], options[k])) {
               total += costs.at(k);
               break;
            }
       }
   }
   cout << fixed << setprecision(2) << "$" << total << ", ";
   for (int j = 0; j <= i; j++) {
       if (j < (i-1)) {
           cout << userOptions[j] << ",";
       }
       else {
           cout << userOptions[j] << endl;
       }
   }
}

---------------------------------------------

output

NO MODEL SELECTED
Select a model(E, L, X): e

Available options and their prices:
Leather Seats ($5000)
DVD System ($1000)
10 Speakers ($800)
Navigation System ($1400)
CarPlay ($500)
Android Auto ($500)
Lane Monitoring ($2000)
3/36 Warranty ($800)
6/72 Warranty ($999)
Dual Climate ($1500)
Body Side Molding ($225)
Cargo Net ($49)
Cargo Organizer ($87)
450W Audio ($700)
Heated Seats ($1000)

User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 1
Enter option: dual climate
User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 3

NO MODEL SELECTED
Select a model(E, L, X): l

Available options and their prices:
Leather Seats ($5000)
DVD System ($1000)
10 Speakers ($800)
Navigation System ($1400)
CarPlay ($500)
Android Auto ($500)
Lane Monitoring ($2000)
3/36 Warranty ($800)
6/72 Warranty ($999)
Dual Climate ($1500)
Body Side Molding ($225)
Cargo Net ($49)
Cargo Organizer ($87)
450W Audio ($700)
Heated Seats ($1000)

User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 1
Enter option: dual climate
User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 1
Enter option: cargo net
User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 2
Enter option to delete: cargo net
User choice:
1 - Add an option
2 - Remove an option
3 - Cancel order
4 - Quit
Enter your choice: 4
Model: L, $13500.00, dual climate

Add a comment
Know the answer?
Add Answer to:
c++ problem You are asked to implement a car ordering system for Bobcats Auto Dealership. This...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C# you will be creating a car dealership app that will contain an Automobile class...

    In C# you will be creating a car dealership app that will contain an Automobile class and three subclasses – Car, Truck, SUV. The properties for Automobile are as follows Base cost Model Make Year The Car will inherit Automobile and include the following: Tax break for better fuel option this calculation will be 2% The Truck will inherit Automobile and include the following: Incentive of $2000 off the cost The SUV will inherit Automobile and include the following: Extra...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry...

    Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...

  • Programming Language is Python Need it to look just like the sample output. pls and ty!!...

    Programming Language is Python Need it to look just like the sample output. pls and ty!! Design your solution: 1. Main menu: Create a main user menu to display the main options to the user. User have the option to choose between 1 and 4. The program will display an error message if user option is not within the valid selection (less than 1 and greater than 4). Think about using a conditional structure to serve the user choice. Invalid...

  • C++ Help please- kind of long. The aim is to implement a seat reservation system for...

    C++ Help please- kind of long. The aim is to implement a seat reservation system for a passenger airplane. We assume a small airplane with 10 rows and 4 seats per row. We assume that the seat chart is initially stored in a file “chartIn.txt” in the following format: 1   A B C D 2   A B C D 3   A B C D 4   A B C D 5   A B C D 6   A B C D 7  ...

  • In this lab, you will create a program to help travelers book flights and hotel stays that will b...

    In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays...

  • Create a python program based on the following requirements the program should also have to have...

    Create a python program based on the following requirements the program should also have to have the following Base Class - Car (Make, Model, year) Sub Class - Gas (Make, Model, year, and gas per mile) Sub Class - Electric (Make, Model, year, and Full Battery charged per mile) 1. Add car 2. View car 3. Delete car 4. Exit program 1. The Car sell manager Application will need to store the car information for gas-powered car members and electric-powered...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the syste...

    Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check the validity of this user-id and password to verify that this is a legitimate user. Because this validation must be done many times each day, it is necessary to structure this information in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT