Answer to Question #185959 in C++ for shuvo

Question #185959

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-29T05:41:11-0400
#include <iostream>


using namespace std;


#define FOOT_TIME 17
#define BUS_TIME 13


int main()
{
    string route, rush, time;
    cout << "Time on foot on the way: " << FOOT_TIME << endl;
    cout << "Time by bus on the way: " << 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 tmp;
    for(int i = 0; i < 5; ++i)
    {
        if(i < 2)
        {
            tmp = (int)rush[i] - '0';
            rushTime[0] += tmp;
            tmp = (int)time[i] - '0';
            nowTime[0] += tmp;


        }
        else if(rush[i] == ':')
                continue;
        else
        {
            tmp = (int)rush[i] - '0';
            rushTime[1] += tmp;
            tmp = (int)time[i] - '0';
            nowTime[1] += tmp;
        }
    }
    if(route == "onfoot")
        cout << "Time on the way is 17 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 13 mins, you haven't got into jam!" << endl;
    else
        cout << "Time on the way is less than 13 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