473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

First In First Serve Using Data Structures in C++

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
5 1624
dev7060
636 Expert 512MB
Mind showing more of your code?
Mar 29 '19 #2
Can U please help me now
Mar 29 '19 #3
dev7060
636 Expert 512MB
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
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

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

Similar topics

11
by: Innocence | last post by:
Hi I've been considering how to optimize map data structures for a tile based Python game. However, since I'm a Python newbie I lack experience with Pythons 'exotic' data types like lists and...
3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
5
by: el_roachmeister | last post by:
For being a good web programmer, is a course on data structures important? It seems php already has built-in functions for what they teach in a data structures course. On the other hand all...
28
by: John McCabe | last post by:
Hi I'm looking for something equivalent to the Data Structures and Algorithms in Ada 95 books by Biedler and Feldman etc, but based towards efficient C++ implementations. Does anyone know of...
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
3
by: osp | last post by:
hi to every one.... i just started out with c++ and i think i am doing well.i use Robert Laffore to study. which book should i use for data structures ? please help. thank you with regards ...
29
by: Mik0b0 | last post by:
Hallo to everyone. This fall I am going to start data structures as a part of C language course. The problem is I could not find any satisfying tutorial about structures in C. There are plenty of...
3
by: Joshua J. Kugler | last post by:
A while back, I seem to remember coming across a small program that could view and edit python data structures via a nice expanding tree view. I'm now in need of something like that (to verify...
4
by: jehugaleahsa | last post by:
Hello: When developing data structures for C#, there is an obvious performance hit when utilizing primitive types. For instance, a recent hash table implementation I wrote works exceedingly fast...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.