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

للخبراء بلغه السي++ تكفون ساعدوني بحل هذا الواجب

مغلق
بدأه النوايف في 6 نوفمبر 2004 · 11 رد · 1,479 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا هو السؤال

وياليت انكم تساعدوني

What is this about?

For this programming assignment; we are going to implement the round-robin scheduling technique (Program in C++) and study the effects of varying time quantums

What to do?

Round-Robin Scheduling algorithm implementation needs a circular queue. Your main job in this project would be to implement the circular queue. Read data from a modifiable text file; load into the circular queue. The time-slice would be a start-up parameter issued by the user. Calculate the waiting times for each process and the average waiting time for all of the processes to get served. Your program must read time quantum <an integer> at the command line. Process CPU burst time must vary between [0-100]

Hints:

1. Implement a circular queue. Each node of the queue would have two attributes (1. Process burst time, 2. Pointer). Your program should be able to read 100 processes from file!

2. Make a text file with data arranged. Your text file may look like this

3. Read time slice as a commandline input eg ([Linux % user] RRP 4)..4 is the timeslice

4. Read the text file at the start of [RRP] and fill your circular queue. Make a node in the queue for each process read from file.

5. While traversing through the queue for each process "being processed" decrease the process time (P time - time_slice). if process time is <0 delete the node.

6. Calculate the Waiting time for each process. Then find the average waiting time. Display these values.

What to turn in:

1. C++ program complete compilable and without any errors.

2. A Report discussing the effects of different time-quantums on same data. (2-3 pages) preferably containing a graph illustrating the analysis of your results. Use the following time quantums [1 2 4 8 16 32 64 128]. Attach a sheet of your data.

الملف this

موجود في المرفقات

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

this.txt

تم تعديل هذه المشاركة بواسطة النوايف في 6 نوفمبر 2004 في 02:30

#2

اهلا وسهلا بك

ولكن فضلا يا اخي اقرأ قوانين المنتدى

واعمل بحث قبل السؤال

لكم مني خالص التقدير

*********************

دروس الاكسس

قاعدة بيانات بالسي++

قاعدة بيانات اخرى بالسي++

الفريق العربي للبرمجه

*********************

كان الله في عون العبد مادام العبد في عون اخيه

#3

أخي النوايف ..

اليك كود لعمل round robin scheduling سيساعدك كثيرا .. اتمني لك الاستفاده منه..

/* Scheduling Simulation*/

#include <stdio.h>
#include <stdlib.h>

/* Process Data Structure */
struct process {
    int pid;                /* Process ID */
    int burst;              /* CPU Burst Time */
    int priority;           /* Priority */
    int working;            /* Working time, for round-robin scheduling */
    int waiting;            /* Waiting time, for round-robin scheduling */
    struct process *next;
};

/* Function Prototype Declarations */
struct process *init_process (int pid, int burst, int priority);
void fcfs (struct process *proc);
void listprocs (struct process *proc);
void priority (struct process *proc);
void rr (struct process *proc, int quantum);
void sjf (struct process *proc);

/* Main Program Segment */
int main (void) {
    /* Initialize process list */
    struct process *plist, *ptmp;
    plist       = init_process(1, 10, 3);
    plist->next = init_process(2,  1, 1); ptmp = plist->next;
    ptmp->next  = init_process(3,  2, 3); ptmp = ptmp->next;
    ptmp->next  = init_process(4,  1, 4); ptmp = ptmp->next;
    ptmp->next  = init_process(5,  5, 2);

    /* Perform simulations */
    listprocs(plist);
    fcfs(plist);
    sjf(plist);
    priority(plist);
    rr(plist, 1);

    /* Terminate cleanly */
    while (plist != NULL) {
        ptmp = plist;
        plist = plist->next;
        free(ptmp);
    };
    return(0);
};


/* Process list entry initialization routine */
struct process *init_process (int pid, int burst, int priority) {
    struct process *proc;
    proc = malloc(sizeof(struct process));
    if (proc == NULL) {
        printf("Fatal error: memory allocation failure.\nTerminating.\n");
        exit(1);
    };
    proc->pid = pid;
    proc->burst = burst;
    proc->priority = priority;
    proc->working = 0;
    proc->waiting = 0;
    proc->next = NULL;
    return(proc);
};


/* First-Come-First-Served scheduling simulation */
void fcfs (struct process *proc) {
    int time = 0, start, end;
    struct process *tmp = proc;

    printf("BEGIN:\tFirst-Come-First-Served scheduling simulation\n");

    while (tmp != NULL) {
        start = time;
        time += tmp->burst;
        end = time;
        printf("Process: %d\tEnd Time: %d\tWaiting: %d\tTurnaround: %d\n", tmp->pid, time, start, end);
        tmp = tmp->next;
    };

    printf("END:\tFirst-Come-First-served scheduling simulation\n\n");
};


/* Process listing */
void listprocs (struct process *proc) {
    struct process *tmp = proc;

    printf("BEGIN:\tProcess Listing\n");

    while (tmp != NULL) {
        printf("PID: %d\t\tPriority: %d\tBurst: %d\n", tmp->pid, tmp->priority, tmp->burst);
        tmp = tmp->next;
    };

    printf("END:\tProcess Listing\n\n");
};


/* Priority scheduling simulation
 * Note: lower priority value gets a higher priority
 */
void priority (struct process *proc) {
    int time, start, end, highest;
    struct process *copy, *tmpsrc, *tmp, *beforehighest;

    printf("BEGIN:\tPriority scheduling simulation\n");

    /* Duplicate process list */
    tmpsrc = proc;
    copy = tmp = NULL;
    while (tmpsrc != NULL) {
        if (copy == NULL) {
            copy = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = copy;
        } else {
            tmp->next = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = tmp->next;
        };
        tmpsrc = tmpsrc->next;
    };

    /* Main routine */
    time = 0;
    while (copy != NULL) {
        /* Find the next job */
        beforehighest = NULL;
        highest = copy->priority;
        tmp = copy->next;
        tmpsrc = copy;
        while (tmp != NULL) {
            if (tmp->priority < highest) {
                highest = tmp->priority;
                beforehighest = tmpsrc;
            };
            tmpsrc = tmp;
            tmp = tmp->next;
        };

        /* Process job and remove from copy of process list */
        if (beforehighest == NULL) {
            /* Handle first job is highest priority case */
            start = time;
            time += copy->burst;
            end = time;
            printf("Process: %d\tEnd Time: %d\tWaiting: %d\tTurnaround: %d\n", copy->pid, time, start, end);
            tmpsrc = copy->next;
            free(copy);
            copy = tmpsrc;
        } else {
            /* Handle first job is not highest priority case */
            tmp = beforehighest->next;
            start = time;
            time += tmp->burst;
            end = time;
            printf("Process: %d\tEnd Time: %d\tWaiting: %d\tTurnaround: %d\n", tmp->pid, time, start, end);
            beforehighest->next = tmp->next;
            free(tmp);
        };
    };

    printf("END:\tPriority scheduling simulation\n\n");
};


/* Round-Robin scheduling simulation */
void rr (struct process *proc, int quantum) {
    int jobsremain, passes;
    struct process *copy, *tmpsrc, *tmp, *slot;

    printf("BEGIN:\tRound-Robin scheduling simulation (Quantum: %d)\n", quantum);
    /* Duplicate process list */
    tmpsrc = proc;
    copy = tmp = NULL;
    while (tmpsrc != NULL) {
        if (copy == NULL) {
            copy = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = copy;
        } else {
            tmp->next = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = tmp->next;
        };
        tmpsrc = tmpsrc->next;
    };

    /* Main routine */
    jobsremain = 1;
    slot = NULL;
    while (jobsremain) {
        jobsremain = 0;

        /* Pick next working slot */
        if (slot == NULL) {
            slot = copy;
            jobsremain = 1;
        } else {
            passes = 0;
            do {
                if (slot->next == NULL) {
                    passes++;
                    slot = copy;
                } else {
                    slot = slot->next;
                };
            } while (passes <= 2 && slot->burst == slot->working);
            if (passes <= 2) {
                jobsremain = 1;
            };
        };

        /* Perform a cycle */
        tmp = copy;
        while (tmp != NULL) {
            if (tmp->burst > tmp->working) {
                if (tmp == slot) {
                    tmp->working += quantum;
                } else {
                    tmp->waiting += quantum;
                };
            };
            tmp = tmp->next;
        };
    };

    /* Display statistics and clean up copy */
    tmp = copy;
    while (tmp != NULL) {
        printf("Process: %d\tWorking: %d\tWaiting: %d\tTurnaround: %d\n", tmp->pid, tmp->working, tmp->waiting, tmp->working + tmp->waiting);
        tmpsrc = tmp;
        tmp = tmp->next;
        free(tmpsrc);
    };

    printf("END:\tRR scheduling simulation\n\n");
};


/* Shortest Job First scheduling simulation */
void sjf (struct process *proc) {
    int time, start, end, shortest;
    struct process *copy, *tmpsrc, *tmp, *beforeshortest;

    printf("BEGIN:\tShortest Job First scheduling simulation\n");

    /* Duplicate process list */
    tmpsrc = proc;
    copy = tmp = NULL;
    while (tmpsrc != NULL) {
        if (copy == NULL) {
            copy = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = copy;
        } else {
            tmp->next = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
            tmp = tmp->next;
        };
        tmpsrc = tmpsrc->next;
    };

    /* Main routine */
    time = 0;
    while (copy != NULL) {
        /* Find the next job */
        beforeshortest = NULL;
        shortest = copy->burst;
        tmp = copy->next;
        tmpsrc = copy;
        while (tmp != NULL) {
            if (tmp->burst < shortest) {
                shortest = tmp->burst;
                beforeshortest = tmpsrc;
            };
            tmpsrc = tmp;
            tmp = tmp->next;
        };

        /* Process job and remove from copy of process list */
        if (beforeshortest == NULL) {
            /* Handle first job is shortest case */
            start = time;
            time += copy->burst;
            end = time;
            printf("Process: %d\tEnd Time: %d\tWaiting: %d\tTurnaround: %d\n", copy->pid, time, start, end);
            tmpsrc = copy;
            copy = copy->next;
            free(tmpsrc);
        } else {
            /* Handle first job is not shortest case */
            tmp = beforeshortest->next;
            start = time;
            time += tmp->burst;
            end = time;
            printf("Process: %d\tEnd Time: %d\tWaiting: %d\tTurnaround: %d\n", tmp->pid, time, start, end);
            beforeshortest->next = tmp->next;
            free(tmp);
        };
    };

    printf("END:\tShortest Job First scheduling simulation\n\n");
};
#4

اختي فلسطينيه

مشكوره على الكود

بس ابي شخص يحل لي السؤال اؤ يساعدني في حله

لانه مره صعب وانا مااافهمته

وياليت احد يشرحه لي او يحله

وبعدين ابيه بلغه السي++

ومشكووووووووووورين

#5

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

اقتباس
لانه مره صعب وانا مااافهمته

أخي شو اللى مش فاهمه بالضبط ؟؟ هل السؤال نفسه ؟!!

اقتباس
وبعدين ابيه بلغه السي++

انا تعمدت ان اضعه بالـسي لسببين :

مساعدتك على الفهم سواء لطريقه العمل .. او لتسلسل خطوات البرنامج وذلك بقراءه الكود جيدا وتتبعه ..

وثانيا لاني لا اريد ان احل لك الواجب بشكل كامل فانا اريد ان اضمن انك قمت بمجهود بحل السؤال ..

وان كان وضع الكود يعني حل بنسبه 95% فالكود انما لمساعدتك بالافكار فكود السي سهل الفهم ..وتحويله ايضا سهل ...

#6

أختي فلسطينية

انا مااافهمت السؤال وماااعرف كيف احله

لاني كنت غايب عن المحاضره

وياليت انك تساعديني في حله

وتقولين لي وش اسوي بالظبط

وانا إن شاء الله ابكون معاك

وياليت احد المشرفين يساعدنا في الحل

وبعدين اختي فلسطينية

نبغي نمسك السؤال حبه حبه

ونحله حبه حبه

اول مطلوب هو

Implement a circular queue. Each node of the queue would have two attributes (1. Process burst time, 2. Pointer). Your program should be able to read 100 processes from file!

كيف اسوي

circular queue

ووشهو الكود

#7

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

الاخ النوايف .. سأبدأ معك حبه حبه ..وباذن الله تستفيد ..

اولا لنبدأ بالسؤال .. السؤال يعتمد على بناء circular queue والتي هي عباره عن queue عاديه ولكن بعد ان تمتلىء تبدأ تعبي من اول وجديد ..

و كما تعرف الـ queue العاديه عباره عن سلسلة من nodes ..

كل node عباره عن struct تضع فيه البيانات التي تريدها .. وهي عندك هناProcess burst time, Pointer

اولا : عليك تعريف struct مناسب لبياناتك

ثانيا : عليك تعريف 2pointers احدهما head والاخر tail لكي يؤشران على بدايه الـ queue ونهايتها

أخي حاول تعمل الstructure لما سبق .. لأكمل لك الخطوات ..

#8

هلا اختي فلسطينيه

كل اللي اعرفه عن

Queue

class Queue

{

private int front;

private int rear;

}

public Queue(int s) // constructor

{

maxSize = s+1;

queArray = new int[maxSize];

front = 0;

rear = -1;

nItems = 0;

}

#9

وينكم يالمشرفين صار لي اربعه ايام

ولا واحد حل لي السؤال

تكفوووووووووووون ابي واحد يساعدني

#10

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

أختي الفلسطينية الأخ لازم ساعد أخوه وأنا من فلسطين منقطاع غزة ومن خان يونس بالتحديد أرجو إنك تساعديني في كتابة برنامج عن merge sort

بلغة سي بحيث أنه يقرامن ملف ويكتب بملف

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

وأنا مش هلقد بالفيلات لأنه الفصل السابق مضى وأنا محجوزة على الحدود (المعبر بين رفح ومصر)

أرجو إنك تساعدي أختك الفلسطينية

stargate103@hotmail.com

#11

هلا بلال إلك بلغة سي

#12

ممكن بس حد يقول يعنى اي round robin scheduling

دة بيتكلم عن اية اية موضوع و فيما يستخدم و شكرا

لا اله الا الله .......................................... محمد رسول الله

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

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…