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

أبي الفزعة بسرررررعة..O_o

مغلق
بدأه اريام في 24 ديسمبر 2003 · 4 رد · 815 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و الرحمة...

عاد ما تتيخيلون فرحتي بوجود منتدى برمجة...دلني عليه موقع مجلة المبرمج العربي و اشكره بشدة..

و الحقيقة ابي مساعدة عاجلة جدا..في بروجيكت طلب مني.. و اتمنى المساعدة..فكرة البرنامج عن برنامج حجز رحلات طيران.. و يجب أن أحجز 5 مقاعد للدرجة الاولى و خمسة أخرى للدرجة السياحية.. و يعبّر عن كون المقاعد غير شاغره بان تظهر 0.. و اذا محجوزة يظهر رقم 1..و طبعا هذا بيكون في array..يظهر للمستخدم في بداية ابرنامج كما هو ظاهر فيما ارفقته

.... وطبعا بعد ان يدخل المستخدم اسمه يمنح مقعدا.. و المقعد المحجوز لا يمكن حجزه مرة اخرى..... و اذا اكتمل عدد المقاعد المحجوزة في الدرجة الاولى مثلا..تظهر رسالة تقول.. لا يوجد مقعد شاغر هناهل تريد الحجز في الدرجة السياحية.؟.. اذا اختار المستخدم نعم..يذهب الى الدرجة السياحية و يكمل التسجيل ..اذا طبع لا..تظهر رسالة أخرى..الرحلة القادمة بعد 3 ساعات مثلا.. فكيف لي أن اطبق هذا... برنامجي الذي طبعته لكم خطوة اولى لكن المشكلة تتمثل في حجز المقاعد. و اعرف ان الحل يكمن في استخدام ال pointerلكن لا اعرف كيف اطبقه. فما العمل..؟

للعلم بان في دراستي قد استخدمت ال array, و ال pointer.. بالاضافة الى ال file processing و هذا استخدمته في البرنامج ..و لا اريد تطبيق اي شي خارج نطاق هذه الدروس..

و الحين ممكن تساعدوني...ترى بقى اسبوع واحد على تقديم البروجيكت.. و انا في امس الحاجة لأي ملاحظة ..

:(

و سأرفق ما وصلت له حتى الآن و الظاهر انه شي لا يذكر..لأن البرنامج فيه افكار أخرى صعبة..

reem.cpp

#2

هلا أختي ،، :)

أذكر إننا عملنا برنامج قريب من برنامجك ،،

وكان المطلوب منا ، إننا نحله خلال شهر كامل ،،

و برنامجك ،، من الممكن إنك تحليه ،

لو رتبتي أفكارك فيها شوي ،، :)

و نحن بالخدمة بإذن الله ،،

-0-0-0-0-0-

لإنه الصراحة ،، الملف اللي أرسلتيه ،،

مكتوب بإختصار و عالسريع .,,؟؟ :(

ولازم تحاولي فيها ،،

و السلام عليكم ،،

أختك ،، العصامية ،،

#3

I will try to help as much as I can .. I will give you possible solutions. The data structure of the first one are arrays and here how it should work:

you should have two arrays. The first array is an array of ten of integers .. the ten integers should be initialized to "0" since zero represents an empty seat. and the second array should be an array of ten stricngs to store passengers names where all the slots are initialized to null "\0". now you have two arrays one for names and the other for seats availabilty. Keep in mind that the first five slots of each array will be reserved for first class reservations while the last five slots are reserved for the economic class reservation. And the most important thing is to keep in mind that the same index is used to index both arrays. Lets walk through the program now. a reservation is accuired and the passenger name is given, slot number "0" in the seats array will be set to "1" and the slot number "0" in the names array will be set to "some name" and so on. when the first five slots are full the program should prompt the error message that you talked about and do a reservation in the economic class slots.

The second solution is using pointers, the data structure will consist of a linear linked list (or any other you wish) where each node will contain the passenger name and the reservation type (first class or economic) but the program should keep track of the number of seats available.

Give it a try and lets see some code.

Mutix.up

#4

I thoguth that your program is worth programming ;) so I decided to finsh up some part of it. Remeber this is not the whole program, you still need to do the following:

(1) improve the API

(2) do the file thing

(3) modify the data structure if needed

simple linked list is used to do that program.

Listing of the code:

res.h

#include <iostream.h>

#define MAX_SEATS       5
#define FIRST_CLASS     0
#define ECONOMIC        1

class   node
{
 public:
  node  *next;
  char  *name;
  int   type;
};

class   remote
{
 public:
        remote  ();
        ~remote () {};
  int   reserve (char *&, int &);
  int   display ();
  int   isFIRST ();
  int   isECON  ();

 private:
  node  *head;
  int   F_seats;
  int   E_seats;
};

res.c

#include "res.h"

remote::remote ()
{
 head = NULL;
 F_seats = 0;
 E_seats = 0;
}

int     remote::reserve (char *& name, int & type)
{
 node *tmp = NULL;
 tmp = new node;
 tmp->name = new char [strlen (name) + 1];
 strcpy (tmp->name, name);
 tmp->type = type;

 if (!head)
 {
  head = tmp;
  head->next = NULL;
 }

 else
 {
  tmp->next = head;
  head = tmp;
 }

 if (type == ECONOMIC) E_seats++;
 else  F_seats++;
 cout << "** Reservation completed **" << endl;

 display ();
 return 1;
}

int     remote::display ()
{
 if (!head) return 0;

 node *tmp = head;

 while (tmp)
 {
  cout << "----------------------" << endl;
  cout << tmp->name << " -- ";
  if (tmp->type == ECONOMIC) cout << "ECONOMIC CLASS" << endl;
  else cout << "FIRSL CLASS" << endl;
  cout << "----------------------" << endl;
  tmp = tmp->next;
 }
 delete tmp;
 return 1;
}

int     remote::isFIRST ()
{
 if (F_seats == MAX_SEATS) return 0;
 else return 1;
}

int     remote::isECON  ()
{
 if (E_seats == MAX_SEATS) return 0;
 else return 1;
}

api.c

#include"res.h"

void    main ()
{
 remote P;
 int type = -1;
 char *name;

 while (1)
 {
  cout << "Enter your name :";
  cin.get (name, 81, '\n');
  cin.get ();

  cout << "Enter 0 for first class and 1 for economic class :";
  cin >> type;
  cin.get ();

  if (type == FIRST_CLASS)
  {
   if (P.isFIRST ()) P.reserve (name, type);

   else
   {
    cout << "sorry, no more first class seats," << endl;
    cout << "Would you like an conomic class seat ?," << endl;
    cout << "0 for NO, 1 for YES : ";
    cin >> type;
    cin.get ();
    if (type == ECONOMIC == 1) goto TRY;
    else cout << "no more seats, next flight is after 3 hours" << endl;
   }
  }

  else if (type == ECONOMIC)
  {
   TRY:
   if (P.isECON () == 1) P.reserve (name, type);
   else cout << "no more seats, next flight is after 3 hours" << endl;
  }

  else
   cout << "An error has ocured, please try again" << endl;
 }
}

Mutix.up

#5

أشكركم على تجاوبكم معي....

و اشكرك يالعصامية .. و فعلا اعترف برنامجي كان مختصر جدا.... و قد طلب منا في منتصف الفصل الدراسي و نتيجة تعبي خلاله ضاع قبل يومان فقط .. و عندما كتبت ما كتبته كنت قد حللته في نفس اليوم..لكن يفترض بي تجميع افكاري كما قلتي.. و ها قد حاولت و ووصلت الى التالي المرفق مع ردي.. ..لكن ما تزال هناك مشكلة..

اخيMutix..شكرا على المعلومات المفيدة التي سطرتها لكن فيها الكثير مما لم ادرس...

و يبدو لي ان البرنامج بسيط...لأني قد توصلت جزئيا الى حله .. و سأرفقه لكم..

لكن هناك شيء ما مفقود او خاطيء.. و أتمنى مساعدتي بملاحظاتكم...

و اشكركم جدا....

و ها هو البرنامج معدلا..

try2.cpp

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

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