473,385 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Write a seating reservation program

C&M Airlines (Charlie and Mable) operates a small commuter airline with a single plane
that seats 12 passengers. The plane makes one flight per day. Write a seating reservation
program as described.

The passenger information is stored in an array of 12 structures. This array should be
maintained in the main() function. Each structure holds the seat ID, a marker that
indicates if the seat has been assigned, a passenger first name and a passenger last name.

__________________________________________________ __
(this is what i have, but im completely stomped. Please help)
#include "stdafx.h"
#include <string.h>

void menu();
void showEmptySeats();

int _tmain(int argc, _TCHAR* argv[])
{


typedef struct
{
char firstname[21];
char lastname[20];
int id;
int taken;
} info;


info airplane[12];
menu();

return 0;
}

void menu()
{


char choice[10];


printf("a.) Show number of empty seats\nb.) Show list of empty seats\nc.) Assign a seat\nd.) Delete a seat assignment\ne.) Quit\n\nPlease choose an option: ");
scanf("%s", choice);

/* Execute function */
if(strcmp("a",choice)==0) showEmptySeats();
else if(strcmp("b",choice)==0) printf ("b");
else if(strcmp("c",choice)==0) printf ("c");
else if(strcmp("d",choice)==0) printf ("d");
else if(strcmp("e",choice)==0) printf ("e");
}


void showEmptySeats()
{

};
Apr 17 '14 #1
3 12011
weaknessforcats
9,208 Expert Mod 8TB
Where is your main()?

It looks like menu() is really your main().

Get what you have to compile.

Then implement one choice, like display the empty seats.
Get that to work and then work on another choice. You should be able to out this together piecemeal just fine.

Post again.
Apr 17 '14 #2
Alright so i just typed this up w/ my roomate and it somewhat works but i think the calculations are wrong. Please help me make it smoother and better... Using Visual Studios

Expand|Select|Wrap|Line Numbers
  1. #include "StdAfx.h"
  2. #include <iostream> 
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int assignSeat(int seat_num, int row_num, int pass_num);
  8. int num1(char*);
  9. int num2(char*);
  10.  
  11.  
  12. int NumSeats = 12;
  13.  
  14. void Reserve();
  15. void Cancel();
  16. void ChangeSeat();
  17. void Display();
  18. void InitializeSeats();
  19.  
  20. struct Seat 
  21.   {
  22.       char pass_name[20];
  23.       int Available;
  24.   };
  25.  
  26.   struct Seat SeatArray[6][2];
  27.  
  28. int main()
  29. {      
  30.    char seatchioce = 0;
  31.    int row_num = 6;
  32.    char a = 0;
  33.    char w = 0;
  34.  
  35.   int total_passenger = 12;
  36.  
  37.   char arr1[][6] = {"A","A","A","A","A","A"};
  38.   char arr2[][6] = {"B","B","B","B","B","B"};
  39.  
  40.   int MenuChoice;
  41.  
  42.   InitializeSeats();
  43.   while(1)
  44.   {
  45.       cout << " 1. Reserve a seat" << endl;
  46.       cout << " 2. Cancel a seat" << endl;
  47.       cout << " 3. Change a Seat" << endl;
  48.       cout << " 4. Display empty seats" << endl;
  49.       cout << " 5. Exit" << endl;
  50.  
  51.       cout << "Enter your choice: ";
  52.       cin >> MenuChoice;
  53.  
  54.     if((MenuChoice < 0) && (MenuChoice > 5))
  55.     {
  56.       cout << "Invalid" << endl;
  57.  
  58.     }
  59.     else
  60.     {
  61.         switch(MenuChoice)
  62.         {
  63.             case 1: Reserve();
  64.                 break;
  65.             case 2: Cancel();
  66.                 break;
  67.             case 3: ChangeSeat();
  68.                 break;
  69.             case 4: Display();
  70.                 break;
  71.             case 5:
  72.                 exit(1);
  73.         }
  74.     }
  75.     cin.get();  
  76.   }
  77.  
  78. return 0; 
  79.  
  80. }
  81. void Reserve() /*reserve the seats*/
  82. {
  83.     int pass_num = 0;
  84.  
  85.      cout << "All " << NumSeats << " seats are available " << endl;
  86.  
  87.      for(int i = 0; i < 6; i++)
  88.      {
  89.          for(int j = 0; j < 2; j++)
  90.          {
  91.              if(SeatArray[i][j].Available == 1)
  92.              {
  93.                  cout << "Please enter the passenger name: ";
  94.                  cin >> SeatArray[i][j].pass_name;
  95.                  SeatArray[i][j].Available = 0;
  96.                  NumSeats--;
  97.                  return;
  98.              }
  99.          }
  100.  
  101.      }
  102. }
  103. void Cancel()/*Cancel the seat*/
  104. {
  105.     char CancelPassengerName[20];
  106.  
  107.     cout << "Enter the Passenger to be cancelled: ";
  108.     cin >> CancelPassengerName;
  109.     for(int i =0; i <6; i++)
  110.     {
  111.         for(int j=0; j<2; j++)
  112.         {
  113.  
  114.             if(strcmp(SeatArray[i][j].pass_name, CancelPassengerName) == 0) 
  115.             {
  116.                 NumSeats++;
  117.                 SeatArray[i][j].Available = 1;
  118.                 return;
  119.             }
  120.         }
  121.     }
  122.     cout << " Passenger not in the list" << endl;
  123. }
  124. void ChangeSeat()/*Change the seat*/
  125. {
  126.     char MovePassenger[20];
  127.     int SeatRow, SeatColumn;
  128.  
  129.     cout << "Enter the passenger name to be moved: ";
  130.     cin >> MovePassenger;
  131.  
  132.     for(int i = 0; i < 6; i++)
  133.     {    for(int j = 0; j < 2; j++)
  134.         {
  135.             if(strcmp(SeatArray[i][j].pass_name, MovePassenger) == 0) 
  136.             {
  137.                 SeatRow = i;
  138.                 SeatColumn = j;
  139.             }
  140.         }
  141.     }
  142.  
  143.     if(NumSeats <= 0)
  144.     {
  145.         cout << "Seat unavailable" << endl;
  146.         return;
  147.     }
  148.     else{
  149.         for(int i = 0; i < 6; i++)
  150.         {
  151.             for(int j = 0; j < 2; j++)
  152.             {
  153.                 if(SeatArray[i][j].Available == 1)
  154.                 {
  155.                     strcpy_s(SeatArray[i][j].pass_name, MovePassenger);
  156.                     SeatArray[SeatRow][SeatColumn].Available = 1;
  157.                     SeatArray[i][j].Available = 0;
  158.  
  159.                     return;
  160.                 }
  161.             }
  162.         }
  163.     }
  164. }
  165. void Display()/*Display the seat assingment*/
  166. {
  167.     for(int i = 0; i < 6; i++)
  168.     {
  169.         for(int j = 0; j < 2; j++)
  170.         {
  171.             if(SeatArray[i][j].Available == 0)
  172.             {
  173.                 cout << SeatArray[i][j].pass_name << " = " << NumSeats << endl;
  174.             }
  175.             else
  176.             {
  177.                 if(j == 1)
  178.                     cout << i+1 << "B" << endl;
  179.                 else
  180.                     cout << i+1 << "A" << endl;
  181.             }
  182.         }
  183.     }
  184. }
  185.  
  186. void InitializeSeats()/*all available seats*/
  187. {
  188.     for(int i = 0; i < 12; i++)
  189.     {
  190.         for(int j = 0; j < 2; j++)
  191.             SeatArray[i][j].Available = 1;
  192.     }
  193. }
  194.  
  195.  
Apr 17 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. #include "StdAfx.h"
  2.  
can be avoided by creating a console application rather than a Windows console application:

1)create a Win32 project
2)when the wizard appears, do not click finish
3)instead click application settings
4)select console application, select empty project
5)click finish.

This code:
Expand|Select|Wrap|Line Numbers
  1. struct Seat SeatArray[6][2];
can be a one dimensional array of 12. The seat mapping does not have to match the actual aircraft. Maybe odd number elements are A (1,3,5,7,9,11) and even number elements are B (0,2,4,6,8,10). But what you have still works.

This code:
Expand|Select|Wrap|Line Numbers
  1. char arr1[][6] = {"A","A","A","A","A","A"};
  2. char arr2[][6] = {"B","B","B","B","B","B"};
  3.  
does not appear to be used.

This code:
Expand|Select|Wrap|Line Numbers
  1. if((MenuChoice < 0) && (MenuChoice > 5))
  2.     {
  3.       cout << "Invalid" << endl;
  4.      
  5.     }
  6.     else
  7.     {
  8.         switch(MenuChoice)
  9.         {
  10. etc...
  11.  
looks like the default case of the switch.

There are several other things of a lesser nature but the overall construction looks sound.

What is it, exactly, that constitutes a wrong calculation?
Apr 17 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: gswork | last post by:
Let's write a c program, without knowing what it does... Some of you may recall Jim Roger's excellent series of posts (on comp.programming) exploring the implementation of common software...
37
by: Spidey | last post by:
How can to write a c program without a main() so i can compile and run it
23
by: Ed Zagmoon | last post by:
I want to write a program that can kill people in C. Something that will display flashing colors or fractal pictures that will overload the brains of my victims so that they die. But, how can I...
4
by: patsandy | last post by:
Hi, I am Patricia and I would like to get some assistance to write a Program in C. Your help would be greatly appreciated. The Program must calculate how long it takes to fly from one place...
4
by: Break2 | last post by:
I am trying to write a simple program which asks a user to enter 5 integers after which the average will be computed and written to the screen. That simple. However I want to do it according to a...
11
by: 960392954 | last post by:
The Towers of Hanoi is a famous problem about moving a certain number of disks from one peg to another.I write a recursive program for it.If you have known it ,you can skip the program. #include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.