GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Aug-2004, 12:43
Casarik Casarik is offline
New Member
 
Join Date: Aug 2004
Posts: 1
Casarik is on a distinguished road

C++ coding problem


I'm trying to create a program that is like a airplane seating chart which lists the seats available for reservation and tells the user to choose a seat to reserve. After the user choose a seat, it is suppose to update the chart and place an X on the seats that are now unavailable. I am having trouble creating the code for the update section. Here is what i have so far:

CPP / C++ / C Code:
#include <iostream>
#include <string>

using namespace std;

class seating
{
char chart[8][4];
public:
char choice[2];

seating()
{
for(int i=0;i<8;i++)
{
chart [i][0]='A';
chart [i][1]='B';
chart [i][2]='C';
chart [i][3]='D';
}
}

void getchoice()
{
cout << endl << "Please enter the seat to reserve (enter x to exit): ";
cin >> choice;
}

void updatechart()
{
int row, seat;
bool goodseat;

cout<<endl<<"Updating..."<<endl;
}

void showchart()
{
cout<<endl;

for(int i=0;i<8;i++)
{
cout<<i+1<<" ";
cout<<chart [i][0]<<" ";
cout<<chart [i][1]<<" ";
cout<<chart [i][2]<<" ";
cout<<chart [i][3];
cout<<endl;
}
}
};

int main()
{
seating s;

s.showchart();
s.getchoice();

while(s.choice[0]!='x')
{
s.updatechart();
s.showchart();
s.getchoice();
}

cout<<endl<<"Thank you and good bye.";
cout<<endl<<endl;

return 0;
}

Any help would be appreciated. Thanks in advance.
Last edited by dsmith : 16-Aug-2004 at 13:31. Reason: Please use [c] & [/c] for syntax highlighting
  #2  
Old 16-Aug-2004, 13:42
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello Casarik. How about something that makes use of the ASCII values of the characters entered?

CPP / C++ / C Code:
void updatechart()
{
int row, seat;
bool goodseat;

cout<<endl<<"Updating..."<<endl;
row = choice[0]-49;
seat = toupper(choice[1])-65;


if(chart[row][seat] == 'X')
	cout<<"That seat is taken!\n";
else
	chart[row][seat] = 'X';
}

That does absolutely no bounds checking though.


HTH,
d
  #3  
Old 21-Aug-2004, 20:47
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
first off your getchoice function isn't going to work

you have choice[2] declared and then you try to store a value into simply choice. You need to declare which spot your going to assign the value to (either choice[0] or choice[1]). Next the user is gonna enter thier choice as something along the lines of 1A which, and I'm not sure about this (someone can either back me up or correct me) means your gonna have to store the 1 in an int variable and then type cast it to a char.

now once you get that fixed I would just have updatechart() simply put an X in the chart[][] array.Something like:

CPP / C++ / C Code:
void updatechart()
{
     int row = choice[0];
     int seat = choice[1];

     chart[row][seat] = 'X';
}
or if you don't want to make chart public you can make an array that hold which seats are taken and during you showchart() function check for seats already taken.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mpeg2 SVCD disc problem mrnobody Computer Software Forum - Windows 0 13-Aug-2004 08:51
C I/O problem kelly80 C Programming Language 4 27-Apr-2004 20:15
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 20:48
RE: A simple update and } problem Dagma20 MySQL / PHP Forum 3 27-Mar-2004 16:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.