Transcribed TextTranscribed Text

Q6 - Programming question (30 marks) Write a program (pagesim.c or pagesim.cpp) that simulates three page replacement algorithms: Optimal, LRU and Clock. Your program will read in a reference string from standard input, and then run a simulation using all three algorithms. The number of available frames will be specified on the command line, and your simulation will start with all frames empty. For the clock algorithm you should use the single refererence bit implementation. At the end of the simulation your program will output the contents of the frames and the number of page faults for each replacement algorithm. If a frame has never been used, print out ‘-1’ as it’s content. You must format your output to match the sample output below: Example input file test1.txt: Sample output: 1 2 3 4 1 2 5 1 2 3 4 5 $ ./pagesim 4 < test1.txt Optimal: -frames: 4 2 3 5 -page faults: 6 LRU: -frames: 5 2 4 3 -page faults: 8 Clock: -frames: 4 5 2 3 -page faults: 10 You can make the following assumptions: -Number of available frames will be between 1 and 20 (inclusive). -Number of entries in the reference string will be at most 5000. -Frame numbers will be non-negative integers smaller than 100. Q7 - Programming question (30 marks) For this question you will implement a program (fat.c or fat.cpp) that will check the consistency of a file allocattion table with respect to the entries of a directory. Your program will read input from standard input, and will output results to standard output. Input The input will contain a simplistic representation of a filesystem. It will contain the following, all separated by white space: •block size – an integer in the range [1, 1024] •number of entries in the directory – an integer in the range [0, 50] •number of entries in FAT – an integer in the range [1, 200000] •list of directory entries, one entry per line, each line containg: ofilename – a string of up to 128 characters, any chars allowed except white space opointer to the first block – an integer in range [-1, 200000], where ‘-1’ denotes aNULL pointer, ‘0’ denotes first block, etc. ofile size in bytes – an integer in range [0, 230] •FAT entries – a list of integers separated by white space oeach entry represents a pointer to the next entry in the FAT oeach entry is an integer in a range [-1, 200000] o-1 denotes a NULL pointer (end of chain) othe entries in FAT are numbered starting from 0

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <string>
#include <vector>
#include <limits.h> // for INT_MAX
#include <iostream>

typedef std::string SS;
typedef std::vector<SS> VS;

#define MAX_FRAMES 20
#define MAX_ENTRIES 5000

typedef struct{
    unsigned int number;
    unsigned int future;
    unsigned int hits;
    unsigned int clock;
} frame;

bool search(int key, std::vector<int>& fr)
    for (int i = 0; i < fr.size(); i++)
       if (fr[i] == key)
            return true;
    return false;

int predict(int pg[], std::vector<int>& fr, int pn, int index)

    int res = -1, farthest = index;
    for (int i = 0; i < fr.size(); i++) {
       int j;
       for (j = index; j < pn; j++) {
            if (fr[i] == pg[j]) {
                if (j > farthest) {
                   farthest = j;
                   res = i;
       if (j == pn)
            return i;
    return (res == -1) ? 0 : res;

void optimal(int pages[], int page_no, int frame_no)

    std::vector<int> fr;
    int hit = 0;
    for (int i = 0; i < page_no; i++) {

       // Page found in a frame : HIT
       if (search(pages[i], fr)) {

By purchasing this solution you'll be able to access the following files:
pagesim.cpp and fat.cpp.

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Operating Systems Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats