Hey guys, I really appreciate everything that you do for me and it really helps me a lot...I have learned so much. But I have a new problem, for my assignment this week it deals with InHeritance and Pointers and I have 90% of my program set up but I need help with the last 10% of it.
Here is my assignment and I have bold the section that I need help with!
Create a Vehicle class to store information
Attributes:
make (you can also think of this as the Manufacturer)
model
color
year
mileage
(Note: All attributes should not be public.)
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 vehicle.
5. Create a virtual function called details that does not do anything. (This will force the cars, trucks, and motorcycles that inherit from this class to overload this function.)
Create a Car class that inherits from the vehicle class
Attributes:
There are no additional attributes
Behaviors:
1. Override the details function to print the details for this car.
2. (Example on an output line of a car’s details:
“The current car is a 2008 Red Ford Mustang with 5000 miles.”)
Create a Truck class that inherits from the vehicle class
Attributes:
bedsize
Behaviors:
1. Create mutator (Set) and accessor (Get) functions for all attributes of this class.
2. Override the details function to print the details for this truck.
(Example on an output line of a truck’s details:
“The current truck is a 2006 Black Ford F150 with 10000 miles and a 10-foot bedsize.”)
Create a Motorcycle class that inherits from the vehicle class
Attributes:
Biketype
Note: (Some types of bikes would be chopper, cruiser, dirt bike, touring, and custom. )
Behaviors:
1. Create mutator (Set) and accessor (Get) functions for all attributes of this class.
2. Override the details function to print the details for this motorcycle.
(Example on an output line of a motorcycle’s details:
“The current motorcycle is a 2007 Silver Harley Cherokee chopper with 8000 miles”)
Create a program with a main() to be used by the inventory manager to keep track of all of the vehicles on the lot.
1) Create the following vehicles of the correct type
Make Model Color Year Type Bed size Bike type
1. Porsche 911 Silver 2005 Car
2. Ford Mustang Red 2007 Car
3. Kawasaki Ninja Black 2004 Motorcycle custom
4. Ford F150 White 2007 Truck 10-foot
5. Voltzwagon Jetta Black 2006 Car
6. Harley Cherokee Silver 2000 Motorcycle chopper
7. Toyota Tacoma Blue 2002 Truck 12-foot
8. Honda CBR1500CC Red 2008 Motorcycle cruiser
9. <<Your dream vehicle here>>
2) Prompt the user to change:
a. The model of one car.
b. The bed size of one truck.
c. The bike type for one motorcycle.
d. The year of any one vehicle (you choose the type).
3) Create and array of pointers to these objects and use a loop to call the details() function for each one in turn and print out the details for all vehicles on the lot.
And here is my current code!
Vehicle.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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#ifndef VEHICLE_H
#define VEHICLE_H
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
//Vehicle Class
class Vehicle {
protected:
Vehicle myVehicle[9];
string make; //make
string model; // model
string color; // color
int year; // year
int mileage; // miles on car
string type; //Type of vehicle
public:
//Constructor that will set information for a new car
void New_vehicle (string a, string b, string c, int d, int e)
{make = a; model = b; color = c; year = d; mileage = e;}
Vehicle(); //Default constructor
Vehicle(string, string, string, int, int, string);
//mutator and accessor functions
void setMake(string);
void setModel(string);
void setColor(string);
void setYear(int);
void setMileage(int);
void setType(string);
string getMake();
string getModel();
string getColor();
int getYear();
int getMileage();
string getType();
//Check mileage to see if valid
void valid_mileage(int);
//virtual function
virtual void details() {
}
};
//Sets to default values
Vehicle::Vehicle() {
make = " ";
model = " ";
color = " ";
year = 0;
mileage = 0;
type = " ";
}
Vehicle::Vehicle(string make, string model, string color, int year, int mileage, string type) {
Vehicle::make = make;
Vehicle::model = model;
Vehicle::color = color;
Vehicle::year = year;
valid_mileage(mileage);
Vehicle::type = type;
}
void Vehicle::setMake(string make) {
Vehicle::make = make;
}
void Vehicle::setModel(string model) {
Vehicle::model = model;
}
void Vehicle::setColor(string color) {
Vehicle::color = color;
}
void Vehicle::setYear(int year) {
Vehicle::year = year;
}
void Vehicle::setMileage(int mileage) {
valid_mileage(mileage);
}
void Vehicle::setType(string type) {
Vehicle::type = type;
}
string Vehicle::getMake() {
return make;
}
string Vehicle::getModel() {
return model;
}
string Vehicle::getColor() {
return color;
}
int Vehicle::getYear() {
return year;
}
int Vehicle::getMileage() {
return mileage;
}
string Vehicle::getType() {
return type;
}
void Vehicle::valid_mileage(int mileage) {
if (mileage>=0)
Vehicle::mileage=mileage;
else {
Vehicle::mileage=0;
cout << "WARNING! You have entered invalid mileage!\n";
}
Vehicle& getVehicle(int n) {
return myVehicle[n];
}
};
#endif
|
Car.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#ifndef CAR_H
#define CAR_H
#include "Vehicle.h"
//Car class that inherits from the vehicle class
class Car:public Vehicle
{
private:
//There are no new attributes
public:
void details() {
cout << "The current car is a " << year << ' ' << color << ' '
<< make << ' ' << model << " with " << mileage << " miles.\n";
}
};
#endif
|
Truck.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
|
#ifndef TRUCK_H
#define TRUCK_H
#include "Vehicle.h"
//Truck class that inherits from the vehicle class
class Truck:public Vehicle
{
private:
int bedsize; //BedSize
public:
Truck(); //constructor
Truck(int);
//mutator and accessor functions
void setBedsize(int);
int getBedsize();
};
Truck::Truck() {
bedsize = 0;
}
Truck::Truck(int bedsize) {
Truck::bedsize = bedsize;
}
void Truck::setBedsize(int bedsize) {
Truck::bedsize = bedsize;
}
int Truck::getBedsize() {
return bedsize;
}
void details() {
cout << "The current truck is a " << year << ' ' << color << ' '
<< make << ' ' << model << " with " << mileage << " miles and a " << bedsize << "-foot bedsize.\n";
}
};
#endif
|