C++ Data Managment Assignment

About the client

United States

Posted on Apr 01, 2013 / Est. budget $ 50 / Project closed

Awarded winner(s):

Achuks

Click to see the freelancer contact details

/* Page One */
Program Description

Your program will display (see the sample output) the following menu at startup and will continue to do so, after it executes the user's choice to add, delete or show passengers, until the user chooses exit, which of course exits the program.

Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice:

The program maintains two lists, which as explained below are both queues. The first is for booked passengers. Since the plane has only 3 seats for passengers, only 3 passengers can be on this list. The second is the waiting list. GenghisAir's policy is not to have more than 3 customers on the waiting list; anyone else is told to try again later.

Adding

You add a customer to the list of booked passengers unless that list is full (3 booked passengers). If it is, then you add the customer to the waiting list unless that list also is full (maximum size of waiting list is 3). If so, you tell the customer sorry, try again later. Each passenger is added in order.

Deleting

If there are any booked passengers, then you delete the first passenger on that list. Next, if there are any customers on the waiting list, you add the first customer on the waiting list to the list of booked passengers, and of course take that customer off the waiting list.

If there are no booked passengers, then there is no one to delete (if there are no booked passengers there can't be any customers on the waiting list).

Showing a Passenger

See the sample output. If there are any booked passengers, then you list them in order. You then list in order any customers on the waiting list unless there are none, in which case you advise there is no one on the waiting list.

If there are no booked passengers, then there is no one to show (if there are no booked passengers there can't be any customers on the waiting list), so you advise there are no booked passengers.

Queue Class

Both the booked passenger list and the waiting list are queues. Since deletions are permitted, each queue will be implemented by a circular or ring queue. This concept is explained in the book and in Module #4 (Queue).

You will write the queue as a class. Module #4 (Queue) explains the member variables and member functions, including a constructor.

Files

The class will be written using header and implementation files. Your program also will include a driver file, so your multi-file project will have these three files and no others:

File Name Purpose
cqueue.h Header file for queue
cqueue.cpp Implementation file for queue
test.cpp Driver file

Your Job

The code/output handout provides all the code for the cqueue.h file (except the value of one constant) and the test.cpp file except the implementation of the add, delete and show functions. Your job is to complete those two files and write the cqueue.cpp file.


/* Second Page */
This handout provides all the code for the cqueue.h file except the value of one constant and the test.cpp file except the implementation of the add, delete and show functions. As explained in the assignment, your job is to complete those two files and write the cqueue.cpp file. Finally, this handout provides sample output.



1. cqueue.h

const int MAX = ??; //To do: determine appropriate number

struct Passenger {
char name[80];
};

class CQueue {
private:
int front;
int rear;
Passenger passengers[MAX];



public:
CQueue();
bool IsEmpty(void);
bool IsFull(void);
void Enqueue(Passenger);
Passenger Front(void);
void Dequeue(void);
};



2. test.cpp

#include
#include
#include "cqueue.h"
using namespace std;

enum choice { BOOKED, WAITING };
const int LINES = 2;
int showMenu(void);
void addPassenger(CQueue*);
void deletePassenger(CQueue*);
void showPassengers(CQueue*);

int main (void)
{
CQueue qPassengers[LINES];
int x;
do{
x = showMenu();
switch (x)
{
case 1: addPassenger(qPassengers);
break;
case 2: deletePassenger(qPassengers);
break;
case 3: showPassengers(qPassengers);
break;
}
} while (x != 4);

return 0;
}

int showMenu(void)
{
int select;

cout << "Menun";
cout << "========n";
cout << "1. Add Passengern";
cout << "2. Delete Passengern";
cout << "3. Show Passengersn";
cout << "4. Exitn";
cout << "Enter choice: ";
cin >> select;
return select;
}



// To do: implement addPassenger, deletePassenger and showPassengers



3. Sample Output



Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
No passengers
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 2
No passengers to delete
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Jeff
Booking Jeff on flight
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
Booked Passengers
=================
Jeff
No passengers on waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Mikhail
Booking Mikhail on flight
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Ivan
Booking Ivan on flight
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
Booked Passengers
=================
Jeff
Mikhail
Ivan
No passengers on waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Waiter
Sorry. Plane fully booked. Adding Waiter to waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
Booked Passengers
=================
Jeff
Mikhail
Ivan
Waiting list
=================
Waiter
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 2
Removing Jeff from booked passengers
Adding Waiter from waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
Booked Passengers
=================
Mikhail
Ivan
Waiter
No passengers on waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Fred
Sorry. Plane fully booked. Adding Fred to waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Dead
Sorry. Plane fully booked. Adding Dead to waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Enter name: Foodita
Sorry. Plane fully booked. Adding Foodita to waiting list
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 3
Booked Passengers
=================
Mikhail
Ivan
Waiter
Waiting list
=================
Fred
Dead
Foodita
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit
Enter choice: 1
Sorry. Plane and waiting list fully booked. Try later
Menu
========
1. Add Passenger
2. Delete Passenger
3. Show Passengers
4. Exit

Enter choice: 4
Press any key to continue

Project bids (3)

Bids are visible only by project owner and Premium members.