Find Jobs
Hire Freelancers

Correction of c++ SJF simulation code

€8-30 EUR

Completed
Posted over 10 years ago

€8-30 EUR

Paid on delivery
I am creating an SJF code ( no preemtion). It is functioning correctly (as far as i can tell) but always some processes(1-4 out of 10) are not sorted correctly. Assume there are 10 processes I attached my code with comments. Also here is my logic behind it. Burst times and arrival times are generated and are known before the algoithm begins 1) I sort all processes and find the one that is going to be executed first ( if two have same arrival time its the one with the lower burst time) 2)After this there are three variables. Completed ( how many processes are done), Totaltime( time that has passed) and counter ( how many processes have arrived after 1 was completed 3) i begin a repetition for i=1 until 10 ( the rest 9 processes). Totaltime has been initialized as burst[0]+arrival[0]. each time count how many processes have arrived. Also perform a completed++ at the very end of the repetition (after the next steps that is) 4) the tricky part : perform bubblesort for 1=completed until counter-1 and for j=i until counter ( the problem almost certainly is here) 5)The next process has been found , so its burst time is added to totaltime, counter is set to 0 and some other calculations which you have to check turnaroundtime ( time that passed from the arrival of a process until its completation) and waittime ( time passed from arrival until it was started) P.S 1)If you think my logic is totally flawed you are free to make your own version but all the variables mentioned have to be there
Project ID: 5021933

About the project

7 proposals
Remote project
Active 11 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
Γεια σου. Το λάθος σου είναι στην ταξινόμηση των διεργασιών που έχουν φτάσει, με βάση το burst time. Συγκεκριμένα, γράφεις: //for the arrived processes arrange them with smaller burst time first for (int i1 = completed; i1 < counter -1; i1++) for (int j = i1; j < counter; j++) Δες το πρόβλημα με ένα παράδειγμα. Έστω ότι μετά την πρώτη ταξινομήση με βάση το χρόνο άφιξης έχεις αυτό τον πίνακα: P0, P1, P2, P3, P4, P5, P6, P7, P8, P9 Έστω ακόμα ότι εκτελέστηκε η P0, συνεπώς: completed = 1; Ας υποθέσουμε πως οι διεργασίες P1 ως P7 έχουν τον ίδιο χρόνο άφιξης. Επομένως πρέπει να ταξινομήσουμε τον πίνακα των διεργασιών, μεταξύ (και συμπεριλαμβάνοντας) των δεικτών 1 και 7. Με βάση τον κώδικα σου θα ισχύει: counter = 7 Άρα: for (int i1 = 1; i1 < 6; i1++) for (int j = i1; j < 7; j++) Ή αλλιώς γραμμένο for (int i1 = 1; i1 <= 5; i1++) for (int j = i1; j <= 6; j++) Κοινώς, ο κώδικας σου, στο συγκεκριμένο παράδειγμα, θα ταξινομούσε τις διεργασίες P1 ως P6, που είναι λάθος. Ο δείκτης της P7 είναι ίσος με: "Δείκτης της τελευταίας διεργασίας που εκτελέστηκε" + "Αριθμός διεργασιών που έφτασαν όσο εκτελούταν η τελευταία διεργασία (περιμένουν στην ουρά)" = (completed - 1) + counter Άρα οι σωστές επαναλήψεις για την ταξινόμηση είναι: for (int i1 = completed; i1 < completed - 1 + counter; i1++) for (int j = i1; j <= completed - 1 + counter; j++) Κερασμένο το tip. Το αφήνω σε εσένα αν θες να προχωρήσεις το project για να μου αφήσεις μια καλή κριτική.
€8 EUR in 0 day
0.0 (0 reviews)
3.8
3.8
7 freelancers are bidding on average €51 EUR for this job
User Avatar
Hi Sir, I am ready to work for you.I have 8 years of experience in C/C++/java and Iphone/android. please see some of my works also check my reviews you will get better idea about my skill.I deliver quality work within time frame. Please visit my profile once. Thanks with regards, Amit
€52 EUR in 3 days
4.9 (58 reviews)
6.4
6.4
User Avatar
Hi, I am C++ expert and can help you with this project, Please let me know if you are interested. Thank You
€30 EUR in 1 day
4.8 (119 reviews)
6.1
6.1
User Avatar
I am very proficient in c, c++. I have 15 years c++ developing experience now, and I have worked for 5 years. My work is online game developing, and mainly focus on server side, the lauguage is c++ under linux os. So, programming in c++ is never a problem. I used c++ to make many great projects, for example, I made the tools which can convert java files to c++ with the same meaning, ofcourse garbage collection included. I made our own mobile game using c++, I even can show you the demo of client. Trust me, please let expert help you.
€28 EUR in 2 days
4.7 (20 reviews)
5.1
5.1
User Avatar
Hi. i can help you to fix your program. please give me a chance to work on your file and prove my ability. thank you.
€29 EUR in 1 day
5.0 (7 reviews)
4.0
4.0
User Avatar
Can help... I am an Expert... Please check the past projects I have handled and check my reviews for what employers have to say about my work... Can start right now...
€200 EUR in 7 days
0.0 (0 reviews)
0.0
0.0
User Avatar
I have made the changes , Hope below one will solve your purpose. for (i = completed; i < nPages; i++) { //find how many processes have smaller arrival time than the current time for (j = completed; j < nPages; j++) { if (arrival[j]<=Totaltime) //This will ensure till now i have following process { if (i!=j) //i.e. no need to match with own { if (burst[i] > burst[j]) { tmp = burst[i]; burst[i] = burst[j]; burst[j] = tmp; tmp = index [i]; index[i] = index [j]; index[j] = tmp; tmp = arrival [i]; arrival[i]=arrival[j]; arrival[j]=tmp; } } } //end of if (arrival[j]<=Totaltime) //Here either we did shorting or not...but one job has been completed } printf ("\n%lf\t%lf\t%lf\t%lf\t%lf",index[i],burst[i],arrival[i],(Totaltime-arrival[i]),(Totaltime+=burst[i])); counter=0; Totaltime+=burst[i]; sumTotaltime += Totaltime; completed++; turnaroundtime[i]=Totaltime-arrival[i]; sumturnaroundtime+=turnaroundtime[i]; sumWaitTime+=Totaltime-arrival[i]-burst[i]; }
€9 EUR in 3 days
0.0 (0 reviews)
0.0
0.0

About the client

Flag of GREECE
athens, Greece
5.0
4
Payment method verified
Member since Dec 23, 2012

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.