AllExperts > Experts 
Search      

Pascal

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Pascal Answers
Question Library

Ask a question about Pascal
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Nikolai Kolev
Expertise
I can answer quetions about dynamic and static structures. I can find errors in programs. I can give you ideas about solving problems.

Experience
I have studied Pascal for 8 years. I'm a professional who is very experienced.

 
   

You are here:  Experts > Computing/Technology > Pascal > Pascal > Turbo pascal problem....

Topic: Pascal



Expert: Nikolai Kolev
Date: 2/15/2006
Subject: Turbo pascal problem....

Question
-------------------------
Followup To
Question -     Will I use any functions or procedures. When choosen seat(s) are taken it should mark "X" in those specific place. What is the use of true and false in that code hints you have give to me.
    Please, for the second time give me those. Pls.......
-------------------------
Followup To
Question -
    Please give just the format on how to use 2 dimensional arrays,case statement and give me the step-by-step hint on how to do it.
    What do you mean in your phrase" In the beginning init?".
    I'm hoping that you could send me the things I need stated above....
    Thanks.....
    
  
    I have a Pascal problem and I want you to please help me get the correct answer of it. I know that you had help all who got some Pascal problems because you have a great knowledge on it. My problem is stated below:

    Write a program to assign passenger seats in an airplane. Then lets the user to choose a seat or seats he desired. And just assume a small airplane with seats numbered as follows:
1   A   B   C   D
2   A   B   C   D
3   A   B   C   D
4   A   B   C   D
5   A   B   C   D
6   A   B   C   D
7   A   B   C   D

    After the user enter his choosen seat(s) the program should display the seat pattern, marking with an '' X '' the seats 1A , 2B, 3C and 4D are taken, the display  should look like this:

1   X   B   C   D
2   A   X   C   D
3   A   B   X   D
4   A   B   C   X
5   A   B   C   D
7   A   B   C   D

    I hope that you could send me a response with the pascal code I needed. I'll treasure your kindness  and cherish it .

          Thanks in advance........

Dennis Mejos
Southern Christian Colloge
Student
Answer -
Hi,

I can give you some hint how to solve your problem, but I won't send you the code - the purpose is to learn how to program it, not just copy-paste.

You should use 2 dimensional array of boolean values to store the taken and empty places. In the begining init the values in the array to false (all seats are empty). Then ask the user to input an integer for a row and a char for the specific place. For the char you should use case statement to determine the number. After that mark the chosen seat as true (it's taken) and that is it!:)

If you have any other questions please ask.
Answer -
1. Here is how to declare the array:
var
 data: array[1..7, 1..4] of boolean;

2. Here is a way to initialize (init) it:

for i := 1 to 7 do
for j := 1 to 4 do
 data[i, j] = false;

3. Here is how to use the case statements:
Let's assume the user's input is stored in the "seat" variable.
case seat of
 'A': j := 1;
 'B': j := 2;
 'C': j := 3;
 'D': j := 4;
end;
Then you can set the selected row and seat to true: data[i, j] := true; //Where i is variable that stores the selected by the user row.

That's it:) - it's really simple.

Answer
Well, when you print the info for the seats you must check whether that position in the array is true or false and display the appropriate symbol (X or A through D). Here is a sample code:
for i := 1 to 7 do
for j := 1 to 4 do
 if data[i, j] then
 begin
   write('X');
 end else
 begin
  //a case statements to display A through D
 end;

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.