car dealer

Objectives:
Use arrays, files, searching arrays, manipulating array contents, characters, and strings.
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
CS 2400 HW 6, Bobcat Auto Dealership (60 points)
Due: Wednesday June 19, 2019
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

//just start it.
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void loop();
int input;


int main(int argc, char const *argv[]) {
void loop();
cout << "Enter choice: ";
cin >> input;
/*add code*/
return 0;
}// main

void loop(){
while (input!=6){
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;
cin >> input;
}
if(input == 1){
cout << "Enter the model (E, L, X): "<<endl;
if (input !='E' || input !='L'|| input !='X'){

}

}


}

//i am working on the first case function
Last edited on
What code do you have so far?
just start it.
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void loop();
int input;


int main(int argc, char const *argv[]) {
void loop();
cout << "Enter choice: ";
cin >> input;
/*add code*/
return 0;
}// main

void loop(){
while (input!=6){
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;
cin >> input;
}
if(input == 1){
cout << "Enter the model (E, L, X): "<<endl;
if (input !='E' || input !='L'|| input !='X'){

}

}


}

//i am working on the first case function
Please use code tags. You can edit your post, highlight your code, and then press on the "<>" formatting option on the side of the text box.

Your while loop is going to infinitely loop until the user presses 6. I understand the only time you want to terminate the program is when 6 is entered, but doing it this way stops you from moving on if they enter anything 1-5.

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

As stated, each one should be a function. Meaning the best way to implement the program is to loop through asking them to enter 1-6, and then use a switch/if statements in order to take them to the appropriate function.

Ideally, you can do something like this:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
int loop(int input)
{
	do
	{
		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;
		cin >> input;
	} while (input < 0 || input > 6);
	return input;
}

int main()
{
	int input;
	do
	{
		loop(input);

		switch (input)
		{
		case 1: //Call Function
			break;
		case 2: //Call Function
			break;
		case 3: //Call Function
			break;
		case 4: //Call Function
			break;
		case 5: //Call Function
			break;
                case 6:
                        break;
                default: 
                        std::cout << "Try Again!";
		}

	} while (input != 6);


	return 0;
}
Last edited on
closed account (367kGNh0)
‏‏‎
Last edited on
Rascake wrote:
As you seem new or un well spoken with switches, allow me to also advice you to, in future, use them and use the productively by nesting. Adding to @zapshe code.

[code][switch (input)
{
case 1: //Call Function
break;
case 2: //Call Function
break;
case 3: //Call Function
break;
case 4: //Call Function
break;
case 5: //Call Function
switch (var){

}/code]


What on earth????
Last edited on
closed account (367kGNh0)
Sorry, I just wanted to advise him to try switches. They simplify the job. I thank the admin for blankening my message completely, as clearly I am an awful c++ console programmer
Last edited on
Rascake wrote:
Sorry, I just wanted to advise him to try switches

Do you think it's reasonable (or even fair) for the blind to lead the blind?
Maybe you should learn the language first before you "help" others.
Intense wreckage.
closed account (367kGNh0)
Do you think it's reasonable (or even fair) for the blind to lead the blind?
Maybe you should learn the language first before you "help" others.
Exactly, I am an awful c++ console programmer, but I don't need to learn more, I know enough to work with my framework(Cocos), but yes, I should have not stepped in, I think I'm quarter eyed, not completely blind, and you called the OP blind, yes you have no knowledge of his reputation. We must stop derailing the topic aswell, that isn't very welcoming
Last edited on
Rascake wrote:
I am an awful c++ console programmer,


Rascke wrote:
and you called the OP blind, yes you have no knowledge of his reputation

Obviously I meant "beginners leading beginners" you braindead idiot. And obviously the OP is a beginner. And so are you. Less, really, since you don't even care. Pathetic.
Last edited on
closed account (367kGNh0)
It's not that I don't care but the cocos framework has no times you must add more OOP based code, so I didn't study it. What would be pathetic is studying something I would never use, when I could actually become knowledgable in a more critical aspect in the objection's software development, such as the framework I'm using,. What is more important, the language or the framework? Funny really, someone in the beginners section just in has an issue with a switch based implementation issue, hopefully I can learn from his assistance.

Last edited on
You are such a liar! Switches have nothing to do with OOP, What an idiot!!!
closed account (367kGNh0)
What, i did not say that, I thought you was referring to my general attempts in assisting around the forum, such as the recent discussing with the person who wanted to conjecustate a friend class, which I accidentally just re-explained how to call a friend class in instead. were derailing the post, your merely wasting your time and could be doing something far better than feeling better for being superior to another forum member, (not c++ programmer because that's not what I am, I really feel more like a cocos coder, it is based 100% on c++ but lacks it, yet I have made fairly stable games with it. but am not a c++ coder)
Last edited on
Blah blah blah. More lies. I'm just going to ignore you from now on.
Hello, @zapshe, I think you may have unintentionally skipped the posters ' requirement of saving all the data to "options.xml". I have never associated c++ code with the system files so I just mention this to inform you incase this was accidental, as an edit showing how would too be useful for myself :)
Last edited on
Hello, why hasn't the troll been banned, having read his reputation it should have occured long ago, is this an un-supervised forum?

Difference between trolling on purpose and being inconvenient by nature.

Hello, @zapshe, I think you may have unintentionally skipped the posters ' requirement of saving all the data to "options.xml". I have never associated c++ code with the system files so I just mention this to inform you incase this was accidental, as an edit showing how would too be useful for myself :)

options.txt - Simple use of the fstream library. If they need help with it I'm sure they'll post a reply, most of the post is just the requirements needed for the assignment. I saw a bigger issue with the code's logic.
Difference between trolling on purpose and being inconvenient by nature.
Anyone can change their ways if they force themselved to :)

Simple use of the fstream library
agreed, that is pretty much 101 for the fstream, but what if the file is moved? Can the code automatically adapt? And theory wise, if you directed an endless for loop,
1
2
3
4
5
6
7
for (int i=1;i>0;i++)
        {
            
                cout << "\n \n somehow 5mb text...";
            
            
        }

to a file. If done enough times could you, without difficulty, add a good few GB to your storage?
Last edited on
If done enough times could you, without difficulty, add a good few GB to your storage?

You'd have to loop it a lot, millions of times to reach a size in the MB, and almost a billion times to reach GB. Notepad also can't handle something that big.

And theory wise, if you directed an endless for loop, to a file.

Yea, best you don't do that. Takes a lot of CPU and when it eventually eats all your free space and tries to keep writing I assume it'll crash (or get shut down by the OS).

agreed, that is pretty much how I would usually do it, but what if the file is moved? Can the code automatically adapt?

You can make it so if it doesn't find it to look somewhere else. But if YOU as the programmer don't know where the file would be moved, then you can't really find it. Even professional applications aren't going to be able to handle things like that. They'll look for the files where they expect them to be, move something and it'll give you an error at startup most likely.
Topic archived. No new replies allowed.