12. Calculate the travel fare. Need C, C++, Java, Python, or Perl code for the below question. Important: Do not copy codes from prepinsta.com.
12. Calculate the travel fare. Need C, C++, Java, Python, or Perl code for the below question. Important: Do not copy codes from prepinsta.com.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
12. Calculate the travel fare. Need C, C++, Java, Python, or Perl code for the below question. Important: Do not copy codes from prepinsta.com.
![Given, n=8, where n is number of total BusStops.
BusStops = ["TH", "GA", "IC", "HA", "TE", "LU", "NI","CA"]
Write a code with function getFare(String Source, String Destination) which take
Input as source and destination stops (in the format containing first two characters
of the Name of the Bus Stop) and calculate and return travel fare.
Example 1:
Input Values
ca
Ca
Output Values
INVALID OUTPUT
Example 2:
Input Values
NI
HA
Output Values
23.0 INR
Note: Input and Output should be in format given in example.
Input should not be case sensitive and output should be in the format INR.
C++ Code:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2bb17e7e-2ebe-4c45-b40e-6cf48e363ffb%2F5ab1a698-becb-4c02-aad3-a950a5a36641%2Fh9hr4_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Given, n=8, where n is number of total BusStops.
BusStops = ["TH", "GA", "IC", "HA", "TE", "LU", "NI","CA"]
Write a code with function getFare(String Source, String Destination) which take
Input as source and destination stops (in the format containing first two characters
of the Name of the Bus Stop) and calculate and return travel fare.
Example 1:
Input Values
ca
Ca
Output Values
INVALID OUTPUT
Example 2:
Input Values
NI
HA
Output Values
23.0 INR
Note: Input and Output should be in format given in example.
Input should not be case sensitive and output should be in the format INR.
C++ Code:
![Question: A City Bus is a Ring Route Bus which runs in circular fashion. That is, Bus
once starts at the Source Bus Stop, halts at each Bus Stop in its Route and at the
end it reaches the Source Bus Stop again.
If there are n number of Stops and if the bus starts at Bus Stop 1, then after nth
Bus Stop, the next stop in the Route will be Bus Stop number 1 always.
If there are n stops, there will be n paths.One path connects two stops. Distances
(in meters) for all paths in Ring Route is given in array Path[] as given below:
Path = [800, 600, 750, 900, 1400, 1200, 1100, 1500]
Fare is determined based on the distance covered from source to destination stop
as Distance between Input Source and Destination Stops can be measured by
looking at values in array Path[] and fare can be calculated as per following
criteria:
• If d =1000 metres, then fare=5 INR
. (When calculating fare for others, the calculated fare containing any fraction
value should be ceiled. For example, for distance 900n when fare initially
calculated is 4.5 which must be ceiled to 5)
Path is circular in function. Value at each index indicates distance till current stop
from the previous one. And each index position can be mapped with values at
same index in BusStops [] array, which is a string array holding abbreviation of
names for all stops as-
"THANERAILWAYSTN"="TH", "GAONDEVI" = "GA", "ICEFACTROY" = "IC",
"HARINIWASCIRCLE" = "HA", "TEENHATHNAKA" = "TE", "LUISWADI" = "LU",
"NITINCOMPANYJUNCTION"="NI", "CADBURRYJUNCTION" = "CA"
Given, n=8, where n is number of total BusStops.
BusStops = ["TH", "GA", "IC", "HA", "TE", "LU", "NI","CA"]
Write a code with function getFare(String Source, String Destination) which take
Input as source and destination stops (in the format containing first two characters
of the Name of the Bus Stop) and calculate and return travel fare.
Example 1:
Input Values
ca
Ca
Output Values
INVALID OUTPUT](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2bb17e7e-2ebe-4c45-b40e-6cf48e363ffb%2F5ab1a698-becb-4c02-aad3-a950a5a36641%2Fkpcst58_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Question: A City Bus is a Ring Route Bus which runs in circular fashion. That is, Bus
once starts at the Source Bus Stop, halts at each Bus Stop in its Route and at the
end it reaches the Source Bus Stop again.
If there are n number of Stops and if the bus starts at Bus Stop 1, then after nth
Bus Stop, the next stop in the Route will be Bus Stop number 1 always.
If there are n stops, there will be n paths.One path connects two stops. Distances
(in meters) for all paths in Ring Route is given in array Path[] as given below:
Path = [800, 600, 750, 900, 1400, 1200, 1100, 1500]
Fare is determined based on the distance covered from source to destination stop
as Distance between Input Source and Destination Stops can be measured by
looking at values in array Path[] and fare can be calculated as per following
criteria:
• If d =1000 metres, then fare=5 INR
. (When calculating fare for others, the calculated fare containing any fraction
value should be ceiled. For example, for distance 900n when fare initially
calculated is 4.5 which must be ceiled to 5)
Path is circular in function. Value at each index indicates distance till current stop
from the previous one. And each index position can be mapped with values at
same index in BusStops [] array, which is a string array holding abbreviation of
names for all stops as-
"THANERAILWAYSTN"="TH", "GAONDEVI" = "GA", "ICEFACTROY" = "IC",
"HARINIWASCIRCLE" = "HA", "TEENHATHNAKA" = "TE", "LUISWADI" = "LU",
"NITINCOMPANYJUNCTION"="NI", "CADBURRYJUNCTION" = "CA"
Given, n=8, where n is number of total BusStops.
BusStops = ["TH", "GA", "IC", "HA", "TE", "LU", "NI","CA"]
Write a code with function getFare(String Source, String Destination) which take
Input as source and destination stops (in the format containing first two characters
of the Name of the Bus Stop) and calculate and return travel fare.
Example 1:
Input Values
ca
Ca
Output Values
INVALID OUTPUT
Expert Solution

Step 1
I have used Python 3 to solve the above Question.
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education