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.
#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;
}
Comments
Leave a comment