1- find wait time
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
float b[4];
float w=0;
float p1=0, p2, p3, p4;
for (int i = 0; i < 4; i++)
{
cout << "enter the burst time for process: ";
cin >> b[i];
}
for (int i = 0; i < 4; i++)
{
cout << "\n process= " << i << "\tthe burst time = " << b[i] << "\n";
}
p2 = b[0];
p3 = b[0] + b[1];
p4 = b[0] + b[1] + b[2];
w = (p1 + p2 + p3 + p4)/4;
cout << "\n wait time p1 = " << p1 << endl;
cout << "\n wait time p2 = " << p2 << endl;
cout << "\n wait time p3 = " << p3 << endl;
cout << "\n wait time p4 = " << p4 << endl;
cout << "\n wait time all = " <<w<< endl;
_getch();
}
2- scheduler as queue
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class fifo
{
private:
struct node_fifo{
int data;
node_fifo *next;
};
node_fifo *front;
node_fifo *back;
int count;
public:
fifo()
{
count = 0;
front = back = NULL;
}
bool isempty(){ return count == 0; }
void insert(int item)
{
node_fifo *p = new node_fifo;
p->data = item;
if (isempty())
{
back = front = p;
back->next = p;
p->next = NULL;
}
else
{
back->next = p;
back = p;
back->next = NULL;
}
count++;
}
void display()
{
node_fifo *p = front;
while (p != NULL)
{
cout <<"process "<< p->data << "\t ";
p = p->next;
}
}
};
void main()
{
fifo q;
q.insert(1);
q.insert(2);
q.insert(3);
q.insert(4);
q.display();
_getch();
}
0 التعليقات:
إرسال تعليق