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

Write a program in C++ that implements the ADT vehicle (a class with at least on

ID: 3824609 • Letter: W

Question

Write a program in C++ that implements the ADT vehicle (a class with at least one pure virtual function). Information you may want to keep about a vehicle includes

·       identification information

·       empty weight

·       maximum gross weight

·       maximum range

·       maximum speed

The constructor should take all such information as arguments. Include virtual functions (may be pure or impure) for interrogating each such attribute. Also include a pure virtual function for interrogating the transportation mode.

Construct derived classes airplane, boat, and car each derived directly from vehicle. Each derived class should provide an interrogation function for the transportation mode, which should indicate by-air, by-land, or by-water (or something similar).

Write a short program which instantiates at least one object of each derived type. Verify all operations work correctly.

Explanation / Answer

#include <iostream>
#include<string>

using namespace std;
class vehicle
{
public:
   string id_number;
   float max_gross_weight;
   float max_range;
   float max_speed;
   vehicle()
   {

   }
   vehicle(string id, float max_gw, float max_r, float max_sp) :id_number(id), max_gross_weight(max_gw), max_range(max_r), max_speed(max_sp)
   {

   }
   virtual string get_idnumber() = 0;
   virtual float get_max_gross_weight() = 0;
   virtual float get_max_range() = 0;
   virtual float get_max_speed() = 0;
   virtual void display() = 0;

};
class airplane: public vehicle
{
public:
   airplane(string id, float max_gw, float max_r, float max_sp) :vehicle(id,max_gw,max_r,max_sp)
   {

   }
   string get_idnumber()
   {
       return id_number;
   }
   float get_max_gross_weight()
   {
       return max_gross_weight;
   }
   float get_max_range()
   {
       return max_range;
   }

   float get_max_speed()
   {
       return max_speed;
   }

   string get_transportation_mode()
   {
       return "by - air";
   }
   void display()
   {
       cout << "Serial number:" << id_number << endl;
       cout << "Max gross weight:" << max_gross_weight << endl;
       cout << "Max Range:" << max_range << endl;
       cout << "Max Speed:" << max_speed << endl;
       cout << "transportation mode:" << get_transportation_mode() << endl;
   }

};
class boat : public vehicle
{
public:
   boat(string id, float max_gw, float max_r, float max_sp) :vehicle(id, max_gw, max_r, max_sp)
   {

   }
   string get_idnumber()
   {
       return id_number;
   }
   float get_max_gross_weight()
   {
       return max_gross_weight;
   }
   float get_max_range()
   {
       return max_range;
   }

   float get_max_speed()
   {
       return max_speed;
   }

   string get_transportation_mode()
   {
       return "by - water";
   }
   void display()
   {
       cout << "Serial number:" << id_number << endl;
       cout << "Max gross weight:" << max_gross_weight << endl;
       cout << "Max Range:" << max_range << endl;
       cout << "Max Speed:" << max_speed << endl;
       cout << "transportation mode:" << get_transportation_mode() << endl;
   }

};
class car : public vehicle
{
public:
   car(string id, float max_gw, float max_r, float max_sp) :vehicle(id, max_gw, max_r, max_sp)
   {

   }
   string get_idnumber()
   {
       return id_number;
   }
   float get_max_gross_weight()
   {
       return max_gross_weight;
   }
   float get_max_range()
   {
       return max_range;
   }

   float get_max_speed()
   {
       return max_speed;
   }

   string get_transportation_mode()
   {
       return "by - road";
   }
   void display()
   {
       cout << "Serial number:" << id_number << endl;
       cout << "Max gross weight:" << max_gross_weight << endl;
       cout << "Max Range:" << max_range << endl;
       cout << "Max Speed:" << max_speed << endl;
       cout << "transportation mode:" << get_transportation_mode() << endl;
   }

};

int main()
{
   vehicle *obj_air = new airplane("123AeBC",1244,2000,800);
   vehicle *obj_boat = new boat("123ABCe", 123, 2000, 40);
   vehicle *obj_car = new car("123ABCd", 1235, 2000, 200);
   obj_air->display();
   obj_boat->display();
   obj_car->display();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote