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

The options.txt is formatted like this:

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

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

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

//function signature
void showMenu();
char getModel();
void displaySelection(char model, double total, vector<string> &options);
bool isEqual(string str1, string str2);

// main function to run the program
int main() {
    // print a welcome message
   cout << "Welcome to Bobcats Auto Dealership" << endl;
   // declare variables
   int input = 0;
   char model = ' ';
   double total = 0;
   vector<int> price;
   vector<string> availableOption;
   vector<string> selectedOption;

   // read input from file
   ifstream file("options.txt");
   if (!file.is_open()) {
       cout << "Can not open File!" << endl;
       return -1;
   }
   while (!file.eof()) {
       // first input is price of option
       int cost;
       file >> cost; // get price of option
       // rest of line is option details
       string option;
       getline(file, option);
       // add price to price list
       price.push_back(cost);
       // add option
       if (option[0] == ' ') {
           option = option.substr(1, option.length() - 1); // ignore white space at start of option name
       }
       availableOption.push_back(option);
   }

   // show menu and ask for option till user select quit
   while (input != 6) {
       cout << endl; // print empty line
       // display user selected option
       displaySelection(model, total, selectedOption);
       // show menu for next selection
       showMenu();
       cin >> input; // get user input
       // check for valid input
       if (input < 0 || input>6) {
           cout << "Invalid input!" << endl;
       }
       // check for user input
       if (input == 1) {
           if (model == ' ') {
               model = getModel();
               // check the model and add cost
               if (model == 'E') {
                   total = 10000.0;
               }
               else if (model == 'L') {
                   total = 12000.0;
               }
               else {
                   // model is X
                   total = 18000.0;
               }
           }
       }
       else if (input == 2) {
           // print all options available
           cout << "Prices for model E, L, & X: $10000.00, $12000.00, $18000.00" << endl;
           cout << "Available Options" << endl;
           for (int i = 0; i < availableOption.size(); i++) {
               cout << availableOption.at(i) << "($" << price.at(i) << ")" << endl;
           }
       }
       else if (input == 3) {
           if (model != ' ') {
               cout << "Enter option: ";
               string option_name;
               cin.ignore(); // ignore newline character
               getline(cin, option_name); // get option name from user
               // check if option is available
               for (int i = 0; i < availableOption.size(); i++) {
                   if (isEqual(availableOption.at(i),option_name)) {
                       // check if user already selected that option
                       bool isSelected = false;
                       for (int j = 0; j < selectedOption.size(); j++) {
                           if (isEqual(availableOption.at(i),selectedOption.at(j))) {
                               isSelected = true; // set flag to true
                           }
                       }
                       // add option to selected option if not already selected
                       if (!isSelected) {
                           selectedOption.push_back(availableOption.at(i));
                           // add cost of option
                           total = total + price.at(i);
                       }
                   }
               }
           }
       }
       else if (input == 4) {
           if (model != ' ') {
               cout << "Enter option: ";
               string option_name;
               cin.ignore(); // ignore newline character
               getline(cin, option_name); // get option name from user
               // check if option is seleced
               for (int i = 0; i < selectedOption.size(); i++) {
                   if (isEqual(selectedOption.at(i),option_name)) {
                       // remove cost of option
                       for (int j = 0; j < availableOption.size(); j++) {
                           if (isEqual(selectedOption.at(i),availableOption.at(j))) {
                               total = total - price.at(j);
                           }
                       }
                       // remove option from selected option
                       selectedOption.erase(selectedOption.begin() + i);
                   }
               }
           }
       }
       else if (input == 5) {
           // cancel order and start new one
           model = ' ';
           total = 0;
           selectedOption.clear();
       }
   }

   return 0;
}

// function implementaion
void displaySelection(char model,double total, vector<string> &options) {
   // check if order is started
   if (model == ' ') {
       cout << "NO MODEL SELECTED" << endl;
   }
   else {
       // print model
       cout << "Model: " << model << ", $" << fixed << setprecision(2) << total << endl;
       cout << "Options: ";
       // check for options
       if (options.size() > 0) {
           // print all options
           for (int i = 0; i < options.size(); i++) {
               // print 3 options per line
               if (i != 0 && i % 3 == 0) {
                   cout << endl;
               }
               // print each option
               cout << options.at(i);
               // add commas
               if (i < options.size() - 1) {
                   cout << ", ";
               }
           }
       }
       else {
           cout << "None";
       }
       cout << endl; // print newline
   }
}

void showMenu() {
   cout << "1. Select a model(E, L, X)" << endl;
   cout << "2. Display available options and prices" << endl;
   cout << "3. Add an option" << endl;
   cout << "4. Remove an option" << endl;
   cout << "5. Cancel order" << endl;
   cout << "6. Quit" << endl;
   cout << "Enter choice: " << endl;
}

char getModel() {
   string model = "";
   cin.ignore(); // ignore newline character
   // promt user for model till valid model is selected
   while (true) {
       cout << "Enter the model (E, L, X): ";
       getline(cin, model);
       // check for valid model
       if (model.length() == 1) {
           char c = toupper(model[0]);
           if (c=='E' || c=='L' || c=='X') {
               model = "";
               model = model + c;
               break;
           }
       }
   }
   return model[0];
}

bool compareChar(char& c1, char& c2) {
   if (toupper(c1) == toupper(c2)) {
       return true;
   }
   else {
       return false;
   }
}
bool isEqual(string str1, string str2) {
   return (str1.size() == str2.size() && equal(str1.begin(), str1.end(), str2.begin(), &compareChar));
}

==================================

option.txt

==================================

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

let me know if you have any problem or want any modification in program.

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
  • 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...

  • 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...

  • Using C not C++, Write a program that can be used by a small theater to...

    Using C not C++, Write a program that can be used by a small theater to sell tickets for performances. The theater’s auditorium has 15 rows of seats, with 30 seats in each row. The program should display a screen that shows which seats are available and which are taken. For example, the following screen shows a chart depicting each seat in the theater. Seats that are taken are represented by an * symbol, and seats that are available are...

  • ABC Car Dealership needs your help to update the ordering system. This car dealer is selling...

    ABC Car Dealership needs your help to update the ordering system. This car dealer is selling four types of vehicles: Sedan, Truck, SUV, and mini Van. And each type of vehicle can have several options: sunroof, security, entertainment, and advanced safety feature. As each vehicle can be equipped with none or more options, and even the same option (e.g. sunroof) can be added twice to the same vehicle. The software needs to be able calculate the total price accurately (base...

  • 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 assignment, you are required to implement a flight registration system. Your system should have...

    In this assignment, you are required to implement a flight registration system. Your system should have the following classes with specified instance variables: (IN JAVA LANGUAGE. Your new system should be able to process check-in of passengers and calculate take-off load of planes.) Flight: flightNo, departureTime (DateTime), arrivalTime (DateTime), originCity, destinationCity, maxLoadOfPlane Ticket: ticketNo, flight (Flight), passengerInfo (Passenger), seat, Class CheckIn: ticket (Ticket), weightOfLuggage, checkInTime (DateTime), valid (Boolean) DateTime: day, month, year, hour, minute Passenger: name, surname Also, you should...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • 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....

  • 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...

  • A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is...

    A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is mapped, row-wise, to a 1D-array of size 28: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Implement a well-structured C program to enable a user to make and cancel seat reservations for the bus. The program uses a text-file seats.txt to store the reservation...

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