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.
Question
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.
Solution
The problem statement is asking to create a program that calculates the time it takes for different types of vehicles (Car, Bicycle, Boat) to travel a given distance at their maximum speeds.
Here are the steps to solve this problem:
-
Create a base class
Vehiclewith propertiesnumOfWheelsandmaxSpeedand methodssetNumOfWheels,setMaxSpeed,getNumOfWheels,getMaxSpeed, andtimeToTravel. -
Create three derived classes
Car,Bicycle, andBoatthat inherit from theVehicleclass. Each derived class should override thetimeToTravelmethod with the appropriate calculation for the specific vehicle type. -
In the
mainfunction, 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.
-
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
Similar Questions
Implement two vehicle classes: Car:The constructor for Car must take two arguments. The first of them is its maximum speed, and the second one is a string that denotes the units in which the speed is given: either "km/h" or "mph".The class must be implemented to return a string based on the arguments. For example, if car is an object of class Car with a maximum speed of 120, and the unit is "km/h", then printing car prints the following string: "Car with the maximum speed of 120 km/h", without quotes. If the maximum speed is 94 and the unit is "mph", then printing car prints in the following string: "Car with the maximum speed of 94 mph", without quotes. Boat:The constructor for Boat must take a single argument denoting its maximum speed in knots.The class must be implemented to return a string based on the argument. For example, if boat is an object of class Boat with a maximum speed of 82, then printing boat prints the following string: "Boat with the maximum speed of 82 knots", without quotes. The implementations of the classes will be tested by a provided code stub on several input files. Each input file contains several queries, and each query constructs an object of one of the classes. It then prints the string representation of the object to the standard output. Constraints1 ≤ the number of queries in one test file ≤ 100 Input Format Format for Custom TestingIn the first line, there is a single integer, q, the number of queries.Then, q lines follow. In the ith of them, there are space-separated parameters. The first of them denotes the vehicle type to be constructed, and the remaining parameters denote the values passed for the constructor of the object.Sample Case 0Sample InputSTDIN Function----- -------2 → number of queries, q = 2car 151 km/h → query parameters = ["car 151 km/h", "boat 77"]boat 77Sample OutputCar with the maximum speed of 151 km/hBoat with the maximum speed of 77 knotsExplanationThere are 2 queries. In the first of them, an object of class Car with the maximum speed of 151 in km/h is constructed, and then its string representation is printed to the output. In the second query, an object of class Boat is constructed with the maximum speed of 77 knots, and then its string representation is printed to the output.Sample Case 1Sample InputSTDIN Function----- --------3 → number of queries, q = 2boat 101 → query parameters = ["boat 101", "car 120 mph", "car 251 km/h"]car 120 mphcar 251 km/hSample OutputBoat with the maximum speed of 101 knotsCar with the maximum speed of 120 mphCar with the maximum speed of 251 km/hExplanationThere are 3 queries. In the first of them, an object of class Boat with the maximum speed of 101 knots is constructed, and then its string representation is printed to the output. In the second query, an object of class Car with the maximum speed of 120 in mph is constructed, and then its string representation is printed to the output. In the third query, an object of class Car with the maximum speed of 251 in km/h is constructed, and then its string representation is printed to the output.
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. Input 1: Car (VEHICLE TYPE) HRDQ2456 (VEHICLE NUMBER) 52WVC1234 (ENGINE NUMBER) 2H2X1234 (CHASSIS NUMBER) 535kph (SPEED) 4 (No. of PASSENGER) 5 (GEARS) Output1: Car HRDQ2456 52WVC1234 2H2X1234 535kph 4 5
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.
Nandhini is tasked with creating a program to calculate and display the speed of a car based on the distance covered and the time taken.Write a program with two classes: Vehicle as the base class and Car as the derived class, which inherits the properties from the Vehicle class for calculating the speed. The base class fetches the input as a float value, whereas the derived class calculates and prints the output as a float value.Note: Use public inheritanceNote: This kind of question will help in clearing Wipro recruitment.Input format :The input consists of two floating-point numbers separated by a space. The first number represents the distance traveled by the car, and the second number represents the time taken to cover that distance, separated by a space.Output format :The output displays a single line of output, showing the speed of the car in kilometers per hour.Refer to the sample output for the formatting specifications.Code constraints :The input distance and time should be non-negative floating-point numbers.The input time should not be zero (to avoid division by zero).Sample test cases :Input 1 :15.0 5.0Output 1 :Speed of car: 3 km/hrInput 2 :100.23 96.0Output 2 :Speed of car: 1.04406 km/hrNote :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.
2. Python: String Representations of ObjectsImplement two vehicle classes: Car:The constructor for Car must take two arguments. The first of them is its maximum speed, and the second one is a string that denotes the units in which the speed is given: either "km/h" or "mph".The class must be implemented to return a string based on the arguments. For example, if car is an object of class Car with a maximum speed of 120, and the unit is "km/h", then printing car prints the following string: "Car with the maximum speed of 120 km/h", without quotes. If the maximum speed is 94 and the unit is "mph", then printing car prints in the following string: "Car with the maximum speed of 94 mph", without quotes. Boat:The constructor for Boat must take a single argument denoting its maximum speed in knots.The class must be implemented to return a string based on the argument. For example, if boat is an object of class Boat with a maximum speed of 82, then printing boat prints the following string: "Boat with the maximum speed of 82 knots", without quotes. The implementations of the classes will be tested by a provided code stub on several input files. Each input file contains several queries, and each query constructs an object of one of the classes. It then prints the string representation of the object to the standard output. Constraints1 ≤ the number of queries in one test file ≤ 100 Input Format Format for Custom TestingIn the first line, there is a single integer, q, the number of queries.Then, q lines follow. In the ith of them, there are space-separated parameters. The first of them denotes the vehicle type to be constructed, and the remaining parameters denote the values passed for the constructor of the object.Sample Case 0Sample InputSTDIN Function----- -------2 → number of queries, q = 2car 151 km/h → query parameters = ["car 151 km/h", "boat 77"]boat 77Sample OutputCar with the maximum speed of 151 km/hBoat with the maximum speed of 77 knotsExplanationThere are 2 queries. In the first of them, an object of class Car with the maximum speed of 151 in km/h is constructed, and then its string representation is printed to the output. In the second query, an object of class Boat is constructed with the maximum speed of 77 knots, and then its string representation is printed to the output.Sample Case 1Sample InputSTDIN Function----- --------3 → number of queries, q = 2boat 101 → query parameters = ["boat 101", "car 120 mph", "car 251 km/h"]car 120 mphcar 251 km/hSample OutputBoat with the maximum speed of 101 knotsCar with the maximum speed of 120 mphCar with the maximum speed of 251 km/hExplanationThere are 3 queries. In the first of them, an object of class Boat with the maximum speed of 101 knots is constructed, and then its string representation is printed to the output. In the second query, an object of class Car with the maximum speed of 120 in mph is constructed, and then its string representation is printed to the output. In the third query, an object of class Car with the maximum speed of 251 in km/h is constructed, and then its string representation is printed to the output.
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.