Answer to Question #246597 in C++ for MIMI

Question #246597

In South Africa, Buses are used as one of the main transport servicesfor people in the country.

Everyday, they follow the same route from a particular town/city/shopping complex etc., to

another location point.

Create an application that uses a recursive function to:

Allow the bus driver to accept payments from passengers.

Check every bus stop to ensure that it knows whether or not a passenger should still

be in bus or off.

The system should:

use a recursive function to keep accepting passengers in each bus stop until the

second last stop.

be aware of how many stops are left.

Assume that there are seven bus stops from the starting point to the last point. (excluding the

starting and the last point)


1
Expert's answer
2021-10-04T19:59:25-0400
#include <iostream>

static float payments = 0;
static int count_stop = 7;
static const int places = 60;
static int passenger[places] = {};

using namespace std;

void move_bus(int n = 1)
{
    cout << "Bus stop " << n << endl;
    if (n == count_stop)
    {
        cout << "The bus has completed its journey" << endl;
        return;
    }
    for (int i = 0;i < places; i++) 
    {
        if (passenger[i] <= n)
        {
            passenger[i] = 0;
        }
    }
    cout << "Passengers got off the bus" << endl;
    char choise;
    int pay;
    cout << "Passengers boarding in progress: " << endl;
    for (int i = 0; i < places; i++)
    {
        if (passenger[i] == 0)
        {
            cout << "Are there passengers for boarding? (y/n) ";
            cin >> choise;
            if (choise != 'y') 
            {
                break;
            }
            cout << "What stop does the passenger take ? ";
            cin >> passenger[i];
            cout << "Pay the fare: ";
            cin >> pay;
            payments += pay;
        }
    }
    cout << "Passenger boarding completed" << endl;
    move_bus(n + 1);
}

int main()
{
    move_bus();
    cout << "Total revenues: " << payments << ends;
    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