Write a C++ program to calculate travel times for a number of predefined trips (use distance = rate * time for your calculations). Create 10 predefined trips, originating from Chicago, to various cities of your choice in the United States. Find and store the distance between cities in miles. List the pre-defined trips and prompt a user to select one of these trips, input a travel speed in miles per hour, then print the calculated duration (in hours). Continue until the user terminates the program.

Examine the problem description and identify a single primary data model to design as a C++ class. Your analysis should have identified a “trip” as the main object (noun) evident in the program description. This data model identification is critical to successful object-oriented programming. Write your class definition in a header file (Trip.h), your class member function definitions in a separate class source file (Trip.C or .cpp), and your main application in a separate source file. Compile your program using the GNU C++ compiler, g++.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

double Trip::getDuration(double speed, vector<road> r)
    double tmp = 0;
    double duration = 0;
    double distance;
    for (int i = 0; i < trip.size() - 1; i++) {
       // SET MAX VALUE
       distance = 10000000;
       for (int j = 0; j < r.size(); j++) {
            if ((trip[i] == r[j].city1 && trip[i+1] == r[j].city2)
                   || (trip[i+1] == r[j].city1 && trip[i] == r[j].city2 )) {
                distance = r[j].distance;
            }// end if

       }// end for loop j
       tmp += distance;
    }// end for loop i
    duration = tmp/speed;
    return duration;

void Trip::setTrip(vector<string> cities)
    trip = cities;      

By purchasing this solution you'll be able to access the following files:

50% discount

$40.00 $20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats