Knowee
Questions
Features
Study Tools

Design a C++ program to manage vehicles for a transport company. The program should handle three types of vehicles: cars, trucks, and buses. Implement a class with a base class and derived classes for each vehicle type. The base class, Vehicle, should have the following attributes: colour, mileage, top speed, and the number of gears. Each derived class should inherit from the Vehicle class and include additional attributes specific to the vehicle type.Car Class (Derived from Vehicle):Additional Attributes: number of doors and fuel type.Functionality: Implement a function to display car details, including all attributes inherited from the base class and the additional attributes specific to cars.Truck Class (Derived from Vehicle):Additional Attributes: cargo capacity and max load capacity.Functionality: Implement a function to display truck details, including all attributes inherited from the base class and the additional attributes specific to trucks.Bus Class (Derived from Vehicle):Additional Attributes: seating capacity and route number.Functionality: Implement a function to display bus details, including all attributes inherited from the base class and the additional attributes specific to buses.

Question

Design a C++ program to manage vehicles for a transport company. The program should handle three types of vehicles: cars, trucks, and buses. Implement a class with a base class and derived classes for each vehicle type. The base class, Vehicle, should have the following attributes: colour, mileage, top speed, and the number of gears. Each derived class should inherit from the Vehicle class and include additional attributes specific to the vehicle type.Car Class (Derived from Vehicle):Additional Attributes: number of doors and fuel type.Functionality: Implement a function to display car details, including all attributes inherited from the base class and the additional attributes specific to cars.Truck Class (Derived from Vehicle):Additional Attributes: cargo capacity and max load capacity.Functionality: Implement a function to display truck details, including all attributes inherited from the base class and the additional attributes specific to trucks.Bus Class (Derived from Vehicle):Additional Attributes: seating capacity and route number.Functionality: Implement a function to display bus details, including all attributes inherited from the base class and the additional attributes specific to buses.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a basic implementation of the program in C++:

#include<iostream>
#include<string>
using namespace std;

// Base class
class Vehicle {
public:
    string colour;
    int mileage;
    int topSpeed;
    int numGears;

    Vehicle(string c, int m, int ts, int ng) : colour(c), mileage(m), topSpeed(ts), numGears(ng) {}
};

// Derived class
class Car : public Vehicle {
public:
    int numDoors;
    string fuelType;

    Car(string c, int m, int ts, int ng, int nd, string ft) : Vehicle(c, m, ts, ng), numDoors(nd), fuelType(ft) {}

    void displayDetails() {
        cout << "Car Details: \n";
        cout << "Colour: " << colour << "\nMileage: " << mileage << "\nTop Speed: " << topSpeed << "\nNumber of Gears: " << numGears;
        cout << "\nNumber of Doors: " << numDoors << "\nFuel Type: " << fuelType << "\n";
    }
};

class Truck : public Vehicle {
public:
    int cargoCapacity;
    int maxLoad;

    Truck(string c, int m, int ts, int ng, int cc, int ml) : Vehicle(c, m, ts, ng), cargoCapacity(cc), maxLoad(ml) {}

    void displayDetails() {
        cout << "Truck Details: \n";
        cout << "Colour: " << colour << "\nMileage: " << mileage << "\nTop Speed: " << topSpeed << "\nNumber of Gears: " << numGears;
        cout << "\nCargo Capacity: " << cargoCapacity << "\nMax Load: " << maxLoad << "\n";
    }
};

class Bus : public Vehicle {
public:
    int seatingCapacity;
    int routeNumber;

    Bus(string c, int m, int ts, int ng, int sc, int rn) : Vehicle(c, m, ts, ng), seatingCapacity(sc), routeNumber(rn) {}

    void displayDetails() {
        cout << "Bus Details: \n";
        cout << "Colour: " << colour << "\nMileage: " << mileage << "\nTop Speed: " << topSpeed << "\nNumber of Gears: " << numGears;
        cout << "\nSeating Capacity: " << seatingCapacity << "\nRoute Number: " << routeNumber << "\n";
    }
};

int main() {
    Car car("Red", 10000, 200, 5, 4, "Petrol");
    car.displayDetails();

    Truck truck("Blue", 50000, 120, 8, 20000, 10000);
    truck.displayDetails();

    Bus bus("Yellow", 30000, 100, 6, 50, 101);
    bus.displayDetails();

    return 0;
}

This program defines a base class Vehicle and three derived classes Car, Truck, and Bus. Each derived class has additional attributes specific to the vehicle type and a function displayDetails() to display all the details of the vehicle. The main() function creates an object of each derived class and calls the displayDetails() function to display the details of each vehicle.

This problem has been solved

Similar Questions

Problem StatementKaniska is tasked with creating a program that allows users to input information about different types of vehicles and calculate the time it takes for these vehicles to travel a given distance at their maximum speeds. The program will support three types of vehicles: Cars, Bicycles, and Boats.Your task is to implement the Vehicle class as the base class for these three vehicle types. The Vehicle class should have the following properties and functionalities:Properties:numOfWheels (integer): representing the number of wheels of the vehicle.maxSpeed (floating-point): representing the maximum speed of the vehicle.Functionalities:A default constructor to initialize numOfWheels and maxSpeed to 0.A virtual function setNumOfWheels(int wheels) to set the number of wheels of the vehicle.A virtual function setMaxSpeed(float speed) to set the maximum speed of the vehicle.A virtual function getNumOfWheels() to get the number of wheels on the vehicle.A virtual function getMaxSpeed() to get the maximum speed of the vehicle.A virtual function timeToTravel(float distance) that calculates and returns the time it takes for the vehicle to travel the given distance at its maximum speed.Implement three derived classes, Car, Bicycle, and Boat, which inherit from the Vehicle class. Each derived class should override the timeToTravel(float distance) function with the appropriate calculation for the specific vehicle type. The Car and Bicycle classes should calculate the time based on their maximum speed in mph, while the Boat class should consider the maximum speed in knots and convert it to mph using the formula 1 knot = 1.151 mph.In the main function, create instances of each vehicle type (Car, Bicycle, and Boat) and take user input for the number of wheels and maximum speed for each vehicle. Then, the user will input a distance, and the program will display the details of each vehicle and the time it takes for each vehicle to travel the given distance at its maximum speed.Note: This kind of question will help in clearing Capgemini recruitment.Input format :The first line consists of the number of wheels and the maximum speed of the car, separated by a single space.The third line consists of the number of wheels and the maximum speed of the bicycle, separated by a single space.The fifth line consists of the maximum speed of the boat (in knots).The sixth line consists of the distance to travel (in miles).Output format :The program outputs the details of the car, bicycle, and boat, including the number of wheels and the maximum speed for each vehicle, as well as the time it would take to travel the specified distance at maximum speed.The output includes the vehicle type, number of wheels, maximum speed, and time taken to travel the distance.The time taken is displayed in hours.Refer to the sample input and output for format specifications.Code constraints :The number of wheels (numOfWheels) for each vehicle is a positive integer.The maximum speed (maxSpeed) for each vehicle is a positive floating-point number.The distance to travel is a positive floating-point number.The maximum speed of the Boat (in knots) should be converted to mph using the formula: 1 knot = 1.151 mph.Sample test cases :Input 1 :4 602 153050Output 1 :Vehicle Details:Car has 4 wheels and can go up to 60 mph. It would take 0.833333 hours to travel 50 miles at maximum speed.Bicycle has 2 wheels and can go up to 15 mph. It would take 3.33333 hours to travel 50 miles at maximum speed.Boat has 0 wheels and can go up to 30 knots. It would take 1.44802 hours to travel 50 miles at maximum speed.Input 2 :4 902 203575Output 2 :Vehicle Details:Car has 4 wheels and can go up to 90 mph. It would take 0.833333 hours to travel 75 miles at maximum speed.Bicycle has 2 wheels and can go up to 20 mph. It would take 3.75 hours to travel 75 miles at maximum speed.Boat has 0 wheels and can go up to 35 knots. It would take 1.86174 hours to travel 75 miles at maximum speed.Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Develop a Java Application with ‘Vehicle’ Class with vehicle type, vehicle number, as member. Inherit the classes bicycle, car, bike, and lorry from vehicle class. Consider car and bike only as passenger vehicle. Get inputs engine number, chassis number, top speed, number of passengers, number of gears for Passenger vehicle, and if is not a passenger vehicle, get inputs total amount of load to carry for the respective inherited classes. Generate a report for the vehicles. Implement the concept using inheritance and method overriding.

Develop a Java Application with ‘Vehicle’ Class with vehicle type, vehicle number, engine number, chassis number, top speed, number of passengers, number of gears. Generate a report for the vehicles. Implement the concept using Interfaces.

Write the codeCreate a Python program to model vehicles, specifically two types: Car and Truck.Begin by defining a base class Vehicle with attributes make, model, and price. Subsequently, create two derived classes, Car and Truck, both of which inherit from the Vehicle class. Each derived class should introduce its unique attributes, and:Implement a method display_info in the base class Vehicle to print the common attributes (make, model, price).Override the display_info method in each derived class (Car and Truck) to print the make, model, price along with the unique attributes (num_doors for Car and max_load for Truck) respectively.Input Format:For Car:The first line contains the make, model, price, and number of doors of the car, separated by spaces.For Truck:The first line contains the make, model, price, and maximum load capacity of the truck, separated by spaces.Output Format:The first line should display information about the car, including the make, model, price, and number of doors.The second line should display information about the truck, including the make, model, price, and maximum load capacity.Sample Test CasesTest Case 1:Expected Output:Enter·make,·model,·price,·and·number·of·doors·of·the·car·(separated·by·spaces):·Honda civic 500000 5Enter·make,·model,·price,·and·maximum·load·capacity·of·the·truck·(separated·by·spaces):·Tesla hammer1002 1200000 7000Honda·civic·$500000Number·of·doors:·5Tesla·hammer1002·$1200000Maximum·load·capacity:·7000·tons

Problem 2: Classes and Objects Scenario: Write a Python program to implement the concept of classes, methods, and objects. Instructions:  Create a Python Class named “Vehicle.”  This Class will have a total of five (5) attributes and one (1) method, as follows: o Attributes: type, total_seats, color, price, mileage o Method: print_detail()  If the total number of seats in a vehicle is more than seven (7) and the price is more than $50,000, print “It is an unaffordable vehicle.” Otherwise, print “You may afford and easily park it.”  Create the following four (4) vehicle objects: bus, bike, car, and pickup_truck.  For each object, take the attribute value from the user. This means the user will enter all five (5) attribute values for each object.  Assign these values to the related object and print all the details one by one.  In your program logic, you must use the concept of classes, methods, and objects, as well as accessing methods through objects.  Save your Python file as: Problem2_StudentNameInitials

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.