0% found this document useful (0 votes)
110 views

Answer All Questions: Q 1 Find Occurrences

The document provides instructions for answering 4 questions by writing code for specified functions. Each question includes: a description of requirements, testing examples, the function prototype, any helper functions, and the evaluation marks. The questions involve finding string occurrences, calculating array variance, counting free pages in a table, and counting modified pages within a virtual address range.

Uploaded by

Syed Hamza Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Answer All Questions: Q 1 Find Occurrences

The document provides instructions for answering 4 questions by writing code for specified functions. Each question includes: a description of requirements, testing examples, the function prototype, any helper functions, and the evaluation marks. The questions involve finding string occurrences, calculating array variance, counting free pages in a table, and counting modified pages within a virtual address range.

Uploaded by

Syed Hamza Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Answer all Questions

For each of the following questions, you can find:


1. Description of the requirements.
2. Testing example(s).
3. Function prototype that you should write your code inside it. The function
already declared and defined in the given start-up code.
4. Helper function(s), if any, that can be used in the solution.
5. Evaluation marks.

Q1 Find Occurrences
Name:
focc <string> <substring>
Description:
• This command should search for the given substring in string and then
return the number of occurrences of this substring if found or zero if not
found.
• <string> is sample statement
• <substring> contains a character or more that we need to find the number
of its occurrences in <string>
Notes:
• The given string contains multiple words separated by underscore; i.e. the
underscore acts here exactly as if spaces exist between words
• The substring is not necessary be exist in the given string and in this case
return 0
Example:
FOS> focc hello_world ld ➔ 1 (hello_world)
FOS> focc hello_world l ➔ 3 (hello_world)
FOS> focc hello_world_o_w o_w ➔ 2 (hello_world_o_w)
FOS> focc hellohellohellohello lo ➔ 4 (hellohellohellohello)
FOS> focc operating_systems ss ➔ 0 (Not exist)
FOS> focc defenselessness ss ➔ 2 (defenselessness)
FOS> focc ppppppp pp ➔ 3 (ppppppp)

Page 1 of 5
Function:
Your code MUST be written inside the following function:

int FindNoOcc(int num_of_args, char** arguments)


1. arguments[1]: A string
2. arguments[2]: A substring we need to find the number of its
occurrences
Return: Number of occurrences of the given substring in a sample
input string
Evaluation:
a) Correct code logic [2 marks]
b) Successful run [3 marks]

[Q1 Total: 5 marks]

Q2 Calculate Array Variance


Name:
cav <array name>
Description:
• This command should calculate the variance (𝜎 2 ) of the elements in the given
<array name>, according to the following equation:
2
2 (𝐴)
∑𝑁−1
𝑖=0 (𝐴[𝑖] − 𝜇(𝐴))
𝑉𝑎𝑟𝑖𝑎𝑛𝑐𝑒 𝑜𝑓 𝑎𝑟𝑟𝑎𝑦 𝐴 = 𝜎 =
𝑁
Where:
▪ N: array size
▪ 𝜇(𝐴): is the mean (average) of the array elements:
∑𝑁−1
𝑖=0 𝐴[𝑖]
𝑀𝑒𝑎𝑛 𝑜𝑓 𝑎𝑟𝑟𝑎𝑦 𝐴 = 𝜇(𝐴) =
𝑁
• NOTEs:
1. use integer data types (no float, no double)
2. cnia is already implemented inside the given code
Example:
FOS> cnia x 3 10 20 30
FOS> cnia y 4 400 400
FOS> cav x //should print 66
FOS> cav y //should print 40,000

Page 2 of 5
Function:
Your code MUST be written inside the following function:

int CalcArrVar(char** arguments)

arguments[1]: array name

Helper Functions:
• strcmp(const char *p, const char *q): to compare string p to string q

Evaluation:
a) Correct code logic [2 marks]
b) Successful run [3 marks]

[Q2 Total: 5 marks]

Q3 Count free pages inside a table


Name:
cfp <table number>
Description:
This command should count the number of free pages inside the given
<table number>. A free page is the one that's not connected to any frame.
If the table is not exists, you should return -1.
Example:
FOS> cfp 960 (number of free pages inside table # 960 = 0)
FOS> cfp 0 (table is not exists, it should return -1)
Function:
Your code MUST be written inside the following function:
int CountFreePagesInTable(char** arguments)
1. arguments[1]: table number
Return:
2. If table exists, return number of free pages.
3. Else, return -1.

Page 3 of 5
Evaluation:
a) Correct code logic [2 marks]
b) Successful run [3 marks]

[Q3 Total: 5 marks]

Q4 Count modified pages in a virtual range


Name:
cmps <start va in HEX> <end va in HEX>
Description:
This command should count the number of modified pages inside the
given virtual range [<start va>, <end va>).
Example:
FOS> cmps F0000000 F0005000
➔ (no modified pages in this range)
FOS> wum 0xF0000000 A ➔ write 'A' at F0000000 (1st page in the range)
FOS> wum 0xF0000005 B ➔ write 'B' at F0000005 (still in the 1st page)
FOS> wum 0xF0003000 C ➔ write 'C' at F0003000 (4th page in the range)
FOS> wum 0xF0004FFF D ➔ write 'D' at F0004FFF (last byte in the 5th page
in the range)
FOS> cmps F0000000 F0005000
➔ (num of modified pages in this range = 3)
FOS> wum 0xF0005000 X ➔ write 'X' at F0005000 (page outside the range)
FOS> cmps F0000000 F0005000
➔ (num of modified pages in this range = 3)
Function:
Your code MUST be written inside the following function:

int CountModifiedPagesInRange(char** arguments)

1. arguments[1]: start virtual address of the range (in HEX)


2. arguments[2]: end virtual address of the range (in HEX)

Page 4 of 5
Return:
3. number of modified pages in the given range
Helper:
1. You may need to use PERM_MODIFIED
2. There's a constant in the code called "PAGE_SIZE" which equal to
4KB
3. You can use "ROUNDDOWN" and "ROUNDUP" functions, described
below in order to round the virtual addresses on multiple of
PAGE_SIZE (4 KB)

Function Description Defined in…

ROUNDUP Rounds a given “value” to the nearest upper


Inc/types.h
(value, align) value that is divisible by “align”.

ROUNDDOWN Rounds a given “value” to the nearest lower


Inc/types.h
(value, align) value that is divisible by “align”.

Evaluation:
a) Correct code logic [2 marks]
b) Successful run [3 marks]

[Q4 Total: 5 marks]

Wishing to you all the best

Page 5 of 5

You might also like