الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

حل مسئلة حجز المقاعد بالطيارة

مغلق
بدأه tariq2002 في 15 نوفمبر 2001 · 7 رد · 556 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

شباااب هاذا حل السؤال الي طلبت انكم تحلولي اياه ولكن........ http://arabteam.nicmatic.com/vb/showthread...=6282#post24171

هناك اشياء ناقصه مثل الكونتينيو الي ممكن تساعدوني فيها و الاراي الي لازم اساويه علشان يبين الكرسي المحجوز من الي مش محجوووز و يعطييييكم العفيه

وكلم عااااااااااااام و انتوا بخير

كود

#include
int smoking_seats(int);
int nunsmoking_seats(int);
int smoking_seats(int i)
{
 if(i<6)
  {
   printf("your seat in smoking seats.n");
   printf("and the number of seat is %dn",i);
  }
 return i;
}
int nunsmoking_seats(int k)
{
 if(k<11)
  {
   printf("your seat in nunsmoking seatesn");
   printf("and the number of seat is %dn",k);
  }
 return k;
}
main()
{
 int value,number,k,j,n,i,f;
 j=1;
 i=1;
 k=6;
 while(j==1)
  {
   printf("n            RESERVATION SYSTEM            n");
   printf("choose one of the following.n");
   printf("1-smoking seats.n");
   printf("2-non smoking seats.n");
   printf("3-exit.n");
   scanf("%d",&number);
   switch(number)
    {
     case 1:
	    smoking_seats(i);
	    i++;
	    if(i>=7)
	     {
	      printf("sorry smoking seat is full.n");
	      printf("would you like to sit in nun smoking seats?n");
	      printf("1-yes.n");
	      printf("2-no.n");
	      scanf("%d",&value);
	      switch(value)
	       {
		case 1:
		       nunsmoking_seats(k);
		       k++;
		       if(i>=7)
		       {
		       if(k>=12)
		       {
		       printf("sorry the plane is full.n");
		       printf("next flight leaves in 3 hours.n");
		       }
		       }
		       break;
		case 2:
		       printf("next flight leaves in 3 hours.");
		       break;
		default:
		       printf("this number is not in use.n");
	       }
	     }
	    break;
     case 2:
	    nunsmoking_seats(k);
	    k++;
	    if(k>=12)
	     {
	      printf("sorry nun smoking seat is full.n");
	      printf("would you like to sit in smoking seats?n");
	      printf("1-yes.n");
	      printf("2-no.n");
	      scanf("%d",&n);
	      switch( n )
	       {
		case 1:
		       smoking_seats( i );
		       i++;
		       break;
		       if(k>=12)
		       {
		       if(i>=7)
		       {
		       printf("sorry the plane is full.n");
		       printf("next flight leaves in 3 hours.n");
		       }
		       }
		case 2:
		       printf("next flight leaves in 3 hours.n");
		       break;
		default:
		       printf("this number is not in use.n");
	       }
	     }
	    break;
     case 3:
	    j=6;
	    break;
     default:
	     printf("this number is not in use.n");
	     break;
    }
  }
}

هذا هو و إن شاء الله تساعدوني في الباقي قبل يوم السبت بليييييز و هذه محاولتي سلااام

#2

أخي من أجل ال continue فقط أضف الأسطر التالية قبل الانتهاء من حلقة ال while الرئيسية ..:

	printf("nWould you like to continue,n");
	printf("1 - Yesn");
	printf("2 - Non");
	printf("Select an entry : ");
	scanf("%d", &n);
	j = (n == 1) ? 1 : 6;

Coding on the Cloud and for the Cloud!

My Blog

#3

ويمكن الحل بطريقة أخرى ::

#include 

// This function asks the user (YES/NO) question
//	returns 1 if the user selects YES otherwise it returns 2
int AskYesNo();

// This function free the seat chart of the plane
void FreeSeatChart();

// This function reserves a seat in the range [from, to]
//	returns the seat number or 0 if full
int Reserve(int from, int to);

// This function reserves a seat in smoking area
//	returns the seat number or 0 if full
int SmokingSeat();

// This function reserves a seat in nonsmoking area
//	returns the seat number or 0 if full
int NonsmokingSeat();

// This function prints a boarding pass for the seat nSeat
void PrintBoardingPass(int nSeat);

// A global array for the seat chart
//
int seatchart[10];

void main()
{
	int bContinue = 1;

	// Free all the seats on the plane
	FreeSeatChart();

	while (bContinue)
	{
		int val;
		int nSeat = 0;

		// Output the menu
		//
		printf("Reservation System:n");
		printf("===============================n");
		printf("1 - Smoking Seat.n");
		printf("2 - Nonsomking Seat.n");
		printf("0 - Exit.n");

		printf("nEnter Your Choice : ");
		scanf("%d", &val);

		switch (val)
		{
		case 0:	// Exit
			return;
		case 1:	// Smoking Seat
			nSeat = SmokingSeat();
			break;
		case 2: // Nonsmoking Seat
			nSeat = NonsmokingSeat();
			break;
		default:
			printf("aError entry! Pleasy try again..nn");
		}

		if (nSeat > 0)
		{
			PrintBoardingPass(nSeat); 
		}

		printf("nWould you like to continue (y/n) : ");
		scanf("%hs", (char *)&val);
		bContinue = (val == 'y' || val == 'Y') ? 1 : 0;

		printf("nn");
	}

}

void FreeSeatChart()
{
	for (int i = 0; i < 10; i++)
		seatchart = 0;
}

int Reserve(int from, int to)
{
	int result = 0;

	int i = from - 1;
	while (i < to)
	{
		if (seatchart == 0) 
		{
			result = i + 1;
			seatchart = 1;
			break;
		}
		i++;
	}

	return result;
}

int AskYesNo()
{
	int val;

	printf("1 - Yesn");
	printf("2 - Non");
	printf("Select an entry : ");

	scanf("%d", &val);

	// This makes sure to return 1 or 2 only
	return (val == 1) ? 1 : 2;
}

int SmokingSeat()
{
	int seat;

	// Look for a seat from 1 to 5
	seat = Reserve(1, 5);

	if (seat == 0)
	{
		printf("All seats are full in the smoking section.n");
		printf("Is it OK to be placed in the nonsmoking sectionn");

		if (AskYesNo() == 1) 
		{
			seat = Reserve(6, 10);
			if (seat == 0)
				printf("Sorry! we couldn't find a place either.n");
		}
		else printf("Next flight leaves in 3 hours.n");
	}

	return seat;
}

int NonsmokingSeat()
{
	int seat;

	// Look for a seat from 6 to 10
	seat = Reserve(6, 10);

	if (seat == 0)
	{
		printf("All seats are full in the nonsmoking section.n");
		printf("Is it OK to be placed in the smoking sectionn");

		if (AskYesNo() == 1) 
		{
			seat = Reserve(1, 5);
			if (seat == 0)
				printf("Sorry! we couldn't find a place either.n");
		}
		else printf("Next flight leaves in 3 hours.n");
	}

	return seat;
}

void PrintBoardingPass(int nSeat)
{
	printf("Boarding Pass :n");
	printf("=============================n");

	printf("Seat # %dn", nSeat);
	printf("Section : ");
	if (nSeat >= 1 && nSeat <= 5)
		printf("Smoking sectionn");
	else
		printf("Nonsmoking sectionn");
}

Coding on the Cloud and for the Cloud!

My Blog

#4

اشكر جدااا الاخ هااني لمساعدته العظيمه في المنتدى و لمساعدتي في البرنااامج

و اشكره جدااااا و الله يعينوا علينا;) :D

#5

شباااب هادا حل البرنامج و لكن لسه بحط الكونتينيو شوي شوي و لكن للان البرنامج ماشي الحل تماااام جربوووه و ردولي خبر

كود

#include
#include
int smoking_seats(int);
int smoking_seats(int s)

	{
		if(s<6)

		{

	printf("***Your are in the smoking section seat no %d ***n",s);

			}

    return s;

		}

			int nonsmoking_seats(int);

		int nonsmoking_seats(int n)

	{

		if(n<11)

{

	printf("***You are in the nonsmoking section seat no:%d ***n",n);

		}

	return n;

			}

	main()

		{

	int val,num,z, n,s,f;

	f=1;
			s=1;

				n=6;

	while(f==1)

	{

		printf("n     RESERVATION PROGRAM     n");
		printf("n  =============================== n");

	printf(" *Please enter your choice*n");

		printf("1. Smoking section n");

	printf("2. Non smoking sectionn");

printf("3. EXIT	n");

	scanf("%d",&num);

		switch(num)

	{

	 case 1:

	 smoking_seats(s);

		 s++;

	  if(s>6)

		 {

    printf(" **All seats in the smoking section is full**n");

	printf("***Is it ok to placed you in the non smoking section***n");

	    printf("1.yesn");

	     printf("2.non");

	       scanf("%d",&val);

		switch(val)

	{



      case 1:

      nonsmoking_seats(n);

			n++;
	 if (s>=7)

      {

   if(n>=12)

	 {

		  printf("*****Sorry the plane is full****** n");

	  printf(" ***Next plane leave after three hours*** n");

      }

	    }
      break;

	  case 2:

       printf("***Next plane leave after three hours*** n");
break;
	defult:
printf("**aError entry! please try again**n");
      }
}


	break;


    case 2:

	 nonsmoking_seats(n);

     n++;

   if(n>=12)

	{

    printf(" *****All the seats in the non smoking seats is full*****n");

   printf("***Is it ok to placed you in the smoking section***  n");

      printf("1.yesn");

  printf("2.non");

     scanf("%d",&z);

   switch(z)

	{

  case 1:

    smoking_seats(s);

  s++;

      if(n>=12)

  {

   if(s>=7)

	{

    printf("***Sorry the plane is full***n");

	printf("*****Next plane leave after three hour******n");

   }

	}


case 2:

		printf(" *****Next plane leave after three hour*****n");

	break;
default:
printf("**aError entry! please try again**n");
	 }
    }
break;

		case 3:

		f=6;

	break;

	default:
printf("**aErroe entry! please try again**n");
break;
      }
   }
}

و اسسسسف لأي شي صار تعرف قصدي هاني الله يعطيكم العافيه و خلاص اتعلمت انا

و بخصوص الاخت و رود جوابك هو ان الفنكشن الي انا اتعلمتها تتعرف بهذه الطريقه دائما ,..... هذا والله اعلم اذا كان في خطأ ياريت تتصححوه سلاام :D ;) :o :o

#6

مرحبا و الله يا أخ هاني جربت احط الكونتينيو و ما اشتغلت فياريت تدلني وين بالضبط بليييييز :( :o :o :o

#7

أخي طارق هذا برنامجك الأخير بعد اضافة الكود الخاص من أجل الcontinue .:

#include
#include

int smoking_seats(int s)
{
	if(s<6)
	{
		printf("***Your are in the smoking section seat no %d ***n",s);
	}

	return s;
}

int nonsmoking_seats(int n)
{

	if(n<11)
	{
		printf("***You are in the nonsmoking section seat no:%d ***n",n);
	}

	return n;
}

void main()
{
	int val, num, z, n, s, f;

	f = 1;
	s = 1;
	n = 6;

	while(f == 1)
	{
		printf("n     RESERVATION PROGRAM     n");
		printf("n  =============================== n");
		printf(" *Please enter your choice*n");
		printf("1. Smoking section n");
		printf("2. Non smoking sectionn");
		printf("3. EXIT	n");

		scanf("%d",&num);

		switch(num)
		{
		case 1:
			smoking_seats(s);
			s++;
			if(s>6)
			{
				printf(" **All seats in the smoking section is full**n");
				printf("***Is it ok to placed you in the non smoking section***n");
				printf("1.yesn");
				printf("2.non");
				scanf("%d",&val);
				switch(val)
				{
				case 1:
					nonsmoking_seats(n);
					n++;
					if (s>=7)
					{
						if(n>=12)
						{
							printf("*****Sorry the plane is full****** n");
							printf(" ***Next plane leave after three hours*** n");
						}
					}
					break;
				case 2:
					printf("***Next plane leave after three hours*** n");
					break;
				default:
					printf("**aError entry! please try again**n");
				}
			}
		break;

		case 2:
			nonsmoking_seats(n);
			n++;
			if(n>=12)
			{
				printf(" *****All the seats in the non smoking seats is full*****n");
				printf("***Is it ok to placed you in the smoking section***  n");
				printf("1.yesn");
				printf("2.non");
				scanf("%d",&z);
				switch(z)
				{
				case 1:
					smoking_seats(s);
					s++;
					if(n>=12)
					{
						if(s>=7)
						{
							printf("***Sorry the plane is full***n");
							printf("*****Next plane leave after three hour******n");
						}
					}
				case 2:
					printf(" *****Next plane leave after three hour*****n");
					break;
				default:
					printf("**aError entry! please try again**n");
				}
			}
			break;

		case 3:
			f = 0;
			break;

		default:
			printf("**aErroe entry! please try again**n");
			break;
		}

		if (f != 0) 
		{
			printf("nWould you like to continue (1:YES / 2:NO) : ");
			scanf("%d", &val);
			f = (val == 1) ? 1 : 0;

			printf("nn");
		}
	}
}

Coding on the Cloud and for the Cloud!

My Blog

#8

شكرااااا لك اخ هانيييي كثيييير لولاك لما ساوتها و لا ارتاحلي بال الى لما ساويتلي اياها و الله يعطييييك الف عافيه على جهودك الجبارة للمنتدى و للمساعده الي قدمتلي ايااهاااا ..... و انا حاولت اساوي الي نصحتني فيه و هاذي اول نصيحه اني رتبت البرنااامج و انشااااء اللله القدم اكثر انشاااااء الله :D ;) :o :o

هذا الموضوع مغلق.

مواضيع مشابهة