Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description (It has to work with c++ please and we can't use pointers or classes thank you) The purpose of this challenge is to get

Description (It has to work with c++ please and we can't use pointers or classes thank you)

The purpose of this challenge is to get familiar with overloaded functions and functions with default parameters. This challenge simulates what an Uber-like service might use behind the scenes.

Requirements

In main(), ask the user to enter their full name. Use code as shown below to accept a string with spaces. getline() is a function available to you from iostream. You do not needshould not tryto create it.

getline(cin, fullname); // where fullname is a string variable 

In main(), ask the user to enter their destination. Destination will be entered as the full street name. Since street address will include spaces, use code similar to what was given in step 1

In main(), ask the user if their destination is within city limits. (In a real scenario, the GPS mapping software would be able to determine this based on the destination address. Since we dont have that ability, we will simply ask the user).

In main(), ask the user to enter the distance of the fare. (In a real scenario, the GPS mapping software would be able to determine this based on the destination address. Since we dont have that ability, we will simply ask the user).

Create a function calc_fare(double distance). This function will calculate the fare as follows: A fixed amount of $10 for distances up to 2 miles. $2.50 per mile for distances over 2 miles and up to 5 miles plus a fixed amount of $5.00. Anything over 5 miles will be charged at $3.50 per mile. Return the amount of the fare based on the above rate table.

Create a function calc_fare(double distance, double surcharge). This function calls the calc_fare() function in step 5 and returns a value adding the surcharge to the resulting fare.

Create a function calc_fare(double distance, bool local). When local is true, it means that the fare is within city limits. When local is false, it means that the fare goes outside city limits, in which case, an additional $50 surcharge will be added to the fare. Call calc_fare() from Step 5 and calc_fare() from Step 6 within this function, depending on the value of local. Note that the functions given in steps 5-7 are overloaded versions of the calc_fare()function.

Essentially, what we are doing in this exercise is creating the calc_fare()functions and calling them with driver calls. Drivers-no pun intended since this is a driving simulation-are basically the execution of functions manually to test that they are working, or calculating correctly. The input values of the calc_fare() functions are being entered manually by the user to test them. In a real use case of the functions, they will be called with distances determined by GPS mapping library calls.

Create a function called show_fare_info(string name, string destination, double fare, bool local = true). This function will display the information to the user based on the previous user input. This function shows information; what return type is best to use for this function? Call this function from main() to display the final output. This function gives a different message based on the local variable.

DO NOT USE

No real restrictions on what not to use, but you must use functions.

Sample partial main()

int main() { // ... more code here cout << "Is this within the city? "; cin >> local; if (local == 'y') { // more code here fare = calc_fare(distance, true); show_fare_info(fullname, destination, fare); } else if (local == 'n') { // more code here fare = calc_fare(distance, false); show_fare_info(fullname, destination, fare, false); } return 0; } 

Sample Interaction / Output

Thanks for using GUBER. What is your full name? MIKE CARSON-SHOPPE Enter destination: 127 WALKING DISTANCE ST What is the distance to 127 WALKING DISTANCE ST? 1.0 Is this within the city? y Ok, MIKE CARSON-SHOPPE, your fare to 127 WALKING DISTANCE ST will be $10.00 

Run it again:

Thanks for using GUBER. What is your full name? MILES OVERSTREET Enter destination: 99 EASY DR What is the distance to 99 EASY DR? 4.0 Is this within the city? y Ok, MILES OVERSTREET, your fare to 99 EASY DR will be $15.00 

Run it again:

Thanks for using GUBER. What is your full name? DUSTY RHOADES Enter destination: 999 FARFARA WAY What is the distance to 999 FARFARA WAY? 25.0 Is this within the city? n Ok, DUSTY RHOADES, your fare to 999 FARFARA WAY will be $137.50. This fare includes a surcharge of $50 for going outside the city limits. Remember to use GUBER on your return trip home. We will offer a 10% discount if you use GUBER on your return. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions