Single File Programming QuestionProblem StatementA traffic monitoring system needs a program to assess and report a driver's speed based on the road type and the current speed. The program should take two inputs: the road type (1 for residential, 2 for city, 3 for highway) and the driver's current speed. The system should then determine whether the driver is below, at, or above the speed limit for the given road type.The speed limits for each road type are as follows:Residential: 25 km/hCity: 35 km/hHighway: 55 km/hThe output is one of the following:"Below" if the current speed is below the speed limit."Normal" if the current speed is equal to the speed limit."Above" if the current speed is above the speed limit.Input format :The first line consists of an integer representing the user's choice (1 for City Roads, 2 for Residential Areas, 3 for Highways).The second line consists of an integer representing the vehicle's speed.Output format :Depending on the selected option, the program displays one of the following messages:"Below" if the current speed is below the speed limit."Normal" if the current speed is equal to the speed limit."Above" if the current speed is above the speed limit.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:1 ≤ choice ≤ 30 < current speed ≤ 100Sample test cases :Input 1 :120Output 1 :BelowInput 2 :125Output 2 :NormalInput 3 :230Output 3 :BelowInput 4 :3100Output 4 :AboveInput 5 :299Output 5 :AboveNote :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.Marks : 10
Question
Single File Programming QuestionProblem StatementA traffic monitoring system needs a program to assess and report a driver's speed based on the road type and the current speed. The program should take two inputs: the road type (1 for residential, 2 for city, 3 for highway) and the driver's current speed. The system should then determine whether the driver is below, at, or above the speed limit for the given road type.The speed limits for each road type are as follows:Residential: 25 km/hCity: 35 km/hHighway: 55 km/hThe output is one of the following:"Below" if the current speed is below the speed limit."Normal" if the current speed is equal to the speed limit."Above" if the current speed is above the speed limit.Input format :The first line consists of an integer representing the user's choice (1 for City Roads, 2 for Residential Areas, 3 for Highways).The second line consists of an integer representing the vehicle's speed.Output format :Depending on the selected option, the program displays one of the following messages:"Below" if the current speed is below the speed limit."Normal" if the current speed is equal to the speed limit."Above" if the current speed is above the speed limit.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:1 ≤ choice ≤ 30 < current speed ≤ 100Sample test cases :Input 1 :120Output 1 :BelowInput 2 :125Output 2 :NormalInput 3 :230Output 3 :BelowInput 4 :3100Output 4 :AboveInput 5 :299Output 5 :AboveNote :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.Marks : 10
Solution
Sure, here is a Python solution for the problem:
# Get the road type and current speed from the user
road_type = int(input())
current_speed = int(input())
# Define the speed limits for each road type
speed_limits = {1: 35, 2: 25, 3: 55}
# Get the speed limit for the given road type
speed_limit = speed_limits[road_type]
# Determine whether the driver is below, at, or above the speed limit
if current_speed < speed_limit:
print("Below")
elif current_speed == speed_limit:
print("Normal")
else:
print("Above")
This program first gets the road type and current speed from the user. It then defines a dictionary where the keys are the road types and the values are the corresponding speed limits. It uses this dictionary to get the speed limit for the given road type. Finally, it checks whether the current speed is below, at, or above the speed limit, and prints the appropriate message.
Similar Questions
Alice is going for a drive. During her drive, she reached a maximum speed of 𝑆S km/hr.As per the rules of the government, the speed of the vehicle must not exceed 4040 km/hr, otherwise the person will be fined.You need to tell whether Alice will be fined or not.Input FormatThe only line of input will contain a single integer 𝑆S - denoting the maximum speed Alice reached while driving.Output FormatPrint YES if Alice will be fined , otherwise print NO.You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).Constraints1≤𝑆≤501≤S≤50Sample 1:InputOutput40NOExplanation:Since Alice's speed does not exceed 4040, she will not be fined.Sample 2:InputOutput41YESExplanation:Since Alice's speed exceeds 4040, she will be fined.
Single File Programming QuestionProblem StatementAmit wants to evaluate the depreciation of his car over time to understand its current value and categorize it based on that value. Write a program that helps him determine the current value of his car after a certain number of years of depreciation and classify it into one of three categories:High: If the current value is greater than 10,000.Medium: If the current value is between 5,000 and 10,000, both inclusive.Low: If the current value is less than 5,000.The depreciation rate of the car is 15% per year. The program should calculate the current value of the car after applying this depreciation over the given number of years and print the current value along with the category.Company Tags: InfosysInput format :The first line of input consists of an integer, representing the initial cost of the car.The second line consists of an integer, representing the number of years the car has been depreciating.Output format :The first line of output prints a double value, representing the current value of the car, rounded off to two decimal places.The second line prints its category.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ initial cost ≤ 1000000 ≤ age ≤ 100Sample test cases :Input 1 :200005Output 1 :Current Value: 8874.11Category: MediumInput 2 :155377Output 2 :Current Value: 4980.81Category: LowInput 3 :125751Output 3 :Current Value: 10688.75Category: HighNote :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.
Single File Programming QuestionProblem StatementKumar is developing a program to compute the overall cost of a bus trip. The calculateTicketCost() function gathers data on ticket price and passenger count and returns ticket cost, while calculateFuelCost() collects information on fuel price, consumption, and distance and returns fuel cost. The main function then calculates and prints the total cost.Formulas used:Ticket cost = ticket price * number of passengersFuel cost = fuel price * fuel consumption * distance travelledTotal cost = Ticket cost + Fuel costInput format :The first line of input consists of the ticket price (a double).The second line of input consists of the number of passengers (an integer).The third line of input consists of the fuel price (a double).The fourth line of input consists of the fuel consumption per unit distance (a double).The fifth line of input consists of the distance travelled (a double).Note: Ensure that all double values are presented with one decimal place.Output format :The output displays "Rs. " followed by a double value representing the total cost for the bus trip, rounded to two decimal places.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:0.1 ≤ ticket price, fuel price, fuel consumption, distance travelled ≤ 100.01 ≤ Number of passengers ≤ 100Sample test cases :Input 1 :0.110.10.10.1Output 1 :Rs. 0.10Input 2 :100.0100100.0100.0100.0Output 2 :Rs. 1010000.00Input 3 :50.52010.22.36.7Output 3 :Rs. 1167.18Note :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.
Single File Programming QuestionProblem StatementJames is a meticulous traveler who is calculating the total cost of his road trip. James considers factors such as distance traveled, gas consumption, average miles per liter, parking fees, and toll charges. The program takes inputs for miles traveled, gas consumed, average miles per liter, parking fees, and toll charges, and computes the total cost using the formula:The result is then displayed with four two-decimal places. The program utilizes arithmetic operators for the calculations.Input format :The first line consists of the total number of miles traveled per day as an integer.The second line consists of the cost of gas per liter as an integer.The third line consists of the average miles per liter of gas as a positive double-point number.The fourth line consists of the parking cost as an integer.The last line consists of the toll cost as an integer.Output format :The output displays a double value representing the total cost calculated based on the given formula with rounded-off to decimal places.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ miles ≤ 10050 ≤ cost of gas ≤ 1505.0 ≤ average_miles ≤ 60.010 ≤ parking charge ≤ 10050 ≤ toll cost ≤ 500Sample test cases :Input 1 :1505.01050Output 1 :70.00Input 2 :587010.54565Output 2 :496.67Input 3 :10015060.0100500Output 3 :850.00Note :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.
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.
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.