hi guys, I've been working on this program and I am kind of lost. Please help me point out what i am doing wrong. this is the description of the program.


You are to code a plane reservation application, which allows the user to keep track of seat reservations.

Seat Information

Your program must keep track of 25 seats on the plane. The seats are numbered from 0 to 24. Seats are numbered from front to back of the plane, that is, seat 0 is at the front, and seat 24 is at the back. All seats are originally empty, and are reserved one at a time. Given a particular seat number, it must be possible to determine if the seat is empty or reserved. Your program should use a constant to specify the number of seats, so that the program can be easily adjusted for a different number of seats.

Functions:

Your program is to provide the following functions:

bool isFull(int seats[], int size)
Effect: determines if all plane seats are full
Returns: true if all seats are full, false otherwise

bool isEmpty (int seats[], int size)
Effect: determines if all plane seats are empty
Returns: true if all seats are empty, false otherwise

int seatsLeft(int seats[], int size)
Effect: determines the number of empty seats remaining
Returns: the number of empty seats in the plane

bool validSeatNum(int seatNo)
Effect: determines if seatNo is a valid number for this plane
Returns: true if seatNo is a seat on this plane, false otherwise

bool seatVacant(int seats[], int size, int seatNo)
Effect: determines if seatNo is an available seat
Precondition: seatNo is a valid seat number

void reserveSeat(int seats[], int size, int seatNo)
Effect: reserves the seat numbered ‘seatNo’
Precondition: seat is vacant
Postcondition: seat #seatNo is now filled

void cancelSeat(int seats[], int size, int seatNo)
Effect: unreserves the seat numbered ‘seatNo’
Precondition: seat had been reserved
Postcondition: seat #seatNo is now available

int furthestFront(int seats[], int size)
Effect: finds the front-most available seat
Precondition: the plane is not full
Returns: the number of the seat

int furthestRear(int seats[], int size)
Effect: finds the rear-most available seat
Precondition: the plane is not full
Returns: the number of the seat

The main function

You are to write a main function which:

• Declares an array which keeps track of each seat

• Allows the user to enter a command indicating which of the following operations he/she wishes to perform (user can enter commands until he/she wishes to exit)
* check if all seats are full
* check if all seats are empty
* reserve a particular seat by number, if available
* reserve a seat furthest to the front
* reserve a seat furthest to the rear
* cancel a particular seat reservation
* print out all information on all seats

below is my code. Thank you.

#include "stdafx.h"
#include <iostream>
#include <iomanip> 

using namespace std;


bool isFull(int seats[], int size);
bool isEmpty(int seats[], int size);
int seatsLeft(int seats[], int size);
bool validSeatNum(int seatNo);
bool seatVacant(int seats[], int size, int seatNo);
void reserveSeat(int seats[], int size,int seatNo);
void cancelSeat(int seat[], int size, intseatNo);
int furthestFront(int seats[], int size);
int furthestRear(int seats[], int size);

int main ()
{
	const int size = 25;
	char choice;

	cout << setw(10) << "1. Check if all seats are full" << endl;
    cout << setw(10) << "2. Check if all seats are empty" << endl;
    cout << setw(10) << "3. reserve a particular seat by number if available" << endl;
	cout << setw(10) << "4. reserve a seat furthest to the front" << endl;
	cout << setw(10) << "5. reserve a seat furhtest to the rear" << endl;
	cout << setw(10) << "6. cancel a particular reservation" << endl;
    cout << setw(10) << "7. print out all information on all seats" << endl;

//Prompt User for choice.

    cout << setw(10) << "Enter your choice (1-7)" << endl; 
    cin >> choice;
	cout << endl;
	
	switch (choice)
	{

	case '1': bool isFull(int seats[], int size) 
			  {
				int answer = true;
				for (int index = 0; index < size; index++)
				{
					if (seats[index] == false)
					answer = false;
				}
				return answer;
				}	
			  break;

	case  '2': bool isEmpty (bool seats[], int size) 
			   {
				   bool answer = true;
				   for (int index = 0; index < size; index++)
				   {
					   if (seats[index] == true)
					   answer = false;
				   }
				   return answer;
				}	
			   break;

	case '3': reserveSeat(int seats[], int size,int seatNo);
			  break;

	case '4': int furthestFront(int seats[], int size) 
			  {
				  int index, answer;
				  if (!isFull(seats, size))
				  {
					  for (index = 0; index < size; index++)
					  {
						  if (seats[index] == false)
						  {
							  answer = index + 1;
							  return answer;
						  }
					  }
				  }
				  else
				  {
					  cout << "All seats are reserved.\n";
					  return 0;
				  }
			  }
			  break;
	case '5':int furthestRear(int seats[], int size) 
			 {
				 int index, answer;
				 if (!isFull(seats, size))
				 {
					 for (index = size - 1; index >= 0; index--)
					 {
						 if (seats[index] == false)
						 {
							 answer = index + 1;
							 return answer;
						 }
					 }
				 }
				 else
				 {
					 cout << "All seats are reserved.\n";
					 return 0;
				 }
			 }
			 break;

	case '6': cancelSeat(int seats[], int size, int seatNo);
			  break;

	case '7': int index, seat;
		      cout << "Current seating status...\n";
			  for (index = 0; index < size; index++)
			  {
				  seat = index + 1;
				  cout << "Seat #" << seat;
				  if (seats[index] == false)
					  cout << " -- Empty\n";
				  else
					  cout << " -- Reserved\n"; 
			  }

			  break;

	}

	return 0;
	}

void reserveSeat(int seats[], int size, int seatNo)
	{
	int index = seatNo - 1;
	if (seatVacant(seats, size, seatNo))
		{
		seats[index] = true;
		cout << "Seat #" << seatNo << " is now reserved.\n";
		}
	else
		cout << "That seat is already reserved.\n";
	}
   

void cancelSeat(int seats[], int size, int seatNo)
	{
	int index = seatNo -1;
	if(!seatVacant(seats, size, seatNo))
		{
		seats[index] = false;
		cout << "The reservation for Seat #" << seatNo << " is now canceled.\n"; 
		}
	else
		cout << "That seat is already empty.\n";
	}
This article has been dead for over six months. Start a new discussion instead.