Reference no: EM13163649
programming assignment is to tweak the existing Mammal program and create your own Vehicle program.
sample program:
#include <iostream>
using namespace std;
enum BREED {YORKIE, GERMAN, DANDIE, SHETLAND, DOBERMAN, LAB};
class Mammal
{
public:
Mammal() :itsAge(2), itsWeight(5) {} // constructor
~Mammal(){} // destructor
// accessors
int GetAge() const {return itsAge;}
void SetAge(int age) {itsAge = age;}
int GetWeight() const {return itsWeight;}
void SetWeight(int weight) {itsWeight = weight;}
// other function members
void speak() const {cout << "Mammal sound!" << endl;}
void Sleep() const {cout << "shhh. I'm sleeping. " << endl;}
protected:
int itsAge;
int itsWeight;
};
class Dog : public Mammal
{
public:
Dog() : itsBreed(YORKIE){} // constructor
~Dog(){} // destructor // accessors
BREED GetBreed() const { return itsBreed;}
void SetBreed(BREED breed) {itsBreed = breed;}
int GetWeight() const {return itsWeight;}
void SetWeight(int weight) {itsWeight = weight;}
// other function members
void WagTail() const {cout << "Tail Wagging.. " << endl;}
void BegForFood() const {cout << " Begging for food " << endl;}
private:
BREED itsBreed;
};
void main()
{
Dog cooper;
cooper.speak();
cooper.WagTail();
cout << "cooper is " << cooper.GetAge() << " years old. " << endl;
}
//Sample Run:
//Mammal sound!
//Tail wagging...
//cooper is 2 years old
This is a program that declares a class Mammal.
Class Mammal has all the generic attributes and functions.
Class Dog, inherits from class Mammal
At the beginning of the program, I am using and enumeration that is simply assigning integers from 0 to whatever the last value is
For example in
enum BREED {YORKIE, GERMAN, DANDIE, SHETLAND, DOBERMAN, LAB};
YORKIE will grab the value of zero and LAB will have the value of 5
I have used inline functions for most of the member functions because it cuts down on the amount of code, you do not have to do that if inline functions are not your favorites.
Copy and paste the program into your IDE and run it, it should run with no errors.
Then I would like you to modify the program and instead of Mammal and Dog, create a base class Vehicle and then create a class car that inherits from the class Vehicle.
You can have weight of the car, brand, topspeed, number of cylinders (e.g. 4 cylinders, V6, V8) and so forth
I would declare it as below:
enum Engine_Type {zero,one,two,three,four,five,V6,seven,V8};
in the enum above, I would be interested in four, V6, and V8, because they will take the values of 4, 6, and 8 repectively.