# Assignments and Challenges

• (5 Pages)
• « First
• 3
• 4
• 5

## 70 Replies - 140204 Views - Last Post: 17 October 2016 - 03:18 PM

### #61 ivaylo9603

Reputation: 1
• Posts: 21
• Joined: 05-November 12

## Re: Assignments and Challenges

Posted 06 November 2012 - 11:14 AM

Ah, had great fun with project Euler. 10 solved so far, more to come!

### #62 Fineaffiliate

Reputation: 0
• Posts: 1
• Joined: 25-May 14

## Re: Assignments and Challenges

Posted 25 May 2014 - 11:27 PM

I worked all night and all i could find is being left with two questions to answer. Functions getting on my nerves..
The last digit in a n interger value can be extracted from the interger value as the remainder when the interger value is divided by 10. Write a function that uses this method to return the last digit of an interger value.

### #63 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12641
• Posts: 45,813
• Joined: 27-December 08

## Re: Assignments and Challenges

Posted 26 May 2014 - 11:18 AM

Just a heads up Fineaffiliate- this isn't the place to ask for help on your assignment, but rather to share fun challenges.

### #64 lexielynne95

Reputation: 0
• Posts: 17
• Joined: 06-October 14

## Re: Assignments and Challenges

Posted 06 October 2014 - 02:14 PM

Wishing code academy would have a C# course...

Khan Academy allows you to write code and it immediately gives you tips on things it sees wrong

### #65 lili214

Reputation: 0
• Posts: 3
• Joined: 10-March 15

## Re: Assignments and Challenges

Posted 10 March 2015 - 05:00 PM

here is one assignment

nt you will write your own simulation of a memory management system for a
process. We are only looking at one process and NOT worrying about multiple processes! There
are several key parts described below that you must consider.
Virtual Memory Map:
You will need to provide a translation map to convert addresses from virtual to physical.
• Pages are 2KB in size.
• Virtual addresses are composed of PDir (11 bits), PTable (10 bits) and Offset (11 bits).
• Addresses that are below 1GB are in the kernel section (no swapping or virtual memory
area allowed). Addresses above 1GB are in the user section where swapping and virtual
memory areas exist.
• For each page you need to track whether it is a VM Area, swapped, clean/dirty, and
accessed. Since we know pages are 2K aligned you can (MUST) use the trailing bits in the
page table reference to store this information.
Virtual Memory Area:
Virtual memory areas are used to map files (executables, libraries, shared files) to the virtual
memory space of a process.
• Virtual memory areas are given a file to map to the region.
• A starting address is provided where the file is mapped.
• The entire file is mapped contiguously at this location.
• You can assume the file will always fit – no error checking needed.
• VM areas can be read-only OR copy-on-write.
o If Read-only then the page is not stored when you swap out.
o If copy-on-write then the page is stored when you swap out IF the page was
updated.
• Files are loaded only when accessed AND only the portion used is loaded.
• You can use the standard fopen(), fread(), fseek() and fclose() to manage
the file to get the data.
Swap Space:
For swap space you can use a swap file. You can use the standard fopen(), fread(),
fwrite(), fseek() and fclose() to manage the file to read/write the data. I will leave the
design decision to you on how you want to locate pages in this file. However:
• The file should only grow as you need it to (swap file starts at size 0).
• You should only keep one copy of a page in the swap file – the most recent version of the
page that is swapped out.• Remember: You can use part of the virtual address of the page as a key to find the page in
the swap file.
• Lastly … kernel pages are never swapped out!
Paging:
The system is provided with a number of frames that are provided to the user process for use.
When a frame is required by the kernel, it gets a frame, but it is not counted against the number of
frames allocated to the user process (kernel frames are taken from a different unlimited pool of
memory frames).
Searching for a page to replace begins where the last search for a page ended (Round Robin style).
The page replacement algorithm (pseudo code) is as follows:
i = #pages
While (page not allocated AND i > 0)
If (page is free)
If (page is accessed)
Mark page as unaccessed
Decrement i
i = #pages
While (page not allocated AND i > 0)
If (page is clean)
Decrement i
Note that when you allocate a page you must swap out the page (if necessary) and update your
Virtual Memory Map and Swap Space tables accordingly.
Program Interface:
Input to the program is provided through command line arguments. You can assume that all
arguments are valid and ample space will be provided to fit a file that is mapped to memory. A
sample invocation is the following:
swap_sim –l my_exe 1073741824 –l my_kernel 0 –s share_space 1500000000 –f 1024 –r
mem_trace
options:
-l gives the name of a read-only file followed by the address where the file is mapped. This option
can be repeated as many times for each file mapped.
-s gives the name of a copy-on-write file followed by the address where the file is mapped. This
option can be repeated as many times for each file mapped.
-f specifies the number of frames allocated to the user process.-r specifies the memory trace file that is to be processed. This file specifies the virtual addresses
for the sequence of read and write actions that take place during the execution. Each line of the file
specifies either a read or a write.
For each read and write action specified in the trace file, the simulation will print the contents (32-
Final statistic output from the program will be the following:
• A count of the number of page faults
• A count of the number of pages swapped out
• A count of the number of pages swapped in
• The number of pages in the swap file you created
• The number of virtual memory pages loaded

### #66 deep.row4

Reputation: 0
• Posts: 18
• Joined: 26-July 13

## Re: Assignments and Challenges

Posted 02 October 2015 - 01:31 AM

```ifstream& operator>> (ifstream& in,  Map& map)
{

in>>map.size;
map.items = new MapItem[map.size * map.size];

for (int i = 0; i < map.size * map.size; i++)
{
in>>map.items[i];

}

return in;
}

```

in main.cpp

```ifstream inFile;
inFile.open("newFile.txt");

Map newMap;
inFIle>>newMap;
inFIle.close();

```

and map.h is

```class Map
{

private:

int size;
MapItem * items;

public:

Map();
explicit Map(int);
~Map();
int getSize();
void build(int, int, char);
MapItem getMapItem(int,int);
friend  ifstream& operator>> (ifstream&,  Map&);
friend   ofstream& operator<< (ofstream&, const Map&);
friend  ostream&  operator<< (ostream&, const Map&);

};

```

overloaded operator is not working! what is going wrong. IS it something wrong with the file. In the file, it looks like this
\ E | E /
E \ | / E
- - | - -
E / | \ E
/ E | E \

### #67 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12641
• Posts: 45,813
• Joined: 27-December 08

## Re: Assignments and Challenges

Posted 06 October 2015 - 02:42 PM

Just a reminder that this is not the place to ask for help. Please use the main programming help forums for help with your assignment. This thread is to share fun challenges/assignments for others to attempt.

### #68 deep.row4

Reputation: 0
• Posts: 18
• Joined: 26-July 13

## Re: Assignments and Challenges

Posted 06 October 2015 - 02:43 PM

macosxnerd101, on 06 October 2015 - 02:42 PM, said:

Just a reminder that this is not the place to ask for help. Please use the main programming help forums for help with your assignment. This thread is to share fun challenges/assignments for others to attempt.

Sure, will do that in future.

### #69 King Hebes

Reputation: 0
• Posts: 37
• Joined: 29-January 16

## Re: Assignments and Challenges

Posted 29 January 2016 - 03:19 AM

I am reading a Java book and at the end of each chapter it has questions and exercises and programming tasks. I started a thread ->here<-. I will update it as I progress if anybody finds it useful. I'm also looking for somebody/people to confirm/check the answers I post as I am unsure if my answers are correct as I am teaching myself. Cheers.

### #70 dani.raja1248

Reputation: -1
• Posts: 1
• Joined: 17-October 16

## Re: Assignments and Challenges

Posted 17 October 2016 - 03:17 PM

mod: removed giant quote.

HERE IS THE SOLUTION

This post has been edited by modi123_1: 17 October 2016 - 03:18 PM

### #71 modi123_1

• Suitor #2

Reputation: 15222
• Posts: 60,932
• Joined: 12-June 08

## Re: Assignments and Challenges

Posted 17 October 2016 - 03:18 PM

.. to what?