Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 15th, 2006, 12:50 AM   #1
pastalover
Newbie
 
Join Date: May 2006
Posts: 11
Rep Power: 0 pastalover is on a distinguished road
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.
pastalover is offline   Reply With Quote
Old May 15th, 2006, 2:14 AM   #2
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Old May 15th, 2006, 2:15 AM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
....................
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old May 15th, 2006, 2:43 AM   #4
pastalover
Newbie
 
Join Date: May 2006
Posts: 11
Rep Power: 0 pastalover is on a distinguished road
anybody other than bloodninja??

i need u to teach me
pastalover is offline   Reply With Quote
Old May 15th, 2006, 2:47 AM   #5
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
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.
Jimbo is offline   Reply With Quote
Old May 15th, 2006, 2:59 AM   #6
pastalover
Newbie
 
Join Date: May 2006
Posts: 11
Rep Power: 0 pastalover is on a distinguished road
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
pastalover is offline   Reply With Quote
Old May 15th, 2006, 3:13 AM   #7
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
so, for iii you should probably just have something like
int firstClass[5] = {0};
int economy[5] = {0};
// or
int seats[10] = {0};
then as you add seats, you set the corresponding index in the corresponding array to 1 (check if it is a 1 first). If the whole array (or section) is filled with 1s, then that seating section is full; so you ask if it's ok to check the other section. Then you check the 2nd section. If it's full, then the whole plane is full, and you output accordingly.
Jimbo is offline   Reply With Quote
Old May 15th, 2006, 8:32 AM   #8
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC