Answer to Question #227454 in C++ for Sandile

Question #227454
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-08-19T03:22:19-0400
#include <iostream>
using namespace std;


class Bus
{
public:
	Bus() {};


	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);
	}
	float payments{ 0 };
	int count_stop{ 7 };
	static const int places = 60;
	int passenger[places] = {};
private:
};

int main()
{
	// example of program execution
	Bus bus_example;
	bus_example.move_bus();
	cout << "Total revenues: "<<bus_example.payments;
	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