cout<<"Number of page frames to be allocated to this process: ";cin>>nFrames;pageFrames = new int[nFrames];for(int i =0;i<nFrames;++i){pageFrames[i] = 0; //need to set explicity, otherwise garbage values prevail}

getInput();}

void getInput(){

cout<<"\nEnter the number of page addresses in stream: ";cin>>elementsInStream;cout<<"\nInput Page Address Stream: ";for(int i =0;i<elementsInStream;++i){cin>>pageStream[i];}}

if(pageFrames[j]==0){if(alreadyPresent(pageNumber)){for(int k=0;k<j;++k)//increment the age of previously allocated frames{age[k]++;}updateComputation(0, 0);}else{pageFrames[j] = pageNumber;for(int k=0;k<=j;++k)//increment the age of all allocated frames till now{age[k]++;}updateComputation(j, pageNumber);j++;if(j==nFrames)j=0;//no page will have number 0 so the check if(pageFrames[j]==0) will be false}}else if(alreadyPresent(pageNumber)){for(int i =0;i<nFrames;++i)age[i]++;updateComputation(0, 0);continue;}

void updateComputation(int position, int value){static int number = 0;for(int i = 0;i<nFrames;++i){if(number!=0)computation[number][i] = computation[number-1][i];}if(value!=0)//we want the new column to just be a copy, we don't want any changecomputation[number][position] = value;number++;}