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.