-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment.cpp
65 lines (57 loc) · 1.54 KB
/
assignment.cpp
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
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<vector>
#include<unistd.h>
using namespace std;
// This function will work for the interactive process
int interactive(){
int r;
int start_s=clock();
r=rand()%128;
cout<<endl<<r<<" "<<char(r);
int stop_s=clock();
cout <<endl<< "time: " << (stop_s-start_s)/double(CLOCKS_PER_SEC) << endl;
return(r);
}
//For non interactive process this function will which include wait
int non_interactive(){
int r;
int milliseconds=3000;
int start_s=clock();
r=rand()%128;
clock_t time_end;
time_end = clock() + milliseconds * CLOCKS_PER_SEC/1000;
while (clock() < time_end)
{
}
int stop_s=clock();
cout <<endl<< "time: " << (stop_s-start_s)/double(CLOCKS_PER_SEC) << endl;
return(r);
}
int main(){
int a,b=20,c;
vector<char> high_priority; //Queue for high priority
vector<char> low_priority; //Queue for low priority
while(b>0){
a=rand()%2;
cout<<endl<<a;
if(a==0){
c=interactive();
high_priority.push_back(char(c));
}
else{
c=non_interactive();
low_priority.push_back(char(c));
}
b--;
}
cout<<endl<<"High Priority queue"<<endl;
for(int i=0;i<high_priority.size();i++){
cout<<high_priority[i]<<" ";
}
cout<<endl<<"Low priority queue"<<endl;
for(int i=0;i<low_priority.size();i++){
cout<<low_priority[i]<<" ";
}
}