You are on page 1of 12

QUESTION 1:

#include<iostream>
#include<queue>
using namespace std;
int iD = 5000;
struct node{
int id;
int arival;
int burst;

node *next = NULL;


};
void menu();
node*head=NULL,*rare=NULL;
void create_node()
{
node*obj = new node();
obj->id = iD;
iD++;
cout << "ENTER BURST TIME : ";
cin>>obj->burst;
cout << "ENTER ARIVAL TIME : ";
cin >> obj->arival;

if (head == NULL)
{

head = obj;
rare = head;
cout << "SUCESSFULL" << endl;
}
else{
rare->next = obj;
rare = rare->next;
}
menu();
}
void delete_node()
{
node*ptr = head; int in_id = 0;
cout << "ENTER PROCESS ID to DELETE PROCESS " << endl;
while (ptr != NULL)
{

cout << "PROCESS ID = " << ptr->id << endl;


ptr = ptr->next;
}
cin >> in_id;
ptr = head;
node*ptr2 = head;
while (ptr->next != NULL)
{
ptr2 = ptr;
ptr = ptr->next;
if (ptr->id == in_id)
{
ptr2->next = ptr->next;
delete(ptr);

}
void calculate_turntime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{
cout << ptr->id << " " << ptr->burst << endl;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
cout << ptr->id << " " << turn << endl;
}

ptr = ptr->next;
}

}
void calculate_waittime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait=0;
while (ptr != NULL)
{
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
ptr = ptr->next;
}

}
void calculate_averageturn()
{
int average=0;
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{

average += ptr->burst;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
average += turn;

}
cout << "AVERAGE TURNAROUND = " << average << endl;

ptr = ptr->next;
}

}
void calculate_averagewait()
{
node*ptr = head; int count = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait = 0;
int average=0;
while (ptr != NULL)
{
count++;
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
average += wait;
ptr = ptr->next;
}
cout << "AVERAGE WAIT= " << average << endl;

}
void menu()
{
system("pause");
system("cls");
int a = 0;
cout << "PRESS 1 TO ADD NEW PROCESS " << endl;
cout << "PRESS 2 TO DELETE NODE " << endl;
cout << "Press 3 TO VIEW AVERAGE TURN AROUND TIME " << endl;
cout << "PRESS 4 TO VIEW AVERAGE WAIT TIME" << endl;
cout << "PRESS 5 TO VIEW WAITING TIME " << endl;
cout << "PRESS 6 TO VIEW TURN AROUND TIME" << endl;
cin >> a;
if (a == 1)
{
create_node();
}
else if (a == 2)
{
delete_node();
}
else if (a == 3)
{
calculate_averageturn();
}
else if (a == 4)
{
calculate_averagewait();

}
else if (a == 5)
{
calculate_waittime();
}
else if (a == 6)
{
calculate_turntime();
}
}
int main()
{
menu();

system("pause");
return 0;
}

QUESTION 2
#include<iostream>
#include<queue>
using namespace std;
int iD = 5000;
struct node{
int id;
int arival;
int burst;

node *next = NULL;


};
void menu();
void sort(node*st);
node*head=NULL,*rare=NULL;
void create_node()
{
node*obj = new node();
obj->id = iD;
iD++;
cout << "ENTER BURST TIME : ";
cin>>obj->burst;
cout << "ENTER ARIVAL TIME : ";
cin >> obj->arival;

if (head == NULL)
{

head = obj;
rare = head;
cout << "SUCESSFULL" << endl;
}
else{
rare->next = obj;
rare = rare->next;
}
sort(head);
menu();
}
void delete_node()
{
node*ptr = head; int in_id = 0;
cout << "ENTER PROCESS ID to DELETE PROCESS " << endl;
while (ptr != NULL)
{

cout << "PROCESS ID = " << ptr->id << endl;


ptr = ptr->next;
}
cin >> in_id;
ptr = head;
node*ptr2 = head;
while (ptr->next != NULL)
{
ptr2 = ptr;
ptr = ptr->next;
if (ptr->id == in_id)
{
ptr2->next = ptr->next;
delete(ptr);

}
void calculate_turntime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{
cout << ptr->id << " " << ptr->burst << endl;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
cout << ptr->id << " " << turn << endl;
}

ptr = ptr->next;
}

}
void calculate_waittime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait=0;
while (ptr != NULL)
{
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
ptr = ptr->next;
}

}
void calculate_averageturn()
{
int average=0;
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{

average += ptr->burst;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
average += turn;

}
cout << "AVERAGE TURNAROUND = " << average << endl;

ptr = ptr->next;
}

}
void calculate_averagewait()
{
node*ptr = head; int count = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait = 0;
int average=0;
while (ptr != NULL)
{
count++;
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
average += wait;
ptr = ptr->next;
}
cout << "AVERAGE WAIT= " << average << endl;

}
void swap(node*a, node*b){
int temp = a->burst;
int temp1 = a->arival;
a->arival = b->arival;
b->arival = temp1;
a->burst = b->burst;
b->burst = temp;
temp1 = a->id;
a->id = b->id;
b->id = temp1;
}
void sort(node*st)
{
int swapped = 0;
node*ptr1;
node * lptr = NULL;
if (st == NULL){
return;
}
do{
swapped = 0;
ptr1 = st;
while (ptr1->next != lptr){
if (ptr1->burst > ptr1->next->burst){
swap(ptr1,ptr1->next);
swapped = 1;
}
ptr1 = ptr1->next;
}
lptr = ptr1;
} while (swapped);

}
void menu()
{
system("pause");
system("cls");
int a = 0;
cout << "PRESS 1 TO ADD NEW PROCESS " << endl;
cout << "PRESS 2 TO DELETE NODE " << endl;
cout << "Press 3 TO VIEW AVERAGE TURN AROUND TIME " << endl;
cout << "PRESS 4 TO VIEW AVERAGE WAIT TIME" << endl;
cout << "PRESS 5 TO VIEW WAITING TIME " << endl;
cout << "PRESS 6 TO VIEW TURN AROUND TIME" << endl;
cout << "PRESS 7 TO EXIT " << endl;
cin >> a;
if (a == 1)
{
create_node();
}
else if (a == 2)
{
delete_node();
}
else if (a == 3)
{
calculate_averageturn();
}
else if (a == 4)
{
calculate_averagewait();

}
else if (a == 5)
{
calculate_waittime();
}
else if (a == 6)
{
calculate_turntime();
}
else if (a == 7)
{

exit(1);
}
}
int main()
{
menu();

system("pause");
return 0;
}

QUESTION 3
#include<iostream>
#include<queue>
using namespace std;
int iD = 5000;
struct node{
int id;
int arival;
int burst;
int pri;
node *next = NULL;
};
void menu();
void sort(node*st);
node*head=NULL,*rare=NULL;
void create_node()
{
node*obj = new node();
obj->id = iD;
iD++;
cout << "ENTER BURST TIME : ";
cin>>obj->burst;
cout << "ENTER ARIVAL TIME : ";
cin >> obj->arival;
cout << "ENTER PRIORITY : ";
cin >> obj->pri;

if (head == NULL)
{

head = obj;
rare = head;
cout << "SUCESSFULL" << endl;
}
else{
rare->next = obj;
rare = rare->next;
}
sort(head);
menu();
}
void delete_node()
{
node*ptr = head; int in_id = 0;
cout << "ENTER PROCESS ID to DELETE PROCESS " << endl;
while (ptr != NULL)
{

cout << "PROCESS ID = " << ptr->id << endl;


ptr = ptr->next;
}
cin >> in_id;
ptr = head;
node*ptr2 = head;
while (ptr->next != NULL)
{
ptr2 = ptr;
ptr = ptr->next;
if (ptr->id == in_id)
{
ptr2->next = ptr->next;
delete(ptr);

}
void calculate_turntime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{
cout << ptr->id << " " << ptr->burst << endl;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
cout << ptr->id << " " << turn << endl;
}

ptr = ptr->next;
}

}
void calculate_waittime()
{
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait=0;
while (ptr != NULL)
{
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
ptr = ptr->next;
}

}
void calculate_averageturn()
{
int average=0;
node*ptr = head; int in_id = 0;
cout << "PROCESS ID " << " " << "TURNAROUND" << endl;
int turn, wait = 0; int count = 0;
while (ptr != NULL)
{
count++;
if (count == 1)
{

average += ptr->burst;
wait = ptr->burst;
}
else{
turn = wait + ptr->burst;
average += turn;

}
cout << "AVERAGE TURNAROUND = " << average << endl;
ptr = ptr->next;
}

}
void calculate_averagewait()
{
node*ptr = head; int count = 0;
cout << "PROCESS ID " << " " << "WaitingTime" << endl;
int wait = 0;
int average=0;
while (ptr != NULL)
{
count++;
cout << ptr->id << " " << wait << endl;
wait += ptr->burst;
average += wait;
ptr = ptr->next;
}
cout << "AVERAGE WAIT= " << average << endl;

}
void swap(node*a, node*b){
int temp = a->burst;
int temp1 = a->arival;
int temp2 = a->pri;
a->arival = b->arival;
b->arival = temp1;
a->burst = b->burst;
b->burst = temp;
temp1 = a->id;
a->id = b->id;
b->id = temp1;
a->pri = b->pri;
b->pri = temp2;
}
void sort(node*st)
{
int swapped = 0;
node*ptr1;
node * lptr = NULL;
if (st == NULL){
return;
}
do{
swapped = 0;
ptr1 = st;
while (ptr1->next != lptr){
if (ptr1->pri < ptr1->next->pri){
swap(ptr1,ptr1->next);
swapped = 1;
}
ptr1 = ptr1->next;
}
lptr = ptr1;
} while (swapped);

}
void menu()
{
system("pause");
system("cls");
int a = 0;
cout << "PRESS 1 TO ADD NEW PROCESS " << endl;
cout << "PRESS 2 TO DELETE NODE " << endl;
cout << "Press 3 TO VIEW AVERAGE TURN AROUND TIME " << endl;
cout << "PRESS 4 TO VIEW AVERAGE WAIT TIME" << endl;
cout << "PRESS 5 TO VIEW WAITING TIME " << endl;
cout << "PRESS 6 TO VIEW TURN AROUND TIME" << endl;
cout << "PRESS 7 TO EXIT " << endl;
cin >> a;
if (a == 1)
{
create_node();
}
else if (a == 2)
{
delete_node();
}
else if (a == 3)
{
calculate_averageturn();
}
else if (a == 4)
{
calculate_averagewait();

}
else if (a == 5)
{
calculate_waittime();
}
else if (a == 6)
{
calculate_turntime();
}
else if (a == 7)
{

exit(1);
}
}
int main()
{
menu();

system("pause");
return 0;
}

You might also like