turbo pascal question

pts.
Tags:
Pascal
Pl. somebodyhelp me solve this hobby of mine answering programming book exercises, particularly pascal programming. I'm not expert to this field but I'm trying to study it myself, I have answered few pascal problems alone but here comes this one problem that I cannot do, so pls any kindhearted one to help me solve this one? Here it is: Write a program to aassign passenger seats in an airplane. 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 Then lets the user to input his desired seat(s). Then the program should display the seat pattern, marking with an 'X' the seats already chosen, taken or assigned. For example, after seats 1A, 2C, 3B, 4D, 5B, 6D and 7A are taken, the display should look like this: 1 X B C D 2 A B X D 3 A X C D 4 A B C X 5 A X C D 6 A B C X 7 X B C D I would greatly appreciate those who can give me the code of this problem. Thanks in advance to kindharted YOU!!!

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is my answer:

Program PassengerSeats;
Uses Crt;
Var Seat: array[1..4, 1..7] of boolean;
I, J: integer;
Number: integer;
Word: char;

Begin
ClrScr; TextColor(15);
Writeln(‘ Wellcome. The seats are numbered as follows:’);
Writeln;
Writeln(‘ 1 A B C D’);
Writeln(‘ 2 A B C D’);
Writeln(‘ 3 A B C D’);
Writeln(‘ 4 A B C D’);
Writeln(‘ 5 A B C D’);
Writeln(‘ 6 A B C D’);
Writeln(‘ 7 A B C D’);
Writeln;
Write(‘ Please chose your seat (Example: 2B ) ‘);

For I := 1 to 7 do
For J := 1 to 4 do Seat[J,I] := False;

Repeat

Word := ReadKey; GoToXY(40,11); write(‘ ‘); GoToXY(41,11);
Write(Word);

Case Word of
’1′: Number := 1;
’2′: Number := 2;
’3′: Number := 3;
’4′: Number := 4;
’5′: Number := 5;
’6′: Number := 6;
’7′: Number := 7;
char(27): Halt(1);
end;

Word := Upcase(ReadKey); Writeln(Word); Writeln;

For I := 1 to 7 do
begin
if (Number = I) and (Word = ‘A’) then Seat[1,I] := True;
if (Number = I) and (Word = ‘B’) then Seat[2,I] := True;
if (Number = I) and (Word = ‘C’) then Seat[3,I] := True;
if (Number = I) and (Word = ‘D’) then Seat[4,I] := True;
end;

TextColor(2);

For I := 1 to 7 do
begin
if (Number = I) and (Word = ‘A’) then
begin
GoToXY(4,I+2); Write(‘X’);
end;
if (Number = I) and (Word = ‘B’) then
begin
GoToXY(6,I+2); Write(‘X’);
end;
if (Number = I) and (Word = ‘C’) then
begin
GoToXY(8,I+2); Write(‘X’);
end;
if (Number = I) and (Word = ‘D’) then
begin
GoToXY(10,I+2); Write(‘X’);
end;
end;
TextColor(15);

Until Word = char(27)
End.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Saadkahn
    Can you please tell me how to write a code.I am new to it.
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following