2017 U2 Q5

Part a)

Client server

Part b)

  1. The user clicks on a link to a webpage from a previous webpage.
  2. The browser resolves the ip address from the server name and sets up a tcp connection to the server (usually on port 80 or 8080)
  3. The browser sends a http request to the server containing the requested resource and information about itself, e.g browser type, supported language etc
  4. The server generates a response which contains header information as well as HTML code for the browser to render.
  5. The browser interprets the code and displays the page to the user.

Part c)

The url https://www.buythings.com  would be preferred since this http protocol includes SSL (Secure sockets layer) or TLS (Transport layer security) which encrypts all HTTP information such that only the sender and the receiver can decipher the information. This is more secure, especially in the case where the http information can be intercepted by malicious entities on the network, they won’t be able to read the sensitive payment information that can be used defraud the online shopper.

Part d)

A process is a running program.

The PCB stores metadata necessary for  managing the process, e.g. process id, process state, memory allocation addresses, scheduling info (priority, time slice), pointers to it’s resources (files, other processes).

Part e)

  1. New
  2. Running
  3. Ready
  4. Waiting
  • Terminated

Part f)

Paging is were each process in an OS is allocated memory in units called pages for easier coordination and management by the operating system. The pages can be stored physically in memory , or stored on the hard disk (in the case that the process is not running at that time). If a process is stored on the disk and needs to be run, a page fault is generated so that the process is swapped back into the physical memory for processing.

Part g)

Thrashing occurs when memory resources become limited by the amount of running processes. The need for physical memory can be exceeded, thus multiple processes that are in waiting state are stored as pages on disk. For continued running of the system, processes are constantly swapped in and out of physical memory, an execution which spends a lot of time on the cpu when compared to running the processes themselves.

Part h)

  1. Because of the frequent process swapping by page faults, the system becomes inefficient and can run slowly.  (The solution is to inefficiency increase the size of physical memory by upgrading the ram size, or configure/manage the system to run less processes.)

  2. The system can become overwhelmed to the point of “crashing”, i.e stop working or responding altogether.

Part i)

Too little physical memory is available for a system that needs to run a lot of processes.


© 2023  Vedesh Kungebeharry. All rights reserved. 

2019 U1 Q5

Part A

i) Debugging is the process of detecting removing and/or correcting errors in code.

ii) Coded is indented every time a control structure is entered. i.e.  thus isolating blocks of logic which is easier to read and understand.

Comments are used to explain what the code is intended to accomplish, thus making it easier understand and modify

Descriptive variable names explains the purpose of each variable making code easier to understand and maintain.

Part B

//this is a complete program, but starting from main() would be sufficient.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
    //Start:declare and initialize all variables
    double redTime     =   -999.99;
    double greenTime   =   -999.99;
    double orangeTime  =   -999.99;
    bool valid=false;//used to signify that no
                    //valid inpuha been enterd
                    //at the start of execution

    //End:declare and initialize all variables

    //while input is not valid
    while(valid==false)
    {
        //ASSUMPTION: the usere only enters positive values
        //get input from user
        puts("Please enter a value for Redtime");
        scanf("%lf",&redTime);
        puts("Please enter a value for greenTime");
        scanf("%lf",&greenTime);
        puts("Please enter a value for orangeTime");
        scanf("%lf",&orangeTime);
        //evaluate each condition, and check that they are all true.
        valid = (redTime>=greenTime+orangeTime)&&
                (orangeTime>=5)&&
                (greenTime>4*orangeTime);

        //if input is invalid
        if(valid==false)
        {
            //prompt user
            puts("Invalid timings: Please re-enter\n");
        }
        //continue looping if valid == false
    }
    //if we have exited the loop, then timings are valid
    puts("Timings are valid\n");
    return 0;
}


Part C(i)

    /*Code presented in question
    int i j;
    for (i=1;<= 3;i++)
        for (j=1;j<i;j=j+1)
            printf("%d" j);
        printf(\n);
    */

//Corrected code
    int i, j;  //comma was missing between i and j
    for (i=1;i<= 3;i++)//no left operand for comparison, "i" dentifier missing
        for (j=1;j<i;j=j+1)
            printf("%d", j);//comma missing between format string and parameter
        printf("\n");  //String was not in quotes

/*Note that this code seems to contain a logical error , 
as implied by the indentation of the code.  
It seems that the 2nd for loop and the printf statement are 
2 lines of code that are meant to be executed within the first for loop, 
and should be enclosed in curly braces. 
This question asks us to correct the syntax errors only. 
One may feel the need to fix the logical error also,  
but it is not required.  */


Part C(ii)

Answer:

112

Note, if you assumed a logical error and fixed it, the output would be

1

12

Based on the code:

#include <stdio.h>

int main() {
        //Corrected code
    int i, j;  //comma was missing between i and j
    for (i=1;i<= 3;i++)//no left operand for comparison, "i" dentifier missing
    {    
        for (j=1;j<i;j=j+1)
            printf("%d", j);//comma missing between format string and parameter
        printf("\n");  //String was not in quotes
    }
    
    return 0;
}


This fix however, would render your response incorrect.

© 2021  Vedesh Kungebeharry. All rights reserved. 

CS U1 2009 U1 Q4

 

Part A

Identifying and evaluating possible solutions involves generating different approaches to solving the problem.  Solutions will include different methods of solving the problem, e.g contrasting data structures :  one solution may use arrays only, another will use a mixture of arrays and structs.  Each solution is compared against each other to determine individual advantages and disadvantages when compared to each other in terms of efficiency and how well it solves the problem.[1]


[1] https://islandclass.wordpress.com/2020/02/17/stages-in-problem-solving/

Part B

Strategy – keep track of all variables in a trace table, draw output as you go along.

Table – write all variables in the order of its logical use within main control structures, use 1 variable per column:

SIZEj
108
 7
 6
 5
  
  
  

Answer:

----------* 
---------**
--------*-*
-------*--*
------*---*
-----*----*
----*-----*
---*------*
--*-------*
-*--------*
***********

Part C

START
Sum<--0
For i<--14 to 126 DO
	If i%7 ==  0  Then
		Sum<--sum +i
	Endif
Endfor
PRINT Sum
END

Coded solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   
    int sum = 0;
    for (int i= 14; i<=126; i++)
        if (i%7==0)
            sum+=i;
    printf("The sum is : %d", sum);

    return 0;
}

© 2021  Vedesh Kungebeharry. All rights reserved. 

2009 U1 Q3

Part a

An algorithm is a well-defined, precise, finite set  of steps for solving a problem.[1]

Part b

Sequence (procedure), Selection (if-then-else) , Iteration (Looping)

Part c

Note:  j goes from 2,4,6,… 96,98 during looping and is output to the screen. Odd numbers are not output. See the attached flowgorithm file here:

https://drive.google.com/file/d/1H21gL4E0YGtgzXgwUD-1cFuEHsmC8IY0/view?usp=sharing

Image:

https://drive.google.com/file/d/1smeXp9ArthIPi7ZY1NfnJqJrYKIJx4rK/view?usp=sharing


Part C(i)

J = 100, C=50

Part c(ii)

2. J=1
3. C=1

Note, for this part we arrive at a solution that solves the problem exactly as stated (only numbers from odd numbers from 1 to 99 and the count.  See flowgorithm file for the corrected algorithm:

Flowgorithm file

Image

Displaying 2009Q3Cii.png




Part c(iii)

c=50

Part  d

Use “Start” instead of main.  See Files Below:

Flowgorithm

Image





[1] VK. Blogged at https://islandclass.wordpress.com/2020/02/10/what-is-an-algorithm-definition/

© 2021  Vedesh Kungebeharry. All rights reserved. 

2009 U1 Q2 Part C

Part i

The instruction Set is the set of machine code instructions that a CPU is designed to understand/process

The Instruction format is  the layout convention chosen to represent instruction types and their corresponding operands for a given instruction set.

Part ii

Any three: ADD, LOAD, STORE, JUMP, JUMPIF, IN, COMPARE

Part iii

OPCODEOperand 1Operand 2

We could reserve 4 bits for the opcode which will facilitate a total of 24  or 16 instructions.

The remaining 12 bits can be  split, using 6 bits for operand 1 an 6 bits for operand 2 .

Part iv

Recall: Direct addressing means that the address of the operand is stored in the instruction

Fetch –

  • Copy instruction from memory , which is specified by the PC,  to the  CIR (Current Instruction Register).
  • increment the PC (Program Counter)

Decode –

  • Determine operands and operation.
    •  Since Direct addressing is used, the MAR will store the address of the operand which was decoded and copied from the CIR.
    • The Data from Memory stored at the location specified by the MAR is copied to the MDR (Memory Data Register)

Execute –

  • Control is passed to the appropriate logic circuit based on the operation opcode. and the results of the operation on the data stored in the MDR, is stored in the AC (accumulator)

© 2021  Vedesh Kungebeharry. All rights reserved.