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.
Question
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.
Solution
This problem is asking you to write a program that calculates the total cost of a bus trip. The total cost is the sum of the ticket cost and the fuel cost.
Here is a step-by-step guide on how to solve this problem:
-
First, you need to create a function called calculateTicketCost(). This function should take two parameters: ticket price and number of passengers. The function should return the product of the ticket price and the number of passengers.
-
Next, create another function called calculateFuelCost(). This function should take three parameters: fuel price, fuel consumption, and distance travelled. The function should return the product of the fuel price, fuel consumption, and distance travelled.
-
Then, in the main function, you should read the inputs from the user. The inputs are: ticket price, number of passengers, fuel price, fuel consumption, and distance travelled.
-
After reading the inputs, call the calculateTicketCost() function with the ticket price and number of passengers as arguments, and store the result in a variable.
-
Similarly, call the calculateFuelCost() function with the fuel price, fuel consumption, and distance travelled as arguments, and store the result in another variable.
-
Finally, add the results of the calculateTicketCost() and calculateFuelCost() functions to get the total cost. Print the total cost with "Rs. " before it, and round it to two decimal places.
Remember to ensure that all double values are presented with one decimal place, and the total cost is rounded to two decimal places.
Similar Questions
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.
Single File Programming QuestionProblem StatementLilly went shopping with a budget of Rs. 10,000 to buy clothes, and accessories. The cost of clothes is twice the value of accessories, and there is an additional expense of Rs. 1000 for fuel. Develop an expense calculator by inputting the amount spent on accessories, then calculate and display Lilly's remaining amount rounded to two decimal places after her shopping.ExampleInput:2000.0Output:3000.0Explanation:budget = 10000.0;fuel = 1000.0;accessories = 2000.0clothes = 2 * accessories = 2 * 2000 = 4000.0total = clothes + accessories + fuel = 4000.0 + 2000.0 + 1000.0 = 7000.0remaining = budget - total = 10000.0 - 7000.0 = 3000.0Input format :The input consists of a float value a, representing the amount spent on accessories.Output format :The output prints the remaining budget after shopping, rounded to two decimal places in the following format: "Rs. [remaining amount]". Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:10.0 ≤ a ≤ 3000.0Sample test cases :Input 1 :10.0Output 1 :Rs. 8970.00Input 2 :2000.0Output 2 :Rs. 3000.00Input 3 :3000.0Output 3 :Rs. 0.00Input 4 :1578.89Output 4 :Rs. 4263.33
Single File Programming QuestionProblem StatementAthul, a supermarket employee, needs a program to calculate Goods and Services Tax (GST) deductions for customer purchases. The program should take a purchase code (A to F) and amount, apply the relevant GST rate, subtract it from the original amount, and print the result. The user's total amount and product code are used to calculate the GST.For example, if the amount is 100.00 and the product code is 'C', 5% GST is applied, and the amount is calculated as 100.00 - (100.00*0.05) which is equal to 95.00.Input format :The first line of the input consists of a character representing the product code ('A', 'B', 'C', 'D', 'E', or 'F').The second line consists of a float value representing the total amount.Output format :If the code is valid ('A', 'B', 'C', 'D', 'E', or 'F'), the output displays a float value representing the amount after deducting GST, rounded off to two decimal places, after applying the appropriate GST deduction.If the code is invalid, it displays "Invalid choice".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:100.0 ≤ total amount ≤ 10000.0Sample test cases :Input 1 :C100.00Output 1 :95.00Input 2 :A2000.00Output 2 :2000.00Input 3 :W2300.67Output 3 :Invalid choiceInput 4 :B10000.00Output 4 :9800.00Input 5 :D1234.52Output 5 :1086.38Input 6 :E5678.00Output 6 :4655.96Input 7 :F9789.00Output 7 :7048.08Note :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 StatementMaria loves shopping and is curious to know the total cost of her favorite items. She intends to purchase t items, each priced at p rupees, with a progressive increase of 5 rupees for every subsequent item.Write a program that takes the price of one item (p) and the number of items (t) as input, calculates the total cost using the formula (t/2) * (2p + (t-1) * 5), and displays the result.Input format :The first line of input consists of a float value p, representing the price of an item.The second line of input consists of an integer t, representing the number of items.Output format :The output displays "Rs. " followed by a float value, representing the total cost in rupees, rounded off to two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:10.0 ≤ p ≤ 1000.01 ≤ t ≤ 100Sample test cases :Input 1 :10.03Output 1 :Rs. 45.00Input 2 :720.056Output 2 :Rs. 48020.00
Single File Programming QuestionProblem StatementMeet Alex, a budget-savvy shopper who wants to give discounts to customers in the following ways:If the amount is greater than 5000 (not inclusive), the discount is 20%.If it is greater than 2000 (not inclusive), the discount is 15%.10% discount for a purchase amount greater than 1000 (not inclusive). Write a program that takes the amount as input and calculates the discounts using a function named applyDiscount. The discount rates are set as 10%, 15%, and 20% as global double datatype variables.Input format :The input consists of a double value representing the amount.Output format :The output displays "Discounted amount: " followed by a double value representing the discounted amount, rounded to two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1000.0 ≤ Amount ≤ 10000.0Sample test cases :Input 1 :2000.0Output 1 :Discounted amount: 1800.00Input 2 :1100.50Output 2 :Discounted amount: 990.45Input 3 :10000.0Output 3 :Discounted amount: 8000.00Input 4 :1000.0Output 4 :Discounted amount: 1000.00
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.