943,850 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5630
  • C++ RSS
May 31st, 2004
0

Send Me The Code For Round Robin

Expand Post »
plz anyone can send me the code for Round Robin simulation ???
send that to ur_friend_qau@hotmail.com
plz its very urgent
i got only 12 hrs
plzzzzzzzzzzzzzzzzzzzzzz
ALLAH HAFIZ
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Diya is offline Offline
2 posts
since May 2004
May 31st, 2004
0

Re: Send Me The Code For Round Robin

Our policy here is to not help you with schoolwork unless you have shown some effort yourself. We are willing to be helpful and act as tutors, but we have our own work to do and not enough time to do everyone else's with no recognition.

However, in this case. You're in luck. A round robin scheduler has already been posted in our code snippets forum it seems: http://www.daniweb.com/forums/showthread.php?t=5027 Please note it's provided as-is. If you want more help, show that you're willing to learn.
Last edited by cscgal; May 31st, 2004 at 4:40 pm.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,645 posts
since Feb 2002
May 31st, 2004
0

Re: Send Me The Code For Round Robin

well i had sent that msg to get help after getting stuck in ma code........
here is my effort of 3 days

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<stdio.h>
  6. #include<math.h>
  7.  
  8.  
  9. struct node
  10. {
  11. long program_no;
  12. long arrival_time;
  13. long cpu_time;
  14.  
  15. node *F;
  16. node *B;
  17. }*wq,*rq;
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. void menu(); //For the display of menu
  25. void wqueue();
  26. node* ready_process();
  27. void display_queue(node *);
  28. void rqueue(node *);
  29. void running();
  30. void interval(node *);
  31. long input_pno_check(long);
  32. long input_int();//For integer Input
  33.  
  34.  
  35. long ts=0;
  36. int TIME=0;
  37.  
  38.  
  39. //////////////////////////Start of main////////////////////////////////////
  40. void main()
  41. {
  42. rq=wq=NULL;
  43.  
  44. clrscr();
  45. char str[10];
  46. int n;
  47. menu();
  48.  
  49. cout<<"\nEnter The No Of Processes ::" ; n=input_int();
  50.  
  51. for(int i=0;i<n;i++)
  52. wqueue();
  53.  
  54. cout<<"\n\n\nEnter The Time Slice ::" ; ts=input_int();
  55. display_queue(wq);
  56.  
  57. node *r;
  58.  
  59. while(wq!=NULL || rq!=NULL)
  60. {
  61.  
  62. do{
  63.  
  64. if(wq!=NULL)
  65. {
  66. r=ready_process();
  67.  
  68. if(TIME==0)
  69. TIME= r->arrival_time;
  70.  
  71.  
  72.  
  73. while(wq!=NULL && r->arrival_time<=TIME)
  74. {
  75. rqueue(r);
  76. if(wq!=NULL)
  77. r=ready_process();
  78. }
  79. running();
  80. }
  81.  
  82.  
  83.  
  84. }while(wq!=NULL && r->arrival_time<=TIME);
  85.  
  86. running();
  87.  
  88. }
  89.  
  90.  
  91.  
  92. cout<<"\n\nAll Process Completed Successfully ::: ";
  93. getch();
  94. }
  95. ///////////////////
  96. ///////End of main////////////////////////////////////
  97.  
  98.  
  99.  
  100. ////////////////////////////Page No input////////////////////////////
  101. long input_pno_check(long pno)
  102. {
  103.  
  104. for(node *p=wq; p!=NULL;p=p->F)
  105. if(p->program_no==pno) //Pagram No Already Exist
  106. return 0; // Return 0 if program id exists
  107.  
  108.  
  109. return -1;
  110. }
  111. /////////////////////////End Of Page No Input////////////////////////
  112.  
  113.  
  114. ///////////////////////////////////////////////////////////////////////
  115.  
  116. void wqueue()
  117. {
  118. cout<<endl;
  119. int valid,pno;
  120.  
  121. cout<<"Enter The Program Id ::";
  122. do{
  123. valid=-1;
  124. pno=input_int();
  125. valid=input_pno_check(pno);
  126. if(valid==0)
  127. cout<<"Program id Already Exist ::\nEnter The Program Id ::";
  128. }while(valid==0);
  129.  
  130.  
  131.  
  132. node *p=new node;
  133. p->program_no =pno; //so creating new nodes
  134. cout<<"Arrival Time ::";p->arrival_time =input_int();
  135. cout<<"CPU Time ::";p->cpu_time =input_int();
  136. p-> F =NULL;
  137. p-> B =NULL;
  138.  
  139. if(wq==NULL)
  140. wq=p;
  141. else
  142. {
  143. node *q=wq;
  144. while(q->F!=NULL)
  145. q=q->F;
  146.  
  147. q->F=p;
  148. p->B=q;
  149. }
  150.  
  151.  
  152. }
  153. /////////////////////////////////////////*****************//////////////////
  154.  
  155. void rqueue(node* program)
  156. {
  157.  
  158.  
  159. cout<<"\nTime "<<TIME<<" :: Process "<<program->program_no<<" Ready ::\n";
  160.  
  161.  
  162. // Remove node from wq
  163. {
  164.  
  165. if(program==wq)
  166. {
  167. wq=wq->F;
  168. wq->B=NULL;
  169. }
  170.  
  171. else
  172. {
  173. program->B->F=program->F;
  174. program->F->B=program->B;
  175. }
  176. program->B=NULL;
  177. program->F=NULL;
  178.  
  179. } //end of remove from wq
  180.  
  181.  
  182. if(rq==NULL)
  183. rq=program;
  184. else
  185. {
  186. /*
  187. program->F=rq;
  188. rq->B=program;
  189. rq=program;
  190. */
  191.  
  192. node *q=rq;
  193. while(q->F!=NULL)
  194. q=q->F;
  195.  
  196. q->F=program;
  197. program->B=q;
  198.  
  199. }
  200.  
  201.  
  202. }
  203. /////////////////////////////////////////*****************//////////////////
  204.  
  205. node* ready_process()
  206. {
  207. node *p,*q;
  208.  
  209. p=wq;
  210. q=wq;
  211.  
  212. while(q->F!=NULL)
  213. q=q->F;
  214.  
  215.  
  216. while(p!=q)
  217. {
  218. if(p->arrival_time > q->arrival_time)
  219. p=p->F;
  220. else
  221. q=q->B;
  222. }
  223. return p;
  224.  
  225.  
  226. }
  227. ////////////////////////////////////////////////////////////
  228. void running()
  229. {
  230. node *p=rq,*r;
  231.  
  232. if(p->cpu_time>ts)
  233. {
  234. cout<<"\nTime "<<TIME<<" :: Process "<<p->program_no<<" Running ::\n";
  235. p->cpu_time=p->cpu_time-ts;
  236.  
  237. for(int i=0;i<ts;i++)
  238. {
  239. TIME++;
  240.  
  241. if(wq!=NULL)
  242. r=ready_process();
  243. if(wq!=NULL && r->arrival_time<=TIME)
  244. {
  245. rqueue(r);
  246.  
  247. }
  248. }
  249.  
  250. }
  251. else if (p->cpu_time==ts)
  252. {
  253. cout<<"\nTime "<<TIME<<" :: Process "<<p->program_no<<" Running ::\n";
  254. interval(p);
  255. p->cpu_time=p->cpu_time-ts;
  256. }
  257. else
  258. {
  259. cout<<"\nTime "<<TIME<<" :: Process "<<p->program_no<<" Running ::\n";
  260. interval(p);
  261. p->cpu_time=0;
  262. }
  263.  
  264. if(p->cpu_time==0)
  265. {
  266. rq=rq->F;
  267. rq->B=NULL;
  268. delete p;
  269. p=NULL;
  270. }
  271.  
  272. if(p!=NULL && p->F!=NULL)
  273. {
  274. rq=rq->F;
  275. rq->B=NULL;
  276. p->F=NULL;
  277.  
  278. for(node*q=rq;q->F!=NULL;q=q->F);
  279. q->F=p;
  280. p->B=q;
  281. }
  282.  
  283.  
  284.  
  285. }
  286. /////////////////////////////////////////////////////////////
  287. void interval(node *p)
  288. {
  289.  
  290. node *r;
  291. for(int i=0;i<p->cpu_time;i++)
  292. {
  293. TIME++;
  294.  
  295. if(wq!=NULL)
  296. r=ready_process();
  297. if(wq!=NULL && r->arrival_time<=TIME)
  298. {
  299. rqueue(r);
  300. cout<<"\nTime "<<TIME<<" :: Process "<<p->program_no<<" Running ::\n";
  301. }
  302. }
  303.  
  304. cout<<"\nTime "<<TIME<<" :: Process "<<p->program_no<<" Done ::\n";
  305.  
  306. char ch;
  307. cout<<"\n\nDo You Want To Initiate AnOther Process [Y/N] :: ";cin>>ch;
  308. if(ch=='y'||ch=='Y')
  309. wqueue();
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318. }
  319.  
  320.  
  321. /////////////////To Display List wq and rd Both////////////////
  322. void display_queue(node *top)
  323. {
  324.  
  325. cout<<"\nProgram ID\tArrival Time\tCPU Time\t" ;
  326. cout<<"\n----------\t------------\t--------\t"<<endl ;
  327. long i=0;
  328.  
  329. for(node *p=top;p!=NULL;p=p->F)
  330. {
  331.  
  332. cout<<p->program_no<<"\t\t";
  333. cout<<p->arrival_time<<"\t\t";
  334. cout<<p->cpu_time<<"\t\t";
  335. cout<<endl;
  336. i++; //counting the number
  337.  
  338. }
  339. cout<<"Total Process ::"<<i<<endl<<endl;
  340.  
  341. }
  342. //////////////////End of display function////////////////
  343.  
  344.  
  345.  
  346. /////////////////Start of integer input Function////////////////////////////
  347.  
  348. long input_int() //this function control wrong entry checks in integer values
  349. {
  350. char str[8];
  351. long len=0,flag,value;
  352.  
  353. do
  354. {
  355. flag=0;
  356. gets(str);
  357. len=strlen(str);
  358.  
  359. for (long i=0;i<len;i++)
  360. {
  361. if (str[i] < 48 || str[i] > 57)
  362. flag=1;
  363. }
  364.  
  365. if (flag==1 || len<1) cout<<"Data Type Mismatch::\nEnter The Value Again :: " ;
  366.  
  367. value=atol(str);
  368.  
  369.  
  370. }
  371. while(flag==1 ||len<1);
  372.  
  373. return (value);
  374. }
  375. /////////////////End of integer input Function////////////////////////////
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392. //////////////////Start of Menu Function//////////////////////////////////
  393. void menu()
  394. {
  395. cout<<"ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n";
  396. cout<<"³ ////******THIS IS SIMULATED ENVIRNOMENT FOR ³\n";
  397. cout<<"³ ROUND ROBIN FOR N PROCESSES*********/////// ³\n";
  398. cout<<"³ ³\n";
  399. cout<<"³ ENTER THE FOLLOWING REQUIRED VALUES TO GET THE RESULTS: ³\n";
  400. cout<<"³ ³\n";
  401. cout<<"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n";
  402. }
  403.  
  404. //////////////////End of Menu Function//////////////////////////////////
Last edited by cscgal; May 31st, 2004 at 11:34 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Diya is offline Offline
2 posts
since May 2004
Jul 1st, 2004
0

Re: Send Me The Code For Round Robin

can u help post the round robin flow chart to make it easier for me to understand rr process
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WooF is offline Offline
2 posts
since Jul 2004
Oct 17th, 2004
0

Re: Send Me The Code For Round Robin

Heyy dani...

this thread is not working...cud u please see thru it...

zich
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zaizch is offline Offline
1 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Function[Array] in combination with cin>>
Next Thread in C++ Forum Timeline: endless loop? not sure why, any suggestions?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC