Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys, i\'m having trouble understanding the program im supposed to write in

ID: 3550556 • Letter: H

Question

Hey guys, i'm having trouble understanding the program im supposed to write in C++. I need to read a file of integers that represent virtual memory and then I translate those addresses to physical memory addresses using a page table and translation lookaside buffer. If someone could help me write this code I would lose so much stress!


Im reading in a file containing intergers as follows:

63987

32256

41413

48870

40282

14498

62738

64859

25437

9606

14533

25499

25920

1981

48202

15518

34908

35365

30861

30258

Explanation / Answer

Use the getline() function in C++ to get a string value from your text file. Each time you use the getline() function it automatically reads the next line, so you don't need to specify line numbers.


Then simply plug that string into whichever function you need it for.


string address = " 63987"


You can also convert strings to other variable types if needed.


Use


cout << your variable here << endl; to see if the variable gives you the correct value.


Also if you need the format


"Virtual address: 63987 Physical address: 243 Value: 124"


simply ---


cout << "Virtual address:" + x + "Physical address:" + y + "Value:"+ z<< endl;


Where x,y,and z are the numbers you plug in. I would recomend using string variable numbers as it saves time instead of converting lines from a file to ints or doubles.


Hope this helps, good luck.