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

ما المقصود من السؤال ومافكرته

بدأه توتـآ في 20 مارس 2010 · 6 رد · 1,209 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله وبركاته

In the timesharing problem solved by the operating system, the operating system must maintain a list
of present users and must alternately allow each user to use a small slice of CPU time, one user at a
time. The operating system will pick a user; let him/her use a small amount of CPU time and then
move on to the next user, etc. For this application, there should be no NULL pointers unless there is
absolutely no one requesting CPU time.
1. What data structure do you suggest to simulate the job of the timesharing problem?
2. After you have decided the appreciate data structure to be used, write a C++ program, this
program should have the following specifications:
a. Printing out the information of users that requesting CPU time.
b. Counting the number of users that requesting CPU time.
c. Use appreciate driven menu.

ما المقصود من السؤال وما فكرته

فقط شرح السؤال والفكرة وليس طلب للحل

وإن شاء الله بس افهمه أدرج حليّ

#2

و عليكم السلام و رحمة الله و بركاته,

للأسف الأسئلة التي تضعينها عبارة عن واجب, و الغالب أنهم يريدون سؤالك عما درسته, لذلك رجاءً ارجعي إلى المنهج و ستجدين بسهولة الإجابات :)

1. What data structure do you suggest to simulate the job of the timesharing problem?

هذا سؤال معقد جداً, و أبحاث كثيرة تنشر حوله, و الـ Optimal Concurrency موضوع مستحيل, و لكن من طرح السؤال, فهم يريدون أن تقولي أن أفضل Data Structure هي الـ Queue,

و تفسير ذلك أن المستخدم الذي يصل أولاً, يتم خدمته و اقتطاع وقت المعالج لأجله, أي أن العملية First Come First Serve.

باقي الأسئلة, يمكن حلها بسهولة بمجرد كتابة الـ Queue أو استعمال أحدها(من الأفضل بالطبع), و الرجع إلى السؤال المعطى لك لحله بالطريقة المطلوبة.

تحياتي...

2
#3

صحيح هو واجب

لكني لم أفهم السؤال لأحله فقط طلبت شرح السؤال وليس الحل .

هل أحلها بالـ Queue ام بالـ linked List

ولماذا الـ Queue أفضل هل لأنها تعتمد على مبدآ FIFO

لماذا لم تقول Stak

تم تعديل هذه المشاركة بواسطة توتـآ في 20 مارس 2010 في 23:51

#4

طيب,

In the timesharing problem solved by the operating system, the operating system must maintain a list

of present users and must alternately allow each user to use a small slice of CPU time, one user at a

time. The operating system will pick a user; let him/her use a small amount of CPU time and then

move on to the next user, etc. For this application, there should be no NULL pointers unless there is

absolutely no one requesting CPU time.

خطوة خطوة......

نظام التشغيل عبارة عن برنامج يعمل على شيء شبيه بالـ Server, و ما يتصل به عبارة عن شاشات و لوحات مفاتيح لا أكثر, أي أن المستخدم لا يملك جهاز حقيقي تحت يديه, و إنما يعمل على الـ Server مع الآخرين.

بالطبع نعلم أن المشكلة المطروحة لديك, تتكلم عن وجود معالج واحد فقط. بالتالي, فإن هناك مستخدم واحد يعمل في لحظة من اللحظات. معنى أن مستخدم يعمل على النظام, أي أن النظام يقوم بإنتظار الأمر منه عن طريق لوحة المفاتيح,

و يقوم بعرض نتائج برامجه على الشاشة و ذلك خلال الوقت الذي يعطيه له النظام و الذي سميناه Slice.

السؤال الذي يطرح نفسه, هل جميع المستخدمين متساوين؟

الإجابة هي نعم حسب السؤال المطروح, إذاً الوقت المعطى لأي مستخدم هو نفس المعطى لغيره, و بالتالي الـ Slice عبارة عن فترة زمنية ثابتة لكل مستخدم.

ماهي الطريقة المنطقية برأيك لإعطاء كل مستخدم حقه؟

هل أول من يأتي يعطى الأفضلية, بحيث لو انتهى وقته يتم نقل التحكم للمستخدم الآخر الذي يعمل على برامج أخرى بالطبع لا يطلع أحد عليها غيره؟

كيف سنختار الشخص التالي؟

الإجابة حسب سؤالك, أن المستخدمين يتم تنفيذ برامجهم بالدور, حسب الوقت الذي أتى به كل مستخدم.

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

أنت تقولين لماذا لا نستخدم Stack؟

طيب كيف سنستخدم Stack, هل آخر من يأتي هو أول من يعطى التحكم في النظام؟ فكري قليلاً, كيف يعمل الـ Stack؟

أما موضوع الـ Linked List و الـ Arrays, فأعتقد أنك بحاجة إلى قليل من مراجعة الـ Data Structures.

الـ Linked List ليس فيها ترتيب للعناصر مثل الـ Stack أو الـ Queue, و إنما هي Random Access Containers. أي أن العناصر عندما ننظر لها, فإننا ننظر لها على أنها مجموعة يمكن الوصول إلى أي منها.

بالتالي, لابد أن نحدد الطريقة التي نصل بها للعناصر. فالـ Queue عبارة مفهوم, يحدد كيفية الوصول إلى العناصر, أول عنصر يدخل هو أول عنصر يخرج. و بالتالي حددنا العلاقة بين العناصر.

عموماً,

ابدأي بكتابة البرنامج, و لن يقصر الأخوة و الأخوات هنا في المنتدى,

تحياتي...

تم تعديل هذه المشاركة بواسطة Khaled.Alshaya في 21 مارس 2010 في 01:03

2
#5

جزاك الله كل خير وأسعدك في الدارين

شرحك واضح ومفهوم الحمد لله

بدأت بكتابه الكود لكن تبادر إلى ذهني سؤال

هل أستطيع إستخدام نوع circle linked list

بما أن الذي استخدم الجهاز الآن وإنتهى وقته سوف يصف بآخر الطابور

فممكن استخدم circle linked list حتى اذهب للمستخدم الذي بعده ثم الذي يليه ثم الذي يليه

حتى اصل لهذا المستخدم

هل فكرتي صحيحه ..؟

وايضا ً لوجود هذه الفقرة في السؤال

there should be no NULL pointers

اي ان آخر Node يجب أن يأشر على Node آخر حتى لا تكون قيمته NULL

تم تعديل هذه المشاركة بواسطة توتـآ في 21 مارس 2010 في 19:44

#6

حللت السؤال :)

ولكن عند تنفيذ البرنامج على الكوبايلر يحدث Run-time Error

عند اول ُمدخل يدخله

هل ممكن احد يساعدني ويخبرني ماالخطأ

#include <string>
#include <iostream>
using namespace std;



// Node Declaration
template <class TYPE>
struct NODE
{
TYPE data;
NODE *link;
}; // End of Node Declaration
// Circular Linked CLL Class Declaration
template <class TYPE>
class CLL
{
private:
NODE<TYPE> *head;
NODE<TYPE> *rear;
NODE<TYPE> *pos;
int count;
// Function Declarations
bool _insert (NODE<TYPE> *pPre,
TYPE dataIn);
public:
CLL (void);
~CLL (void);
int addNode (TYPE dataIn);
int CLLCount (void);
bool getNext (int fromWhere,
TYPE& dataOut);
// CLL Class Declaration
};



/* =============== CLL Constructor ==============
Initialize the CLL.
Pre Class is being instantiated
Post Class instantiated and initialized
*/
template <class TYPE>
CLL<TYPE> :: CLL (void)
{// Statements
head = NULL;
rear = NULL;
count = 0;
} // CLL Constructor




/* ==================== addNode ===================
Inserts data into linked CLL.
Pre dataIn contains data to be inserted
Post Data inserted or error
Return -1 if overflow,
0 if successful,
1 if duplicate key
*/
template <class TYPE>
int CLL<TYPE> :: addNode (TYPE dataIn)
{
bool success = true;
NODE<TYPE> *pPre = rear;
success = _insert (pPre, dataIn);
if (!success)
// Overflow
return (-1);
return (0);
}// addNode




/* ===================== _insert ====================
Inserts data into a new node in the linked CLL.
Pre Insertion location identified by pPre
dataIn contains data to be inserted
Post data inserted in linked CLL or overflow
Return true if successful, false if overflow
*/
template <class TYPE>
bool CLL<TYPE> :: _insert (NODE<TYPE> *pPre,
TYPE dataIn)
{// Local Definitions
NODE <TYPE> *pNew;
// Statements
if (! (pNew = new NODE<TYPE>))
return false;
pNew->data = dataIn;
pNew->link = head;
if (pPre == NULL)
{
// Adding before first node or to empty CLL.
pNew->link = head;
head = pNew;
} // if pPre
else
{
// Adding in middle or at end
pNew->link = head;
pPre->link = pNew;
} // if else
rear = pNew;
count++;
return true;
} // _insert




/* ==================== CLLCount ====================
Returns integer representing number of nodes in CLL.
Pre Nothing
Return count for number of nodes in CLL
*/
template <class TYPE>
int CLL<TYPE> :: CLLCount(void)
{// Statements
return count;
} // CLLCount




/* =============== Destructor ==============
Deletes all data in CLL and recycles memory
Pre CLL is being deleted
Post Data and class structure have been deleted
*/
template<class TYPE>
CLL<TYPE> :: ~CLL (void)
{// Local Definitions
NODE<TYPE> *deletePtr;
// Statements
if (head)
{
while (count > 0)
{
deletePtr = head;
head = head->link;
count--;
delete deletePtr;
} // while
} // if
} // Destructor




/* ====================== getNext =====================
getNext traverses a linked CLL. Each call either starts
at the beginning of the CLL or returns the location of
the element in the CLL that was last returned.
Pre fromWhere is 0 to start at the first element
dataOut is reference to data variable
Post if another element, address placed in output area
Return true if another element located,
false if end of CLL
*/
template <class TYPE>
bool CLL<TYPE> :: getNext (int fromWhere,
TYPE& dataOut)
{// Local Definitions
bool success;
// Statements
if (fromWhere == 0)
{
// Start from first node
if (count == 0)
success = false;
else
{
pos = head;
dataOut = pos->data;
success = true;
} // if else
} // if fromwhere is zero
else
{
// Continue from current position
if (pos->link == head)
success = false;
else
{
pos = pos->link;
dataOut = pos->data;
success = true;
} // if else
} // if fromWhere else
return success;
} // getNext
/* =================*/


int main ()
{
	string name;
CLL<string> users;

 int choice ;

 do {
  cout << "====== Mnue ======  \n ";
  cout << "1-Insert User. \n ";
  cout << "2-Counting the Number of All Users. \n " ;
  cout << "3-Print all Users Information . \n ";
  cout << "4-Exit . \n" ;
  cout << "------------ \n" ;
  cin >> choice ;

  switch (choice )
  {
  case 1:
   cin >> name;
   users.addNode (name);
   break;


  case 2:
{
   bool moreData = users.getNext (0 , name );
    while ( moreData )
    {
     cout << name  << endl;
     moreData = users.getNext ( 1 , name );
}}
   break;

   case 3:
   cout << "The Number of all Users is " << users.CLLCount() << endl;
   break;

  case 4:
   break;

  default : cout << "You Have Intered Wrong Number " << endl;

  }
 }while (choice != 4);
 return 0;
}
#7

:blush:احد يشرح لنا ؟؟؟؟؟؟؟؟؟؟؟ اشرحي لنا الكود اللي حليته

شكررررررررررااااااااااااااا :wub:

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