Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

4QQMN506 Mock Exam solutions

Answer ALL questions

PART A Theory

Question 1 [25 marks]

With the aid of a flow-chart describe how Python works in detail?

 

 

1.   The interpreter reads the Python source code and verifies that it is well formed. It rejects any lines of code that do not adhere to the strict syntax of the Python          language. If it encounters any syntax errors, it halts the translation of the program and displays an error message.

2.    Once any error is corrected and the code is well formed, the interpreter translates    the Python code to an equivalent form in a low-level language called Byte Code. The interpreter completely translates Python code to byte code when it runs a python     program.

3.   This byte code is sent to another software component, called the Python Virtual      Machine (PVM), where it is executed. If there are any other errors the execution is halted with an error message. Otherwise the program runs to completion with any user inputs and program outputs.


Question 2 [25 marks]

a)           What is the syntax of a simple class definition?   [10 marks]

b)          What are the parenthesis brackets used for lists, tuples, dictionaries and sets built in data types? Provide detailed explanations for each of these built in data types.  [10    marks]

c)           Which data type would most appropriately be used to represent the following data values? [5 marks]

i.       The number of months in a year (12)

ii.       The area of a circle (eg 32.45)

iii.       The current minimum wage expressed as 10.50

iv.       The approximate age of the universe (12,000,000,000)

v.       Your name

a)

Syntax

class <class name>(<parent class name>):

<method definition-1>

<method definition-n>

The class definition syntax has two parts: a class header and a set of method definitions that      follow the class header. The class header consists of the class name and the parent class name.

The class name is a Python identifier. Although built-in type names are not capitalized,    Python programmers typically capitalize their own class names to distinguish them from variable names.

All Python classes, including the built-in ones, are organized in a tree-like class hierarchy.

 

b)


c)

i.

ii.

iii.

iv.

v.


 

int

float

float

int

str


 

Question 3 [25 marks]

a)    Explain how to display a directory of all of the functions in a given module. [5 marks]

b)   Explain how to display help information on a particular function in a given module. [5 marks]

c)    As a professional you will have to deal with clients, who would expect you to solve their problems with the aid of programming. With the aid of flowcharts clearly describe the    “Waterfall” model of software development. [15 marks]

 

a)   The dir function returns a list of the named resources (functions and variables) in its argument, which is a module.

b)   The help function displays all of the documentation for its argument, which can be a module

or other resource.

c)

The waterfall model consists of several phases:


1.    Customer request—In this phase, the programmers receive a broad statement of a problem that is potentially amenable to a computerized solution. This step is also called the user         requirements phase.

2.   Analysis—The programmers determine what the program will do. This is sometimes viewed as a process of clarifying the specifications for the problem.

3.    Design—The programmers determine how the program will do its task.

4.    Implementation—The programmers write the program. This step is also called the coding phase.

5.    Integration—Large programs have many parts. In the integration phase, these parts are brought together into a smoothly functioning whole, usually not an easy task.

6.    Maintenance—Programs usually have a long life; a life span of 5 to 15 years is common for software. During this time, requirements change, errors are detected, and minor or major   modifications are made.

 

 

PART B Practical

Question 4 [25 marks]

The greatest common divisor (GCD) of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid’s algorithm can be used to find the greatest common      divisor (GCD) of two positive integers. You can use this algorithm in the following manner:

1.    Compute the remainder of dividing the larger number by the smaller number.

2.    Replace the larger number with the smaller number and the smaller number with the remainder.

3.    Repeat this process until the smaller number is zero.

 

The larger number at this point is the GCD of A and B. Write a program that lets the user enter two  integers and then prints each step in the process of using the Euclidean algorithm to find their GCD.

An example of the program input and output is shown below: