Classes and Arrays

I have a class assignment that involves creating a class and I have no clue how to do it! Here is my assignment,

Create a program that creates and stores cars in inventory for our Automotive Service Shop.

Create a Car class to store car information

Attributes:

make (you can also think of this as the Manufacturer)

model

color

year

mileage

(Note: All attributes should be private.)

Behaviors:

1. Create mutator (Set) and accessor (Get) functions for all attributes of this class.

2. Create a default constructor that initializes all of the attributes to default values (blanks in the case of strings or 0 in the case of numbers.)

3. Make sure to have validation to ensure that the mileage is never set to a number less than 0.

4. Create a constructor that takes the make, model, year, color, and mileage values and sets them for a newly created car.

5. Create another function called car_details that prints all of the attributes of the car in an attractive format.

(Example on an output line of a cars details:

"The current car is a 2008 Red Ford Mustang with 5000 miles.")




Here is what I have so far, please advise me on how to fix this the way the assignment says. I did the program my way first because I did not pay attention to the fact that I would need it for the second program.



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef Car_Class
#define Car_Class
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <cctype>
using namespace std;


	//Class Declaration
	class Car
	{
		private:
			string make;  //make
			string	model; // model
			string	color;  // color 
			string liscensePlate;  // liscense plate number
			int	year;  // year
			int mileage;  // miles on car

		public:
			Car(); //constructor
			GetDetails(); // Second Constructor
			string getMake;
			string getModel;
			string getColor;
			string getLiscensePlate;
			int getYear;
			int getMileage;
			void printCarDetails();
			void CarDetails ( string, string, string, string, int, int);

	};
#endif


	// Constructor to initialize each object to always start the same way
	Car::Car()
	{
		make = ""; 
		model = ""; 
		color = "";   
		liscensePlate = "";  
		year = 0;
		mileage = 0;
	}
	
	Car::GetDetails()
	{

	
int main()
{	

		string make;  //make
		string	model; // model
		string	color;  // color 
		string liscensePlate;  // liscense plate number
		int	year;  // year
		int mileage;  // miles on car


	cout << "What is the car make? " ;
	cin >> make;
	cout << "What the car model? " ;
	cin >> model;
	cout << "What year is the car? " ;
	cin >> year;
	cout << "What color is the car? " ;
	cin >> color;
	cout << "What is the liscense plate number? " ;
	cin >> liscensePlate;
	cout << "How many miles does the car have on it? " ;
	cin >> mileage;
	while (mileage < 0 )
	{	
		cout << " This is not a valid mileage.\n";
		cout << " Enter the miles for this car: " ;
		cin >> mileage;
	}
	
	cout << "The current car is a " << year << " " << color << " " << model << " with " << mileage << " miles!  And the Liscense Plate number is " << liscensePlate << endl; 

return 0;			
}






Once I am done with this assignment I have to get it to work in this assignment
.


Create a program with a main() that uses the car class. It is going to store a set of cars for the user in an array. Write a program that creates an array of 5 cars, each car in the array is a car in a service bay at this Automotive Service Store.

Go ahead and create all 5 cars in the array using the default constructor.

Have the following menu for the user to work with:

1. Choose Service Bay (1-5)

2. Change make of car in the current Service Bay

3. Change model of car in the current Service Bay

4. Change color of car in the current Service Bay

5. Change year of car in the current Service Bay

6. Change mileage of car in the current Service Bay

7. Display car in current service bay

8. Save

9. Exit

Place this menu in a loop like you used for the review for week 1. When the user enters 9 it should end the loop and the program.

Have the other choices by the user do the following.

1. Should change the value of an integer you are using to show the current position in the array of cars the user is working with. Prompt the user for a value and store 0-4 (whatever number the user gives you…subtract 1 from it because arrays start at 0.)

2. Have this option display the make of the car in the current service bay for the user using the accessor function. Then prompt the user for the new value of the car. Use the mutator function

Example of output:

The make of the car in the current service bay is Ford.

Please Enter the change to the make of the car: Ferrarri

(The value of the make of the car in the current place in the array is now Ferrarri.)

3. Have this option display the model of the car in the current service bay for the user using the accessor function. Then prompt the user for the new value of the car. Use the mutator function. (This is the same as 2., except changing the model.)

4. Have this option display the color of the car in the current service bay for the user using the color function. Then prompt the user for the new value of the car. Use the mutator function. (This is the same as 2., except changing the model.)

5. Have this option display the year of the car in the current service bay for the user using the year function. Then prompt the user for the new value of the car. Use the mutator function. (This is the same as 2., except changing the model.)

6. Have this option display the mileage of the car in the current service bay for the user using the mileage function. Then prompt the user for the new value of the car. Use the mutator function. (This is the same as 2., except changing the model.)

7. Have this option call the car_details function for the current car. (Which will display the details of the car for the user.)

8. Have this option write all of the data for each car in the array to a data file. (Open a data file as you know how to do, and then use a loop and loop through all 5 positions in the array and write each of the attributes of each car using its set functions to the data file and then close it.)

9. This option will end the program.

just to get you started..
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <string>
using namespace std;
class Car {
private:
    string make;  //make
    string model; // model
    string color;  // color
    int	year;  // year
    int mileage;  // miles on car

public:
    Car(); //constructor
    Car(string, string, string, int ,int);

    void setMake(string);
    void setModel(string);
    void setColor(string);
    void setYear(int);
    void setMileage(int);

    string getMake();
    string getModel();
    string getColor();
    int getYear();
    int getMileage();

    void valid_mileage(int);
    void car_details();
};

int main() {
    Car myCar("Ford", "Mustang", "Blue", 2010, 7500);
    myCar.car_details();
    return 0;
}
//----------------------------------------------------------------
//class definition..
Car::Car() {
    make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;
}

Car::Car(string make, string model, string color, int year, int mileage) {
    Car::make =  make;
    Car::model = model;
    Car::color = color;
    Car::year = year;
    valid_mileage(mileage);
}

void Car::setMake(string make) {
    Car::make = make;
}

void Car::setModel(string model) {
    Car::model = model;
}

void Car::setColor(string color) {
    Car::color = color;
}

void Car::setYear(int year) {
    Car::year = year;
}

void Car::setMileage(int mileage) {
    valid_mileage(mileage);
}

string Car::getMake() {
    return make;
}
string Car::getModel() {
    return model;
}
string Car::getColor() {
    return color;
}
int Car::getYear() {
    return year;
}
int Car::getMileage() {
    return mileage;
}

void Car::valid_mileage(int mileage) {
    if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "Warning! Not a valid mileage!\n";
    }
}

void Car::car_details() {
    cout << "The current car is a " << year << ' ' << color << ' '
    << make << " with " << mileage << " miles..\n";
}
Last edited on
Wow thanks, if I am correct that is the entire first part right????


Now for my second program I should be able to take that and then add 4 more cars and then my menu and the stuff that the menu does and I should be good correct?
Last edited on
i updated my code above.. now it does the entire first part..
We always discuss the conditional (aka tenary) operator from time to time.. so you could always write this:
1
2
3
4
5
6
7
8
9
10
void Car::valid_mileage(int mileage) {
    
  Car::mileage = mileage >=0? mileage:(cout << "Warning! Not a valid mileage!\n",0);
  /*if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "Warning! Not a valid mileage!\n";
    }*/
}
i prefer if else.. is only use ?: operator if in only need evaluating values, in this case we are printing a string..
what?
Last edited on
forget it..
Ok this is what I have so far.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <string>
using namespace std;
class Car {
private:
    string make;  //make
    string model; // model
    string color;  // color
    int	year;  // year
    int mileage;  // miles on car
	int service;

public:
    Car(); //constructor
    Car(string, string, string, int ,int, int);

    void setMake(string);
    void setModel(string);
    void setColor(string);
    void setYear(int);
    void setMileage(int);
	void setService(int);
	

    string getMake();
    string getModel();
    string getColor();
    int getYear();
    int getMileage();
	int getService();

    void valid_mileage(int);
    void car_details1();
	void car_details2();
	void car_details3();
	void car_details4();
	void car_details5();
};


//----------------------------------------------------------------
//class definition..
Car::Car() {
    make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;

}

Car::Car(string make, string model, string color, int year, int mileage, int service) {
    Car::make =  make;
    Car::model = model;
    Car::color = color;
    Car::year = year;
    valid_mileage(mileage);
	Car::service = service;
}

void Car::setMake(string make) {
    Car::make = make;
}

void Car::setModel(string model) {
    Car::model = model;
}

void Car::setColor(string color) {
    Car::color = color;
}

void Car::setYear(int year) {
    Car::year = year;
}

void Car::setMileage(int mileage) {
    valid_mileage(mileage);
}

void Car::setService(int service) {
	Car::service = service;
}

string Car::getMake() {
    return make;
}
string Car::getModel() {
    return model;
}
string Car::getColor() {
    return color;
}
int Car::getYear() {
    return year;
}
int Car::getMileage() {
    return mileage;
}
int Car::getService() {
    return service;
}

void Car::valid_mileage(int mileage) {
    if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "Warning! Not a valid mileage!\n";
    }
}

void Car::car_details1() {
    cout << "The current car is a " << year << ' ' << color << ' '
    << make << " with " << mileage << " miles," << " and it is in service bay" << service << "  .\n";
}

int main() {


    Car myCar("Ford", "Mustang", "Blue", 2010, 7500, 1);
    myCar.car_details1();
    Car myCar("Toyota", "Tacoma", "White", 1996, 107000, 2);
    myCar.car_details2();
    Car myCar("Nissan", "Altima", "Blue", 2007, 4210, 3);
    myCar.car_details3();
    Car myCar("Honda", "Accord", "Blue", 1999, 97500, 4);
    myCar.car_details4();
    Car myCar("Jeep", "Wrangler", "Blue", 2001, 85000, 5);
    myCar.car_details5();


    
	
	
	return 0;
}


Now how will I do the menu part. For instance the very first menu option is choose a service bay(1-5). So once it chooses service bay 1, I should then be able to edit the car information for that service bay based on the next option I choose.
Last edited on
Please guys I need help asap!

here is my menu I have so far and it will not work

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
46
47
48
49
50
51
52
53
54
	cout << "Car Menu\n\n";			//Menu 
	cout << "1. Choose Service Bay (1-5)\n";
	cout << "2. Change Make of car in the Current Service Bay\n";
	cout << "3. Change Model of car in th current Service Bay\n";
	cout << "4. Change Color of car in the Current Service Bay\n";
	cout << "5. Change Year of car in the Current Service Bay\n";
	cout << "6. Change Mileageof car in the Current Service Bay\n";
	cout << "7. Display Car in Current Service Bay\n";
	cout << "8. Save\n";
	cout << "9. Exit\n\n\n";
	cout << "Please choose one of the above options\n\n";
    cin >> menuSelection;
	while(menuSelection!=9);//keep on keepin on till they pick exit!

				switch ( menuSelection )
			{
				case 1: 
					{
						if (menuSelection = 1);
							cout << " Pick a service Bay (1-5) to edit\n";
							cin >> Car::getService;
					}

						break;
				case 2: 
						
						break;
				case 3: 
						
						break;
				case 4:
						
						break;

				case 5: 
						
						break;
				case 6: 
						
						break;
				case 7: 
						
						break;
				case 8:
						
						break;
				case 9:
						;
						break;
				default:
					cout << " Please restart the program, you have messed up!!!!"; 
						break;

			}


and this is right after the myCar.car_details5(); in the previous line!
Thanks,


Here is new code and errors.


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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>

using namespace std;
ofstream out;

class Car {
private:
	string make;  //make
	string model; // model
	string color;  // color
	int bay;	//bay number
	int	year;  // year
	int mileage;  // miles on car



public:
	Car(); //constructor
	Car(string, string, string, int ,int, int);

	void setMake(string);
	void setModel(string);
	void setColor(string);
	void setYear(int);
	void setMileage(int);

	

	string getMake();
	string getModel();
	string getColor();
	int getYear();
	int getMileage();


	void valid_mileage(int);
	void car_details();

};


//----------------------------------------------------------------
//class definition..
Car::Car() {
	make = " ";
	model = " ";
	color = " ";
	year = 0;
	mileage = 0;

}

Car::Car(string make, string model, string color, int year, int mileage, int service) {
	Car::make =  make;
	Car::model = model;
	Car::color = color;
	Car::year = year;
	valid_mileage(mileage);

}

void Car::setMake(string make) {
	Car::make = make;
}

void Car::setModel(string model) {
	Car::model = model;
}

void Car::setColor(string color) {
	Car::color = color;
}

void Car::setYear(int year) {
	Car::year = year;
}

void Car::setMileage(int mileage) {
	valid_mileage(mileage);
}


string Car::getMake() {
	return make;
}
string Car::getModel() {
	return model;
}
string Car::getColor() {
	return color;
}
int Car::getYear() {
	return year;
}
int Car::getMileage() {
	return mileage;
}

void Car::valid_mileage(int mileage) {
	if (mileage>=0)
		Car::mileage=mileage;
	else {
		Car::mileage=0;
		cout << "Warning! Not a valid mileage!\n";
	}
}



int main() {




	int i;
	const int	 NUM_COLS = 5,
					NUM_ROWS = 5;

	double bay[NUM_ROWS][NUM_COLS] =			 {{"Ford", "Mustang", "Blue", 2010, 7500},
												{"Toyota", "Tacoma", "White", 1996, 107000},
												{"Nissan", "Altima", "Blue", 2007, 4210},
												{"Honda", "Accord", "Blue", 1999, 97500},
												{"Jeep", "Wrangler", "Blue", 2001, 85000}};
	int menu;

			
	
	cout << "Car Menu\n\n";			//Menu 
	cout << "1. Choose Service Bay (1-5)\n";
	cout << "2. Change Make of car in the Current Service Bay\n";
	cout << "3. Change Model of car in th current Service Bay\n";
	cout << "4. Change Color of car in the Current Service Bay\n";
	cout << "5. Change Year of car in the Current Service Bay\n";
	cout << "6. Change Mileageof car in the Current Service Bay\n";
	cout << "7. Display Car in Current Service Bay\n";
	cout << "8. Save\n";
	cout << "9. Exit\n\n\n";
	cout << "Please choose one of the above options\n";
	cin >> menu;
	while(menu!=9);//keep on keepin on till they pick exit!

				switch ( menu )
			{
				case 1: 
					
							cout << " Pick a service Bay (1-5) to edit\n";
							cin >> bay;
					

						break;
				case 2: 
						
					
						cout << " The Make of car in the current service bay is:" << make << endl;
						cout << " Please Enter the change to the make of the car:";
						cin >> make;
					

						break;
				case 3: 
						
					
						cout << " The Model of car in the current service bay is:" << make << endl;
						cout << " Please Enter the change to the model of the car:";
						cin >> model;
					
						break;
				case 4:
					
						cout << " The Color of car in the current service bay is:" << make << endl;
						cout << " Please Enter the change to the color of the car:";
						cin >> color;
					
						
						break;

				case 5: 
					
						cout << " The Year of car in the current service bay is:" << make << endl;
						cout << " Please Enter the change to the year of the car:";
						cin >> year;
					
						
						break;
				case 6: 
					
						cout << " The Mileage of car in the current service bay is:" << make << endl;
						cout << " Please Enter the change to the mileage of the car:";
						cin >> mileage;
					
						
						break;
				case 7: 
						void Car::car_details() {
						cout << "The current car is a " << year << ' ' << color << ' '
						<< make << " with " << mileage << " miles.\n";
						}
						break;
				case 8:
					  out.open("car.txt"); // opens the file
					   if( !out ) { // file couldn't be opened
						  cerr << "Error: file could not be opened" << endl;
						  exit(1);
					   }

					  for (i=0; i<5; ++i)
						  out << num[i] << endl;
					   out.close();

						break;

				default:
					cout << " Please restart the program, you have messed up!!!!"; 
						break;

			}

			

	
	return 0;
}


Last edited on
And here are the errors

Errors


1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1> test.cpp
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(125): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(125): error C2440: 'initializing' : cannot convert from 'const char [8]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(125): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(126): error C2440: 'initializing' : cannot convert from 'const char [7]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(126): error C2440: 'initializing' : cannot convert from 'const char [7]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(126): error C2440: 'initializing' : cannot convert from 'const char [6]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(127): error C2440: 'initializing' : cannot convert from 'const char [7]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(127): error C2440: 'initializing' : cannot convert from 'const char [7]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(127): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(128): error C2440: 'initializing' : cannot convert from 'const char [6]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(128): error C2440: 'initializing' : cannot convert from 'const char [7]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(128): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(129): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(129): error C2440: 'initializing' : cannot convert from 'const char [9]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\justin puckett\documents\my stuff\school work\second semester\spring 2009\c++\week 1 menu driven, file pulling\test\test\test.cpp(129): error C2440: 'initializing' : cannot convert from 'const char [5]' to 'double'
1> There is no context in which this conversion is possible
cars.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

class Car {
private:
    string make;  //make
    string model; // model
    string color;  // color
    int bay;	//bay number
    int	year;  // year
    int mileage;  // miles on car

public:
    Car(); //constructor
    Car(string, string, string, int ,int, int);
    void setMake(string);
    void setModel(string);
    void setColor(string);
    void setYear(int);
    void setMileage(int);

    string getMake();
    string getModel();
    string getColor();
    int getYear();
    int getMileage();

    void valid_mileage(int);
    void car_details();
    string string_car_details();
};




//-----------------------------------------------------------------------------
//class definition..
Car::Car() {
    make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;
}

Car::Car(string make, string model, string color, int year, int mileage, int service) {
    Car::make =  make;
    Car::model = model;
    Car::color = color;
    Car::year = year;
    valid_mileage(mileage);
}

void Car::setMake(string make) {
    Car::make = make;
}

void Car::setModel(string model) {
    Car::model = model;
}

void Car::setColor(string color) {
    Car::color = color;
}

void Car::setYear(int year) {
    Car::year = year;
}

void Car::setMileage(int mileage) {
    valid_mileage(mileage);
}


string Car::getMake() {
    return make;
}
string Car::getModel() {
    return model;
}
string Car::getColor() {
    return color;
}
int Car::getYear() {
    return year;
}
int Car::getMileage() {
    return mileage;
}

void Car::valid_mileage(int mileage) {
    if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "Warning! Not a valid mileage!\n";
    }
}

void Car::car_details() {
    cout << "The current car is a " << year << ' ' << color << ' '
    << make << " with " << mileage << " miles..\n";
}

string Car::string_car_details() {
    stringstream buf;
    buf << "The current car is a " << year << ' ' << color << ' '
    << make << " with " << mileage << " miles..\n";
    return buf.str();
}
//============================================================================== 


cars.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "cars.h"
using namespace std;

int main() {
    int menu=0, current_car=0, tmpInt=0;
    string temp;
    Car myCars[5];

    while (menu!=9) {//keep on keepin on till they pick exit!
        cout << "Car Menu\n\n";			//Menu
        cout << "1. Choose Service Bay (1-5)\n";
        cout << "2. Change Make of car in the Current Service Bay\n";
        cout << "3. Change Model of car in th current Service Bay\n";
        cout << "4. Change Color of car in the Current Service Bay\n";
        cout << "5. Change Year of car in the Current Service Bay\n";
        cout << "6. Change Mileageof car in the Current Service Bay\n";
        cout << "7. Display Car in Current Service Bay\n";
        cout << "8. Save\n";
        cout << "9. Exit\n\n\n";
        cout << "Please choose one of the above options: ";
        cin >> menu;
        cin.ignore();
        cout << "_______________________________________________________\n";

        switch ( menu ) {
        case 1:
            cout << " Pick a service Bay (1-5) to edit\n";
            cin >> current_car;
            --current_car;
            cin.ignore();
            cout << "_______________________________________________________\n";
            break;

        case 2:
            cout << " The Make of car in the current service bay is: "
            << myCars[current_car].getMake() << endl;
            cout << " Please Enter the change to the make of the car: ";
            getline(cin, temp);
            myCars[current_car].setMake(temp);
            cout << "_______________________________________________________\n";
            break;

        case 3:
            cout << " The Model of car in the current service bay is: "
            << myCars[current_car].getModel() << endl;
            cout << " Please Enter the change to the model of the car: ";
            getline(cin, temp);
            myCars[current_car].setModel(temp);
            cout << "_______________________________________________________\n";
            break;

        case 4:
            cout << " The Color of car in the current service bay is: "
            << myCars[current_car].getColor() << endl;
            cout << " Please Enter the change to the color of the car: ";
            getline(cin, temp);
            myCars[current_car].setColor(temp);
            cout << "_______________________________________________________\n";
            break;

        case 5:
            cout << " The Year of car in the current service bay is: "
            << myCars[current_car].getYear() << endl;
            cout << " Please Enter the change to the year of the car: ";
            cin >> tmpInt;
            myCars[current_car].setYear(tmpInt);
            cin.ignore();
            cout << "_______________________________________________________\n";
            break;

        case 6:
            cout << " The Mileage of car in the current service bay is: "
            << myCars[current_car].getMileage() << endl;
            cout << " Please Enter the change to the mileage of the car: ";
            cin >> tmpInt;
            myCars[current_car].setMileage(tmpInt);
            cin.ignore();
            cout << "_______________________________________________________\n";
            break;

        case 7:
            myCars[current_car].car_details();
            cout << "_______________________________________________________\n";
            break;

        case 8:
            {
            ofstream file("Car.txt");
            if(!file.is_open()) {
                cout << "Error! Can not open file..\n\n";
                return 1;
            }
            for(int x=0; x<5; x++)
                file << myCars[x].string_car_details();
            file.close();
            }
            cout << "File Save! ! !\n";
            cout << "_______________________________________________________\n";
            break;

        default:
            cout << " Please restart the program, you have messed up!!!!";
            cout << "_______________________________________________________\n";
            break;
        }//switch
    }//while
    return 0;
}
how far into the class are you?
lmao @ this post.... ur fucked....

I might do this on my own, I think.
Last edited on
what?
what?


nvm....
Topic archived. No new replies allowed.