In Visual Studio In Visual Studio In the code-behind for the web form, you will
ID: 3606216 • Letter: I
Question
In Visual Studio
In Visual Studio
In the code-behind for the web form, you will build a vehicle class that includes fields for: . make .model . year miles .vin In the vehicle class, you will also include a virtual function to calculate the wholesale value. (In vehicle, this will be a virtual function that does nothing). You will build a car class and a truck class that inherit from vehicle (a vehicle can be a car or a truck). The car class includes a field for indicating whether or not the car includes a "luxury package". The truck class includes a field for towing capacity (this might range from 1000 to 9000 pounds) The car and truck classes include a method that overrides the vehicle class virtual wholesale value method. For a car, the wholesale value is: $20,000, minus $100 per year of age, minus $1 per mile, plus $1000 if there is a luxury package The wholesale value of a truck is: $25,000, minus $1000 per year of age, minus $1.50 per mile plus $1000 if towing capacity is greater than 5000 lbs All of your classes will include an override of the System.Object ToString() method (the string returned should include the name of the class and other information that you think is helpful to the user)Explanation / Answer
#include <iostream>
using namespace std;
class vehicle
{
protected:
. int wheels;
double weight;
public:
void initialize(int input_wheels, double input_weight);
int get_wheels(void) {return wheels;}
. double get_weight(void) {return weight;}
double wheel_load(void) {return (weight/wheels);}
};
.
class car : public vehicle
{
int passenger_load;
public:
void initialize(int input_wheels, double input_weight, int people = 4);
int passengers(void)
{
return passenger_load;
}
};
class truck : public vehicle
{
int passenger_load;
double payload;
public:
void init_truck(int how_many = 4, double max_load = 24000.0);
double efficiency(void);
int passengers(void) {return passenger_load;}
};
int main()
{
vehicle unicycle;
unicycle.initialize(1, 12.5);
cout<<"Using base class, vehicle ";
cout<<"------------------------- ";
cout<<"The unicycle has " <<unicycle.get_wheels()<<" wheel. ";
cout<<"The unicycle's wheel loading is "<<unicycle.wheel_load()<<" kg on the
single tire. ";
cout<<"The unicycle weighs "<<unicycle.get_weight()<<" kg. ";
car sedan_car;
sedan_car.initialize(4, 3500.0, 5);
cout<<"Using derived class, car ";
cout<<"------------------------ ";
cout<<"The sedan car carries "<<sedan_car.passengers()<<" passengers. ";
cout<<"The sedan car weighs "<<sedan_car.get_weight()<<" kg. ";
cout<<"The sedan's car wheel loading is "<<sedan_car.wheel_load()<<" kg per
. tire. ";
truck trailer;
trailer.initialize(18, 12500.0);
trailer.init_truck(1, 33675.0);
cout<<"Using derived class, truck ";
cout<<"-------------------------- ";
cout<<"The trailer weighs "<< trailer.get_weight()<< " kg. ";
cout<<"The trailer's efficiency is "<<100.0 * trailer.efficiency()<<" %. ";
// system("pause");
return 0;
}
void vehicle::initialize(int input_wheels, double input_weight)
{
wheels = input_wheels;
weight = input_weight;
}
void car::initialize(int input_wheels, double input_weight, int people)
{
passenger_load = people;
wheels = input_wheels;
weight = input_weight;
}
void truck::init_truck(int how_many, double max_load)
{
passenger_load = how_many;
payload = max_load;
}
double truck::efficiency(void)
{
return payload / (payload + weight);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.