-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7PAGE_REPLACEMENT_FIFO.cxx
95 lines (73 loc) · 1.5 KB
/
7PAGE_REPLACEMENT_FIFO.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<queue>
using namespace std;
int n; //Number of Frames in main memory
queue<char>ongoing;
bool present_in(char ch)
{
queue<char>local;
local=ongoing;
while(local.size()!=0)
{
if(local.front()==ch)
{
return true;
}
local.pop();
}
return false;
}
void fifo(char string[])
{
char ch;
int i=0;
float fault=0;
float hit=0;
bool present;
ch=string[0];
while(ch!='\0')
{
if(ongoing.size()!=n)
{
present=present_in(ch);
if(present)
hit=hit+1;
else
{
ongoing.push(ch);
fault=fault+1;
}
}
else
{
present=present_in(ch);
if(present)
hit=hit+1;
else
{
ongoing.pop();
ongoing.push(ch);
fault=fault+1;
}
}
i++;
ch=string[i];
}
float hit_ratio,miss_ratio;
hit_ratio=hit/i;
miss_ratio=fault/i;
cout<<"\nNUMBER OF PAGES IN STRING IS "<<i;
cout<<"\nNUMBER OF FAULTS IS "<<fault;
cout<<"\nNUMBER OF HITS IS "<<hit;
cout<<"\nHIT RATIO "<<hit_ratio;
cout<<"\nMISS RATIO "<<miss_ratio;
}
int main()
{
char string[40];
cout<<"\n Enter the string ";
cin>>string;
cout<<"\nEnter number of frames ";
cin>>n;
fifo(string);
}