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

Page of 3 ZOOM+ nt rain() Car car Tesla\", S,12345L Boat boat \"Mayflower\", 7.5

ID: 3904957 • Letter: P

Question

Page of 3 ZOOM+ nt rain() Car car Tesla", S,12345L Boat boat "Mayflower", 7.5 Airplane plane{ "Boeing", 987651 }; / (should print) Cars Make Tesla, Model S, VIN-12345 car.Status) /I (should print) Boat: Nane - Meyflower, Cargo-7.5 boat Status() (should print) Airplane: Manufacturer Boeing, Serial -98765 plane Status); 2. Create a vehide class. Each ofthe three objects in problem #1 should inherit from whide You should be ab'e to send a wehide to a location using a function with the signature vold Send oLocation std:pair cdouble, double location). In addition, you shoud be able to see any vehide's current kocation as part of its status Use the following man function and make sure the output matches that indicated in the comments. int naan() Car cart Tesla"."s'. 12345L Boat boat ayFlower, 7.5 Airplane plane Boeing"98765 car.SendToLocatlon(paircdouble, obli.a, 3.5)) S, VIN // (should print) Car: Location- (1.8, 3.5), Hake - Tesla, ?0de1 car.Status): boat.SendTolocation(paircdouble, doublex(i.1, 3.4)) 1/3 (should print) Boat: Locetion-(1.1,3.4) Name-MayFlower, Care boat.Status) plane.SendToLocation (pairedouble, double>(a.e 3.5)) 7.5 (should print) Airplane: Location -(e.a, -3.5), Manufacturer -Booing, Serial-98765 plane.Status):

Explanation / Answer

#include<iostream>
#include<string>
#include<utility>

using namespace std;

class Vehicle{
    private:
     pair <double, double> location;

    public:
       Vehicle(){
         location.first = 0;
         location.second = 0;
       }
       pair <double, double> getLocation(){
          return location;
       }
       void setLocation(pair <double, double> a){
          location = a;
       }

};


class Car : public Vehicle{

    private:
        string model;
        string make;
        long vin;
    public:
        Car(string mk , string md, long v) : Vehicle(){
              model = md;
              make = mk;
              vin = v;
        }
        void sendToLocation(std::pair<double,double> a){
            setLocation(a);
        }
        void status(){
            pair <double,double> b = getLocation();           
            cout << "Car:" << "Location:(" << b.first << "," << b.second << ") ";
            cout << "Make:" << make << " Model:" << model << " vin:" << vin << endl;      
        }
};


class Boat : public Vehicle{

    private:
        string name;
        double cargo;
    public:
        Boat(string nm , double c) : Vehicle(){
            name = nm;
            cargo = c;
        }
        void sendToLocation(std::pair<double,double> a){
            setLocation(a);
        }
        void status(){
            pair <double,double> b = getLocation();           
            cout << "Boat:" << "Location:(" << b.first << "," << b.second << ") ";
            cout << "Name:" << name << " Cargo:" << cargo << endl;      
        }
};


class Airplane : public Vehicle{

    private:
        string manufacturer;
        long serial;
    public:
        Airplane(string mn , long s) : Vehicle(){
            manufacturer = mn;
            serial = s;
        }
        void sendToLocation(std::pair<double,double> a){
            setLocation(a);
        }
        void status(){
            pair <double,double> b = getLocation();           
            cout << "Airplane:" << "Location:(" << b.first << "," << b.second << ") ";
            cout << "Manufacturer:" << manufacturer << " Serial:" << serial << endl;      
        }
};

int main(){

    Car car("Tesla","S",12345L);
    Boat boat("Mayflower",7.5);
    Airplane plane("Boeing", 98765L);
    car.sendToLocation(pair<double,double>(1.8,3.5));
    car.status();
    boat.sendToLocation(pair<double,double>(1.1,1.4));
    boat.status();
    plane.sendToLocation(pair<double,double>(0.0,-3.5));
    boat.status();

    return 0;
}