#include <iostream> #include <conio.h> using namespace std; int time[20]; int timeLength; int pt[20]; int ptLength; class FCFS { public: void askAC() { cout << "Enter Arrival : " ; cin >> arrivalTime ; cout <<"and Cpu Burst : "; cin >> cpuBurstTime; } int getArrival() { return arrivalTime; } int getCpu() { return cpuBurstTime; } void setWt(int n) { WT = n; } int getWt() { return WT; } void setTat() { TAT = WT+cpuBurstTime; } int getTat() { return TAT; } private: int arrivalTime; int cpuBurstTime; int WT; int TAT; }; int main() { FCFS p[5]; int a; for(int i =0;i<5;i++) { cout << "For p[" << i << "]" << endl; p[i].askAC(); } time[timeLength++] = 0; for(int i = 0; i < 5; i++) { a = time[timeLength-1]-p[i].getArrival(); if(a<0){ time[timeLength] = -a + time[timeLength-1]; timeLength++; pt[ptLength++] = 333; a = 0; } p[i].setWt(a) ; p[i].setTat( ); if(time[timeLength-1] < p[i].getArrival() ){ time[timeLength] = p[i].getArrival() + p[i].getCpu(); timeLength++; pt[ptLength++] = i; } else{ time[timeLength] = time[timeLength-1]+p[i].getCpu(); timeLength++; pt[ptLength++] = i; } } cout << endl; for(int i = 0; i < timeLength; i++) { cout << time[i] <<"\t" ; } cout << endl; for(int i = 0; i < ptLength; i++) { if(pt[i] == 333) cout << "idle\t"; else cout << " p[" << pt[i] << "]\t"; } cout <<endl<< "."; cout << endl<< endl; for(int i =0 ;i<5 ;i++) { cout << "waiting time p[" << i << "] :" << p[i].getWt() << endl; cout << "TAT p[" << i << "] :" << p[i].getTat() << endl; } return 0; }
C and C++ programs, games, softwares. Easy programming guide. Learn to code and enjoy coding in CoderNepal
Home » C++ Program code for FCFS
C++ Program code for FCFS
This is solution for FCFS scheduling algorithm using C++ Object Oriented Approach
Subscribe to:
Posts (Atom)
No comments:
Post a Comment