Answer to Question #185974 in C++ for shuvo

Question #185974

Consider a flow chart for computing travel time between Wall Street in Manhattan and St. John’s University. Write a code fragment that represents this flow chart. Assume that there are variables called route and rush hour of type string.


1
Expert's answer
2021-04-29T19:02:22-0400
#include <iostream>

using namespace std;

#define FOOT_TIME 23
#define BUS_TIME 11

int main()
{
    string route, rush, time;
    cout << "Time on foot: " << FOOT_TIME << endl;
    cout << "Time by bus: " << BUS_TIME << endl;
    cout << "Enter the rush(hh:mm): ";
    cin >> rush;
    cout << "Enter the route:('onfoot' or 'bybus'): ";
    cin >> route;
    cout << "Enter the now time(hh:mm)";
    cin >> time;
    int rushTime[] = {0, 0};
    int nowTime[] = {0, 0};
    int temp;
    for(int i = 0; i < 5; ++i)
    {
        if(i < 2)
        {
            temp = (int)rush[i] - '0';
            rushTime[0] += temp;
            temp = (int)time[i] - '0';
            nowTime[0] += temp;

        }
        else if(rush[i] == ':')
                continue;
        else
        {
            temp = (int)rush[i] - '0';
            rushTime[1] += temp;
            temp = (int)time[i] - '0';
            nowTime[1] += temp;
        }
    }
    if(route == "onfoot")
        cout << "Time on the way is 23 mins, jams were ignored!" << endl;

    if(abs(rushTime[0] - nowTime[0])*60 + abs(rushTime[1] - nowTime[1]) >= 13 && route == "bybus")
        cout << "Time on the way is 11 mins, you haven't got into jam!" << endl;
    else
        cout << "Time on the way is less than 11 mins, you've got in jam! " << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS