The carwash you are currently working at part time has a nee

The carwash you are currently working at part time has a need to capture each license plate of cars entering the car wash and then display a list of the cars in reverse order so that they can walk from the end of the carwash to the front and be able to sec each car in the list in the order in which they came in. Write a program using the stack ADT that will capture the car license plates as they come in and then display them in reverse order.

Solution

C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   cout << \"Enter Number of cars!\" << endl;
   int n;
   cin >> n;
   int i = 0;
   stack<int> mystack;
   while(i < n)
   {
       int licence;
       cout << \"Enter licence Number!\" << endl;
       cin >> licence;
       mystack.push(licence);
       i++;
   }

i = 0;
   cout << \"car licence Number in reverse order :\" << endl;
   while(i < n)
   {
       int licence;
       licence = mystack.top();
       mystack.pop();
       cout << licence << endl;
       i++;
   }
   return 0;
}

Sample Output:

Enter Number of cars!
5
Enter licence Number!
1
Enter licence Number!
2
Enter licence Number!
3
Enter licence Number!
4
Enter licence Number!
5
car licence Number in reverse order :
5
4
3
2
1

 The carwash you are currently working at part time has a need to capture each license plate of cars entering the car wash and then display a list of the cars i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site