Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please i need help with this. Thanks so much! Objective: The objective of this h

ID: 3850634 • Letter: P

Question

Please i need help with this. Thanks so much!

Objective:

The objective of this homework is to create a set of subclasses and a base class.

Task 1:   Download the following files and view the demo-code from class.

Download the starter code here: https://github.com/fuzzpault/UIndy-CSCI156-2016-Summer/tree/master/Solutions-Starters/HW06-Vehicles
Type make to compile the vehicle-sandbox.cpp file.
Type make test to run the vehicle_test.cpp file.
Type make coverage to find the code coverage on your tests.

Look at the following code for hints on completing this assignment: https://github.com/fuzzpault/UIndy-CSCI156-2016-Summer/tree/master/Week06-Inheritance-Poly

Task 2:   Create a base class and sub-classes inside vehicle.h.

Create a vehicle.h file.

Your task is to create 4 classes, Bike, Car, Truck, Airplane.   It is your job to choose appropriate types for all variables. Each class below should have it’s own constructor which specifies all parameters.

You MUST create a base class (Vehicle is a good name) to make your life easier!

Here are the specifications for the classes:

Bike class:

getColor, setColor - stored as a string.

getPrice - Returns a float. A new bike is $1000, and it depreciates 100 per year, down to 0.

1 passenger only

2 wheels

getYear, setYear - stored as an int. Year built. Use the current year if the given value is in the future.

print - Returns a string of the details of the vehicle.

Car class:

getColor, setColor - stored as a string.

getPrice - Returns a float. $5,000 per passenger, minus 500 depreciation per year, down to 100. +200 if it has air-conditioning. +100 if it has a DVD player.

getPassengers, setPassengers - 1 to 10 passengers.

getYear, setYear - stored as an int. Year built. Use the current year if the given value is in the future.

getAir, setAir - Bool if the car has air-conditioning.

getDVD, setDVD - Bool if the car has a DVD player

4 wheels

print - Returns a string of the details of the vehicle.

Truck class:

getColor, setColor - stored as a string.

getPrice - Returns a float. $10,000 base price, plus $1,000 per passenger, minus 500 depreciation per year, down to 200. $1.25 per carrying capability lb, $200 per wheel.

getPassengers, setPassengers - 1 to 4 passengers.

getYear, setYear - stored as an int. Year built. Use the current year if the given value is in the future.

getCap, setCap - Int for the lb it can carry, up to 20,000.

getWheels, setWheels - 4 - 16 wheels, integer, must be even

print - Returns a string of the details of the vehicle.

Airplane class:

getColor, setColor - stored as a string.

getPrice - Returns a float. $15,000 base price, plus $1,000 per passenger, minus 500 depreciation per year, down to1000. $5.25 per carrying capability lb, $100 per prop.

getPassengers, setPassengers - 1 to 40 passengers.

getYear, setYear - stored as an int. Year built. Use the current year if the given value is in the future.

getCap, setCap - Int for the lb it can carry, up to 20,000.

getProps, setProps - 1+, integer

print - Returns a string of the details of the vehicle.

If a vehicle has a set value (a bike only has 2 wheels), the setter exists but shouldn’t do anything.
All classes should only have a default constructor, you may have others, but they aren’t required.
All variables must be private or protected.
Use 2017 as the current year. (This is a constant at the top of vehicle.h)
If a value is provided which is outside the allowed values (10000 passengers), don’t do anything.

Task 3:   Write at least 20 unit tests in vehicle_test.cpp for all functionality. Your goal is to have 100% coverage (90% for full credit).

Explanation / Answer

C++ CODE:

#include <iostream>
#include <string>

using namespace std;
class Vehicle{
  
protected:
const int currentYear=2017;
string color;
float basePrice;
int year;
int passenger;
int wheel;

  
public:
Vehicle(string color,float basePrice,int year,int passenger,int wheel){
this->color=color;
this->basePrice=basePrice;
this->year=year;
this->passenger=passenger;
this->wheel=wheel;
}
  
void setColor(string color){
this->color=color;
}
string getColor(){
return color;
}
  
void setPrice(float price){
this->basePrice=price;
}
  
virtual float getPrice()=0;
  
void setYear(int year){
this->year=year;
}
  
int getYear(){
return year;
}
void setWheel(){
this->wheel=wheel;
}
int getWheel(){
return wheel;
}
  
  
  
virtual void print(){
cout << "Color: " << color << endl;
cout << "basePrice: " <<basePrice<< endl;
cout << "Build: " << year<< endl;
cout << "Passengers Allowed: " << passenger << endl;
cout << "Wheels: " << wheel << endl;
  
}
  
};

class Bike: public Vehicle{
private:
float depreciationPerYear;
  
public:
  
Bike(string color,float basePrice,int year,int passengers,int wheels,float depreciation) : Vehicle(color,basePrice,year,passengers,wheels){
  
depreciationPerYear = depreciation;
  
}
  
  
void setDepreciation(float price){
depreciationPerYear=price;
}
  
float getDepreciation(){
return depreciationPerYear;
}
  
float getPrice(){
if(year<=currentYear ){
int price=basePrice-((currentYear-year)*depreciationPerYear);
if(price>=0)
return price;
else
return 0.0;
}
}
  
void print(){
Vehicle::print();
cout<<"depreciation Per Year:"<<depreciationPerYear<<endl;
cout<<"2017 Price:"<<getPrice()<<endl;
}
  
};

class Car: public Vehicle{
private:
float depreciationPerYear;
bool air;
bool dvd;
  
public:
  
Car(string color,float basePrice,int year,int passengers,int wheels,float depreciation,bool air,bool dvd) : Vehicle(color,basePrice,year,passengers,wheels){
  
depreciationPerYear = depreciation;
this->air=air;
this->dvd=dvd;
  
}
  
  
void setDepreciation(float price){
depreciationPerYear=price;
}
  
float getDepreciation(){
return depreciationPerYear;
}
  
float getPrice(){
if(year<=currentYear ){
int price=basePrice-((currentYear-year)*depreciationPerYear);
if(air)
price+=200;
if(dvd)
price+=100;
  
if(price>=100)
return price;
else
return 100;
}
}
  
void print(){
Vehicle::print();
cout<<"depreciation Per Year:"<<depreciationPerYear<<endl;
cout<<"Has air conditioning:"<<air<<endl;
cout<<"Has dvd:"<<dvd<<endl;
cout<<"2017 Price:"<<getPrice()<<endl;
}
  
};
class Truck: public Vehicle{
private:
float depreciationPerYear;
int capacity;
  
public:
  
Truck(string color,float basePrice,int year,int passengers,int wheels,float depreciation,int capacity) : Vehicle(color,basePrice,year,passengers,wheels){
  
depreciationPerYear = depreciation;
this->capacity=capacity;
  
}
  
  
void setDepreciation(float price){
depreciationPerYear=price;
}
  
float getDepreciation(){
return depreciationPerYear;
}
  
float getPrice(){
if(year<=currentYear ){
int price=basePrice-((currentYear-year)*depreciationPerYear);
  
price+=passenger*1000;
price+=capacity*1.25;
price+=wheel*200;


if(price>=200)
return price;
else
return 200;
}
}
  
void print(){
Vehicle::print();
cout<<"depreciation Per Year:"<<depreciationPerYear<<endl;
cout<<"capacity:"<<capacity<<endl;
cout<<"2017 Price:"<<getPrice()<<endl;
}
  
};

class Airplane: public Vehicle{
private:
float depreciationPerYear;
int capacity;
int props;
  
public:
  
Airplane(string color,float basePrice,int year,int passengers,int wheels,float depreciation,int capacity,int props) : Vehicle(color,basePrice,year,passengers,wheels){
  
depreciationPerYear = depreciation;
this->capacity=capacity;
this->props=props;
}
  
  
void setDepreciation(float price){
depreciationPerYear=price;
}
  
float getDepreciation(){
return depreciationPerYear;
}
  
float getPrice(){
if(year<=currentYear ){
int price=basePrice-((currentYear-year)*depreciationPerYear);
  
price+=passenger*1000;
price+=capacity*5.25;
price+=props*100;


if(price>=1000)
return price;
else
return 1000;
}
}
  
void print(){
Vehicle::print();
cout<<"depreciation Per Year:"<<depreciationPerYear<<endl;
cout<<"capacity:"<<capacity<<endl;
cout<<"Props:"<<props<<endl;
cout<<"2017 Price:"<<getPrice()<<endl;
}
  
};

int main()
{
Bike bike("red",1000,2006,1,2,100);
bike.print();
Car car("blue",2000,2009,6,4,200,true,false);
cout<<endl;
car.print();
Truck truck("red",2000,2009,6,4,200,500);
cout<<endl;
truck.print();
Airplane plane("white",2000,2009,6,4,200,500,1);
cout<<endl;
plane.print();
return 0;
}