![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 11
Rep Power: 0
![]() |
can anybody help me?
hello everybody..
i am a new user of C language.i need to learn something about array.i get this question from my friend.anybody wish to help me?i have tried it,but there were errors..i really have no idea how to solve this question.here is the question...>> A small airline has just purchased a computer for its new automated reservation system. Since you are an expert, the president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for “first class” Please type 2 for “economy” If the person types 1, then your program should assign a seat in the first class section (seats 1 – 5). If the person types 2, then your program should assign a seat in the economy section (seats 6 – 10). Your program should then print a boarding pass indicating the person’s seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available. Your program should never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vise versa). If yes, then make the appropriate seat assignment. If no, then print the message “Next flight leaves in 3 hours.” here is my coding: #include <stdio.h> int main() { char answer; int i,j; int firstClass[5]={1,2,3,4,5,}; int economy[5]={6,7,8,9,10}; printf("Please type 1 for 'first class' "); printf("Please type 2 for 'economy' "); scantf("%c",&answer); if(answer='1') printf("Your seat number is %d and %c.",firstClass[i],first class); if(answer='2') printf("Your seat number is %d and %c.,economy[j],economy") } Last edited by pastalover; May 15th, 2006 at 1:10 AM. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
hey, next time, enclose your code in these tags...
[**code**] and then [**/code**] at the end, otherwise people will bitch. that said, your problem is very simple, but i am fucked up and cannot fix it right now. sorry... ignore the asterisks
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
....................
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: May 2006
Posts: 11
Rep Power: 0
![]() |
anybody other than bloodninja??
i need u to teach me |
|
|
|
|
|
#5 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3
![]() |
We'll help you with specific problems, but we won't do your homework for you. What you should probably do is just sit down and write out the steps needed to for your program to do. Then try to convert what you've written to code. At least show us that you've tried to solve the entire thing. Then if you have problems with something specific, we'll try to help.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2006
Posts: 11
Rep Power: 0
![]() |
i already done half of the coding.
basically these are the requirement of the project: i.) first,user must enter no. 1>for first class flight or 2>for economy flight from that the system will assign the thing that will fix the needs. ii.) if the person type 1, then the program will assign seat (1-5) if the person type 2, then the program will assign seat (6-10) iii.) Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available. iv.) it should not assign a seat that has already been assigned.if first class is full program should ask the person if it is acceptable to be placed in the economy section the problem are i cannot do the step no. iv and v |
|
|
|
|
|
#7 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3
![]() |
so, for iii you should probably just have something like
int firstClass[5] = {0};
int economy[5] = {0};
// or
int seats[10] = {0}; |
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Well usually we like you to do it and we help with specific problems, because we want you to learn the most. But very rarily we help out with a whole program, plus sometimes examples can teach one a whole lot...
#include <stdio.h>
int main()
{
char answer = 0;
int i, start, end, seat = 0, tclass = -1, found = 0;
int seats[10] = {0};
for(;;)
{
do
{
printf("Please type 1 for 'first class'\n");
printf("Please type 2 for 'economy class'\n");
printf("Please type anything else to quit: ");
rewind(stdin);
}
while(scanf("%c", &answer) != 1);
if(answer == '1' || answer == '2')
{
if(answer == '1')
{
tclass = 0;
start = 0;
end = 5;
}
else
{
tclass = 1;
start = 5;
end = 10;
}
for(i = start; i < end; i++)
{
if(seats[i] == 0)
{
seat = i;
seats[i] = 1;
break;
}
/* check if seats in current class are taken */
if(i == end - 1)
{
for(i = 0; i < 10; i++)
{
if(seats[i] == 0)
{
/* still a seat free */
found = 1;
break;
}
}
if(!found)
{
printf("Sorry flight is full, next flight leaves in 3 hours.\n\n");
return 0;
}
found = 0;
if(tclass == 0)
{
printf("\nThere is no seat left in first class.\n");
printf("Would you like to get a seat in the economy class?\n");
}
else
{
printf("\nThere is no seat left in the economy class.\n");
printf("Would you like to get a seat in first class?\n");
}
printf("Please type 'y' for yes, anything else for no: ");
rewind(stdin);
scanf("%c", &answer);
if(answer != 'y')
{
printf("Next flight leaves in 3 hours.\n\n");
return 0;
}
/* switch to first class */
if(tclass == 1)
{
tclass = 0;
start = 0;
end = 5;
i = start - 1; /* continue doesn't change for loop */
}
/* switch to economy class */
else
{
tclass = 1;
start = 5;
end = 10;
i = start - 1; /* continue doesn't change for loop */
}
}
continue;
}
printf("Your seat number is %d in %s class\n\n", seat+1, tclass ? "economy" : "first");
}
else
{
printf("Goodbye!\n");
}
}
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|