-
Notifications
You must be signed in to change notification settings - Fork 5
/
LRTF-Scheduling.c
122 lines (108 loc) · 3.41 KB
/
LRTF-Scheduling.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//Project done by Jatin Chauhan
#include <stdio.h>
struct student
{
int StudentId;
int FoodTakenTime;
int WaitingTime;
int TurnAroundTime;
};
void accept(struct student list[], int s);
void display(struct student list[], int s);
void scheduling(struct student list[], int s);
void waitingTime(struct student list[], int n);
void turnAroundTime(struct student list[], int n);
int main()
{
struct student data[20];
int n,i;
char c='n';
do
{
printf("Please enter the No. of Students wants to eat in mess? : ");
scanf("%d", &n);
accept(data, n);
scheduling(data, n);
waitingTime(data,n);
turnAroundTime(data,n);
display(data, n);
printf("Want to continue? press 'y' : ");
scanf("%s",&c);
}while(c=='y');
return 0;
}
void accept(struct student list[80], int s)
{
int i;
for (i = 0; i < s; i++)
{
printf("\n\nEnter data for Student #%d", i + 1);
printf("\nEnter Student id : ");
scanf("%d", &list[i].StudentId);
printf("Enter time taken for food (minuts): ");
scanf("%d", &list[i].FoodTakenTime);
}
}
void display(struct student list[80], int s)
{
int i,AvgWaitingTime=0,AvgTurnAroundTime=0;
int TotalWatingTime=0,TotalTurnAroundTime=0;
printf("\n\n\t\t\tOutput according to LRTF\n");
printf("\n\t\t\t|===============================================================|");
printf("\n\t\t\t|Student id\tFoodTakenTime\tWaitingTime\tTurnAroundTime |");
printf("\n\t\t\t|===============================================================|");
for (i = 0; i < s; i++)
{
printf("\n\t\t\t|%d\t\t%d\t\t%d\t\t%d\t\t|", list[i].StudentId, list[i].FoodTakenTime,list[i].WaitingTime,list[i].TurnAroundTime);
printf("\a\n\t\t\t|---------------------------------------------------------------|");
TotalWatingTime= TotalWatingTime+list[i].WaitingTime;
TotalTurnAroundTime= TotalTurnAroundTime+list[i].TurnAroundTime;
}
printf("\n\n\t\t\tTotal Waiting Time is: = %d",TotalWatingTime);
printf("\n\t\t\tTotal Turn around Time is: = %d\n\n",TotalTurnAroundTime);
printf("\n\n\t\t\tAverage Waiting Time is: = %d",TotalWatingTime/s);
printf("\n\t\t\tAverage Turn around Time is: = %d\n\n",TotalTurnAroundTime/s);
}
void scheduling(struct student list[80], int s)
{
int i, j;
struct student temp;
for (i = 0; i < s - 1; i++)
{
for (j = 0; j < (s - 1-i); j++)
{
if (list[j].FoodTakenTime < list[j + 1].FoodTakenTime)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
else if(list[j].FoodTakenTime == list[j + 1].FoodTakenTime)
{
if(list[j].StudentId > list[j + 1].StudentId)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
}
}
void waitingTime(struct student list[80], int n)
{
int j,total;
list[0].WaitingTime=0;
for(j=1;j<n;j++)
{
list[j].WaitingTime=list[j-1].WaitingTime+list[j-1].FoodTakenTime;
}
}
void turnAroundTime(struct student list[80], int n)
{
int j,total;
for(j=0;j<n;j++)
{
list[j].TurnAroundTime=list[j].WaitingTime+list[j].FoodTakenTime;
}
}