Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8809735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:57:03+00:00 2026-06-14T02:57:03+00:00

The problems I am having are that it always misses, and instead of replacing

  • 0

The problems I am having are that it always misses, and instead of replacing one element it fills up every frame with the integer it pulls in. I’m having a hard time figuring out where to go from here. The “requests.txt” is a file of random integers and a sample output should look like :

2: page hit, page 2 is in frame 8    
45: page hit, page 45 is in frame 2

But mine looks like:

99: page miss, page 99replaces page 0in frame 0
99: page miss, page 99replaces page 0in frame 1
99: page miss, page 99replaces page 0in frame 2
99: page miss, page 99replaces page 0in frame 3
99: page miss, page 99replaces page 0in frame 4
99: page miss, page 99replaces page 0in frame 5
99: page miss, page 99replaces page 0in frame 6
99: page miss, page 99replaces page 0in frame 7
99: page miss, page 99replaces page 0in frame 8
99: page miss, page 99replaces page 0in frame -1
4: page miss, page 4replaces page 0in frame 0
4: page miss, page 4replaces page 0in frame 1
4: page miss, page 4replaces page 0in frame 2
4: page miss, page 4replaces page 0in frame 3
4: page miss, page 4replaces page 0in frame 4
4: page miss, page 4replaces page 0in frame 5
4: page miss, page 4replaces page 0in frame 6
4: page miss, page 4replaces page 0in frame 7
4: page miss, page 4replaces page 0in frame 8

Code:

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void search(int input, int  P_list[], bool  R_bit[], int & victim);
int main()
{
//Basic initilization
int victim = 0;
bool R_bit [10];
int P_list [10];

 for(int i = 0; i <10;  i++)
 {
    //Sets one array to all false
    R_bit [i] = false;
    //Sets every integer in the other array to -1
    P_list [i] = -1;
 }

 int input;


 ifstream inFile;

 //Opens up the text file "requests.txt"
 inFile.open("requests.txt");
 //If It is not able to open the file
 if (!inFile)
 {
     //Display error message
    cout << "Unable to open specified file";
    //Exit with an error(1)
      exit(1);
 }

 while(inFile >> input )
 {
    if(input < 0)
    {
        cout << "invalid input ";
        exit(1);
    }
    else if(input > 99) 
    {
        cout << "invalid input ";
        exit(1);
    }
  //search array 2, replace and end
    search(input, P_list, R_bit, victim);



}       return 0;
}



void search(int input, int  P_list[], bool  R_bit[], int &victim)
{

//local var only unless you pass them  input is the only thing you passed
for(int i = 0; i <10; i++)
{

    if(input == P_list [i])
    {//Output if it is a hit

        cout << input << ": page hit, " << input << "is in frame " << i << endl;
        R_bit [i] = 1;

        return;
    }
    int oldpage;
    //Sets up a bool to end the while loop
    bool flag = true;
    //While true
    while(flag){
    //looks for the first 0 in the R-Bit array
    if (R_bit [victim] == 0)
    {
        //If it is zero
        flag = false;
        //Recording previous page for output 
        oldpage = R_bit [victim];
        //Replaces with input 
        R_bit [victim] = input;

        victim = victim + 1;


    }
    else
    {   //Makes the R-Bit zero
        R_bit [victim] = 0;
        //Increments, makes it zero
        ++victim;

    }
        //If the victim is going to go out of bounds
    if(victim > 9)
    {
        //Set to zero 
        victim = 0;
    }
    }

    //output if it misses and the frame it is in
    cout << input << ": page miss, page " << input << " replaces page " << oldpage << " in frame " << (victim - 1) << endl;

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:57:04+00:00Added an answer on June 14, 2026 at 2:57 am

    You are mixing up R_bit (recent flag) with P_list (saved data)

        //Recording previous page for output 
        oldpage = R_bit [victim];
        //Replaces with input 
        R_bit [victim] = input;
    

    should be

        //Recording previous page for output 
        oldpage = P_list [victim];
        //Replaces with input 
        P_list [victim] = input;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was having problems adding objects to one of my core data objects that
I am having problems having my Java programs see classes that are packaged in
I'm having problems including local javascript files into my html that is on the
I am having problems with working with a third party XML string that contains
I'm having problems in IE6 and 7 with a div that doesn't complete the
I'm having problems working through how I would build times that increment by a
I have started having problems with my VPS in the way that it would
im having problems starting a codeigniter project, the problem is that when i do
Hi all I am having some problems that I think can be attributed to
I am having problems with launching Nokia's own video player from my application that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.