Module Test 2
Module Test 2
SECTION A (25)
Answer the following questions in the booklet that is provided.
NB The computer must be switched off while you are completing Section A.
NB This is not an open-book test.
1
1.5. In a flowchart, which nodes are diamond-shaped? (1)
A. Start/Stop nodes
B. Action nodes
C. Decision nodes
D. Input/Output nodes
1.6. Which is a type of error where the program compiles and runs without errors, but gives incorrect
output? (1)
A. Compile-time error
B. Syntax error
C. Runtime error
D. Logic error
1.7. Which of the following is true for a method call containing a value parameter? (1)
A. The actual parameter is copied to the formal parameter.
B. The formal and actual parameters share the same memory cell.
C. The formal parameter is copied to the actual parameter.
D. The formal parameter is merely an alias for the actual parameter within the scope of the method.
1.8. If a user is asked to "Enter -1 to stop", a(n) _______ loop is being executed. (1)
A. State-controlled
B. Counter-controlled
C. Infinite
D. Sentinel-controlled
1.9. Which of the following is an example of a pre-test loop? (1)
A. A do...while loop
B. A for loop
C. A nested loop
D. A while loop
1.10. Consider an Array containing ten elements. For which option would i take on the values that
correspond with the indexes of the elements? (1)
A. for (int i = 1; i <= 10; i++)
B. for (int i = 0; i < 10; i++)
C. for (int i = 1; i < 10; i++)
D. for (int i = 0; i <= 10; i++)
2
3. Explain why the following recursive method, intended to calculate the factorial of an integer _iNumber,
will fail, and provide the correct code. (5)
private int Fact(int _iNumber)
{
return _iNumber * Fact(_iNumber - 1);
}
SECTION B (95)
NB You have to submit Section A before you start with this section.
Adhere to all programming and naming conventions as taught and ensure that your code is aligned
properly.
This is not an open-book test.
Marks will be subtracted for missing comment boxes.
Question 1 (28)
Develop a Windows Forms application that draws a shape on a Panel as in the screenshot, and name your
project B1. The user should be able to adjust the appearance of the shape in four ways:
He should be able to select whether a circle or a square is drawn,
He should be able to toggle the colour of the shape between blue and red,
He should be able to select whether the shape is filled or if only the outline is drawn.
He should be able to select the size of the shape. The size represents the diameter of the circle or the
side length of the square.
3
Ensure that your Form is displayed in the centre of the screen and that its borders have a fixed size.
Your Panel should have a Size of 250 x 250 pixels and the shape should always be displayed in the centre of the
Panel.
The minimum and maximum size of the shape should be set to 25 and the Width of your Panel respectively. The
maximum size should not be hard-coded.
The shape should be redrawn every time the user adjusts a setting. Use your Panel's Paint event and its
PaintEventArgs parameter to draw the shape. You can force the Panel to be redrawn by calling its Invalidate()
method.
Question 2 (28)
Create a Console application and name your project B2. The application should function as a basic calculator,
prompting the user for two integers and an operator (addition, subtraction, multiplication and division). If the
user enters incorrect input, the prompt should be repeated, as in the screenshot. Finally, the result of the
calculation should be displayed.
The Main() method is provided below. Copy this method and implement the GetInt(), GetOperator() and
Calculate() methods.
Question 3 (39)
Develop a Console application and name the project B3. The application will display a randomly generated two-
dimensional array of integers along with the totals of its rows and columns.
The user should be prompted for the size of the array (choosing 8 should result in an 8 x 8 array) and values
from 1 to 9 should be allowed. Remember to apply defensive programming for this step.
Each element in the array should be awarded a random integer with a minimum value of 0 and a maximum
value of 9.
4
The array should be printed to the Console, as in the screenshot. Finally, the total of each row, from top to
bottom, and of each column, from left to right, should be displayed.
The Main() method for the application is provided below. Copy this method and implement the GetSize(),
PopulateGrid(), DrawGrid() and PrintTotals() methods. You should also have a GetTotal() method that
calculates the total of a row or column and which is called from within the PrintTotals() method.
Submission Procedure
Create a zipped folder containing all your project folders. Rename this zipped folder to your student number and
submit the folder on Blackboard.