siabanie banie

siabanie banie

  • NA
  • 68
  • 74.2k

C++ - reserved and cancel seats

Nov 12 2011 10:46 PM
Hi all,

I am new in C++ and trying to do some exercise to be familiar with the language, here I try to implement a program that accepts seat reservation and cancellations for single performance. There are 50 seats (0 to 49)

The program should loop, each loop performing the following steps:
  1. Prompt the user to type either 'a' or 'c' to add or cancel a reservation.
  2. Read keyboard input. If neither 'a' nor 'c' is entered, prompt again.
  3. If 'a' is entered, request the number of seats required. If enough seats are still available, identify the seat(s) to be reserved. Always use the lowest numbered seats available. Print the numbers of the seats allocated along with a reservation number, so that the reservation can be identified later for the purposes of cancellation. If there are not enough seats, print an error message.
  4. If 'c' is entered, request the reservation number and locate the seats reserved under that reservation number. Mark the seats as available again. If the reservation is not found, print an error message.
Extra: when a reservation added, first check whether the seats can be reserved as a single contiguous block.

Here is what I have done so far but - even my print e.g. cout is marking an error? I am not sure if I should use array or const here, which is more appropriate or can I use #define? - Can anyone assist me please.
Thanks.

#include "stdafx.h"

//The seats has 50 seats numbered from 0 to 49
#define MAX_SIZE 49
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  char ac;
  int seatReq;
  int seatRes;
  int resNum;
  do
  {
  do {
    //This prompt the user to type either a (add) c (cancle) the reservation.
    cout <<"Please type either 'a' for add or 'c' for cancel"<<endl;
    //Read keyboard input
    cin>> ac;
  }
  //If neither 'a' or 'c' is entered prompt again
  while (ac !='A' && ac != 'a' && ac !='C' && ac != 'c'); //Keep asking till get valid answer
 
  //If 'a' entered request the number of seats required
  if (ac == 'a' || ac == 'A') {
  cout << "How many seats are required?" <<endl;
  cin>>seatReq;
  cout <<"You are requried "<<seatReq<<" of seat"<<endl;
  //If enough seats are still available, identify the seat(s) to be reserved
  //Use the lowest numbered seated avaiable
  //Print the numbers of the seats allocated along with a reservation number so that the reservation can be indentified later for the
  //purposes of cancellatoin.
  cout <<"Your seats are available and your seats are reseved at "<<seatRes<<endl;
  }
  else
    //If there are not enough seat, print an error message
    cout<<"Sorry your seats are not available"<<endl;
 
  //If 'c' is entered, request the reservation number and locate the seats reserved under that reservation number.
  //Mark the seats as available again.
  //If the reservation if not found, print an error message
  if (ac == 'C' ||ac == 'c') {
    cout <<"Please entered the reservation number"<<endl;
    cin >> resNum;
    cout <<"Your cancellation reservation number is "<<resNum<<endl;
   }
  else
    cout<<"The reservation number"<<resNum<<" is not valid, please try again"<<endl;
  }

  //If valid asnwer repeat again
  while (ac =='a' || ac == 'A' || ac == 'c' || ac == 'C');

  //When a reservation added, first check whether the seats can be reserved as a single contiguous block.
  return 0;
}



Answers (21)