C++ PROGRAM TO IMPLEMENT FCFS

Please check this program if it is correct logically and let me know i

Page 1 of 1

2 Replies - 31341 Views - Last Post: 23 January 2010 - 06:37 AM Rate Topic: -----

#1 n89.saylee  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-January 09

C++ PROGRAM TO IMPLEMENT FCFS

Posted 22 March 2009 - 05:36 AM

#include<iostream.h>

class process
{
	float burst_time,wait_time;
	class process *next,*ptr;
	int max;
	public:
	void create();
	void fcfs();
}*front=NULL,*rear=NULL;

void process::create()
{
	cout<<"ENTER THE MAXIMUM NUMBER OF PROCESSES THAT CAN BE IN THE QUEUE ==> ";
	cin>>max;
	class process *new_process;
	for(int i=1;i<=max;i++)
	{
		new_process=new process;
		cout<<"ENTER THE BURST TIME OF THE PROCESS "<<i<<" ==> ";
		cin>>new_process->burst_time;
		if(front==NULL)
		{
			front=new_process;
			ptr=front;
		}
		else
		rear->next=new_process;
		rear=new_process;
	}
}

void process::fcfs()
{
	float avg_waiting_time,total_waiting_time;
	cout<<"PROCESS\tBURST TIME"<<endl;
	for(int i=1;i<=max;i++)
	{
		cout<<"P "<<i<<"\t"<<(ptr->burst_time)<<endl;
		ptr=ptr->next;
	}
	ptr=front;
	ptr->wait_time=0;
	total_waiting_time=0;
	for(i=2;i<=max;i++)
	{
		total_waiting_time=total_waiting_time+(ptr->burst_time);
		ptr=ptr->next;
		ptr->wait_time=total_waiting_time;
	}
	ptr=front;
	total_waiting_time=0;
	for(i=1;i<max;i++)
	{
		ptr=ptr->next;
		total_waiting_time=total_waiting_time+(ptr->wait_time);
	}
	avg_waiting_time=total_waiting_time/max;
	cout<<"AVERAGE WAITING TIME IS ==> "<<avg_waiting_time;
}

void main()
{
	process p;
	p.create();
	p.fcfs();
}



Is This A Good Question/Topic? 0
  • +

Replies To: C++ PROGRAM TO IMPLEMENT FCFS

#2 Rennelbludemon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-January 10

Re: C++ PROGRAM TO IMPLEMENT FCFS

Posted 23 January 2010 - 06:07 AM

Maybe this one I made is better. It just lacks of gantt chart.. I need it. Can anyone implement it on my program?

//Rennel L. de Ocampo IT2B

#include<iostream> 
#include<windows.h> //Library for clearing the screen
using namespace std;
int cont, ctr;
class FCFS{ //Class used for the simulation
  public: //public elements of the class
	void input();
	void gantt();
   
	protected:  //protected elements of the class
  float wt, bt, arr, bt2;
  float awt;
};
int main(){   //main function
  FCFS IT2B;
  cout<<"Input number of jobs.\n";
  cin>>ctr;
  if(ctr>=3&&ctr<=6){
	system("cls");
IT2B.input(); //invocation

  }else{
	cout<<"INVALID ENTRY!!\n";
	cout<<"Min is 3\nMax is 6\n Press any key to re-input.\n";
	cin>>cont;
	system("cls");
	main();
  }
  return 0;
}

  void FCFS::input() //input() function of class FCFS
  { 
	wt=0;
	bt2=0;
	cout<<"JOBS\tBT\n";
  for(arr=1;arr<=ctr;arr++){
  cout<<"Job"<<arr; cout<<"\t"; cin>>bt; cout<<"\n";
  bt2=bt+bt2;
  wt=bt2+wt;
}
awt=(wt-bt2)/ctr;
cout<<"AVERAGE WAITING TIME IS: "<<awt<<endl;
  cout<<"Press any key to continue.";
  cin>>cont;
}

/*void FCFS::gantt()
{
  
  */


Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: C++ PROGRAM TO IMPLEMENT FCFS

Posted 23 January 2010 - 06:37 AM

Please don't double post (as well as resurrecting old topics).

Quote

Can anyone implement it on my program?


We can not give you the entire code to solve your problem. We are here to assist in solving problems with code you have written, with any error messages you are getting or what isn't working the way that you expect it to, we would be more than happy to help you with those problems. If there is a topic that you don't understand we would be more than happy to help you with that as well. Make sure to post any code with in code tags like below.

:code:

Be sure to visit our tutorial and snippet areas or read the FAQS at the top of the forums. Also, take a moment to read the rules about posting topics.

Thank you for helping us to help you solve your problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1