By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,844 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,844 IT Pros & Developers. It's quick & easy.

First In First Serve Using Data Structures in C++

P: 3
my sample code here
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5.  
  6. struct process
  7. {
  8. int pn;
  9. float at,bt,ct,tat,wt;
  10. struct process *next;
  11. }process;
  12. ////////////////////////////////////////////////////
  13.  
  14. float total_wait_time=0,total_turn_around_time=0;
  15. int n;
  16.  process *get_process(float a,float b)
  17. {
  18. static int i=1;
  19. pr=new(process);
  20. pr->at=a,pr->bt=b;
  21. pr->pn=i++;
  22. pr->next=NULL;
  23. return pr;
  24.  
  25. void insert(process *ptr,float a,float b)
  26. {
  27. process *pro,*temp;
  28. pro=get_process(a,b);
  29. while(ptr->next!=NULL)
  30. {
  31. temp=ptr;
  32. ptr=ptr->next;
  33. if(ptr->at>a);
  34. {
  35. pro->next=ptr;
  36. temp->next=pro;
  37. return;
  38. }
  39. }
  40. ptr->next=pro;
  41. }
  42. void display(process *ptr)
  43. {process *temp=ptr->next;
  44. cout<<"Process\tArrival time\tBurst time\tCompletion time\tWaiting time\tTurn arround time\n";
  45. while(temp!=NULL)
  46. {
  47. cout<<"P[%d]\t%3.2f\t\t%3.2f\t\t%3.2f\t\t%3.2f\t\t%3.2f\n",temp->pn,temp->at,temp->bt,temp->ct,temp->wt,temp->tat;
  48. temp=temp->next;
  49. }
  50. cout<<"Average waiting time :%3.2f\nAverage turn arround time :%3.2f\n",total_wait_time/n,total_turn_around_time/n;
  51. }
  52. void ganttchart(process *ptr)
  53. {
  54. process *temp,*t;
  55. temp=ptr->next;
  56. t=ptr;
  57. while(temp!=NULL)
  58. {
  59. temp->ct=t->ct+temp->bt;
  60. t=temp;
  61. temp=temp->next;
  62. }
  63. }
  64. void wt_and_tat(process *ptr)
  65. while(temp!=NULL)
  66. {
  67. temp->tat=temp->ct-temp->at;
  68. total_turn_around_time+=temp->tat;
  69. temp->wt=temp->tat-temp->bt;
  70. total_wait_time+=temp->wt;
  71. temp=temp->next;
  72. }
  73. }
  74. ////////////////////////////////////////////////////////////////
  75.  
  76. int main()
  77. {
  78. int i;
  79. float a,b;
  80. start=new(process);
  81. start->next=NULL;
  82. cout<<"=========FCFS Algo==========\nEnter the no. of process : ";
  83. cin>>&n;
  84. for(i=0;i<n;i++)
  85. {
  86. cout<<"Process P("<<i+1<<")\n";
  87. cout<<"Arival time ?";
  88. cin>>&b;
  89. insert(start,a,b);
  90. cout<<"\n";
  91. ganttchart(start);
  92. wt_and_tat(start);
  93. display(start);
  94. return 0;
  95. }
  96.  
  97.  
  98.  
.
In my code,
I am getting an error like this"error: excepted constructor, destructor, or type conversion before'*' token"
Please, help me out this to overcome this error.
Mar 28 '19 #1
Share this Question
Share on Google+
5 Replies


P: 60
Mind showing more of your code?
Mar 29 '19 #2

P: 3
Can U please help me now
Mar 29 '19 #3

P: 60
I tried to run the code in CodeBlocks. It showed me tons of errors. Also, I couldn't find the one you asked for. Looks like you are implementing FCFS CPU scheduling algo. Maybe try to post the code after removing the basic syntax errors of curly braces and stuff.
Mar 29 '19 #4

P: 3
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. #include<stdlib.h>
  4.  
  5. typedef struct process
  6.  
  7. {
  8.  
  9. int pn;
  10.  
  11. float at,bt,ct,tat,wt;
  12.  
  13. struct process *next;
  14.  
  15. }process;
  16.  
  17. /////////////////////////////////////////
  18.  
  19. float total_wait_time=0,total_turn_around_time=0;
  20.  
  21. int n;
  22.  
  23. process *get_process(float a,float b)
  24.  
  25. {
  26.  
  27. static int i=1;
  28.  
  29. process *pr=(process *)malloc(sizeof(process));
  30.  
  31. pr->at=a,pr->bt=b;
  32.  
  33. pr->pn=i++;
  34.  
  35. pr->next=NULL;
  36.  
  37. return pr;
  38.  
  39. }
  40.  
  41. void insert(process *ptr,float a,float b)
  42.  
  43. {
  44.  
  45. process *pro,*temp;
  46.  
  47. pro=get_process(a,b);
  48.  
  49. while(ptr->next!=NULL)
  50.  
  51. {
  52.  
  53. temp=ptr;
  54.  
  55. ptr=ptr->next;
  56.  
  57. if(ptr->at>a)
  58.  
  59. {
  60.  
  61. pro->next=ptr;
  62.  
  63. temp->next=pro;
  64.  
  65. return;
  66.  
  67. }
  68.  
  69. }
  70.  
  71. ptr->next=pro;
  72.  
  73. }
  74.  
  75. void display(process *ptr)
  76.  
  77. {
  78.  
  79. process *temp=ptr->next;
  80.  
  81. printf("Process\tArrival time\tBurst time\tCompletion time\tWaiting time\tTurn arround time\n");
  82.  
  83. while(temp!=NULL)
  84.  
  85. {
  86.  
  87. printf("P[%d]\t%3.2f\t\t%3.2f\t\t%3.2f\t\t%3.2f\t\t%3.2f\n",temp->pn,temp->at,temp->bt,temp->ct,temp->wt,temp->tat);
  88.  
  89. temp=temp->next;
  90.  
  91. }
  92.  
  93. printf("Average waiting time :%3.2f\nAverage turn arround time :%3.2f\n",total_wait_time/n,total_turn_around_time/n);
  94.  
  95. }
  96.  
  97. void ganttchart(process *ptr)
  98.  
  99. {
  100.  
  101. process *temp,*t;
  102.  
  103. temp=ptr->next;
  104.  
  105. t=ptr;
  106.  
  107. while(temp!=NULL)
  108.  
  109. {
  110.  
  111. temp->ct=t->ct+temp->bt;
  112.  
  113. t=temp;
  114.  
  115. temp=temp->next;
  116.  
  117. }
  118.  
  119. }
  120.  
  121. void wt_and_tat(process *ptr)
  122.  
  123. {
  124.  
  125. process *temp=ptr->next;
  126.  
  127. while(temp!=NULL)
  128.  
  129. {
  130.  
  131. temp->tat=temp->ct-temp->at;
  132.  
  133. total_turn_around_time+=temp->tat;
  134.  
  135. temp->wt=temp->tat-temp->bt;
  136.  
  137. total_wait_time+=temp->wt;
  138.  
  139. temp=temp->next;
  140.  
  141. }
  142.  
  143. }
  144.  
  145. //////////////////////////////
  146.  
  147. int main()
  148.  
  149. {
  150.  
  151. int i;
  152.  
  153. float a,b;
  154.  
  155. process *START=(process *)malloc(sizeof(process));
  156.  
  157. START->next=NULL;
  158.  
  159. printf("=========FCFS Algo==========\nEnter the no. of process : ");
  160.  
  161. scanf("%d",&n);
  162.  
  163. for(i=0;i<n;i++)
  164.  
  165. {
  166.  
  167. printf("Process P(%d) \n",i+1);
  168.  
  169. printf("Arival time ? ");
  170.  
  171. scanf("%f",&a);
  172.  
  173. printf("Exicution time ? ");
  174.  
  175. scanf("%f",&b);
  176.  
  177. insert(START,a,b);
  178.  
  179. printf("\n");
  180.  
  181. }
  182.  
  183. ganttchart(START);
  184.  
  185. wt_and_tat(START);
  186.  
  187. display(START);
  188.  
  189. return 0;
  190.  
  191. }
  192.  
  193.  
Can U please change this to C++
Mar 29 '19 #5

Post your reply

Sign in to post your reply or Sign up for a free account.