CSC 206_104_tutorial Questions Solution
CSC 206_104_tutorial Questions Solution
a.
i. The WHILE loop: The second type of iteration to be considered is the while iteration.
This type of conditional loop tests for terminating condition at the beginning of the loop.
In this case no action is performed at all if the first test causes the terminating condition
to evaluate as false.
ii. The FOR Loop : The third type of iteration, that can be used when the number of
iterations is known in advance, is a for loop. This, in its simplest form, uses an
initialisation of the variable as a starting point, a stop condition depending on the value
of the variable. The variable is incremented on each iteration until it reaches the
required value.
59 / 2 = 29, remainder 1
29 / 2 = 14, remainder 1
14 / 2 = 7, remainder 0
7 / 2 = 3, remainder 1
3 / 2 = 1, remainder 1
1 / 2 = 0, remainder 1
Now read the binary number from the bottom to the top: 111011011.
Hence 47510 = 1110110112
ii.
d.
Low-level languages are designed to operate and handle the entire hardware and instructions set
architecture of a computer directly. A program written in a low level language can be made to run very
quickly, and with a very small memory requirement when compared with the equivalent program in a
high-level language. However, they are considered difficult to use, due to the numerous technical
details such as the computer instruction set architecture which must be remembered. Examples of low
level languages are: machine language and assemply language
High Level languages have replaced machine and assembly language in all areas of programming.
Programming languages were designed to be high level if it is independent of the underlying machine.
High-level languages (also known as problem-oriented languages) enable a programmer to write
programs that are more or less independent of a particular type of computer. Such languages are
considered high-level because they are closer to human languages and farther from machine languages.
High level languages are portable (machine independent) as it can be run on different machines with
little or no change. High-level languages provide a richer set of instructions and support, making the
programmer’s life even easier. High level languages use translator programs such as compiler and
interpreter to convert it into a machine language program. Examples are pascal, C, C++, python etc.
(3 marks for explanation, 1 mark for each example= 9 marks)
e.
(one mark should be deducted for each missing arrow or arrow in wrong direction; total mark= 7 ½
marks)
f. NOT, OR, AND, XOR, NAND, NOR (1 mark each for any five)
g.
5 marks
h.
i. Reliability: The program can be depended upon always to do what is supposed to do.
ii. Maintainability: The program will be easy to change or modify when the need arises
iii. Readability: The program will be easy for a programmer to read and understand
iv. Performance: The program causes the tasks to be done quickly and efficiently
v. Storage saving: The program is not allowed to be unnecessarily long to achieve memory
efficiency (2 marks each)
i. PDLC is a systematic wat of developing quality software. It provides an organized plan for
breaking down the task of program development into manageable chunks. Each of which must
be successfully completed before moving on to the next phase. (1 ½ marks)
j.
i. Problem definition
ii. Problem analysis
iii. Algorithm development
iv. Coding and documentation
v. Testing and debugging
vi. Maintenance (1 mark each= 6 marks)
iii. Coding and Documentation: This phase uses a programming language to write or
implement the actual programming instructions for the steps defined in the previous
phase. In this phase, we construct the actual program. That means we write the program
to solve the given problem using programming languages like C, C++, Java, etc., Coding
the program means translating an algorithm into specific programming language. The
technique of programming using only well-defined control structures is known as
Structured programming. Programmer must follow the language rules, violation of any
rule causes error. These errors must be eliminated before going to the next step.
iv. Testing and Debugging: After removal of syntax errors, the program will execute.
However, the output of the program may not be correct. This is because of logical error in
the program. A logical error is a mistake that the programmer made while designing the
solution to a problem. So the programmer must find and correct logical errors by carefully
examining the program output using Test data. Syntax error and Logical error are
collectively known as Bugs. The process of identifying errors and eliminating them is
known as Debugging. During this phase, there is need to check whether the code written
in the previous step is solving the specified problem or not. That means we test the
program whether it is solving the problem for various input data values or not. We also test
whether it is providing the desired output or not. (3 marks each= 12 marks)
n.
i. The sequence structure: The first type of control structures is called the sequence
structure. This structure is the most elementary structure. The sequence structure is a
case where the steps in an algorithm are constructed in such a way that, no condition
step is required. The sequence structure is the logical equivalent of a straight line.
ii. The decision structure or mostly commonly known as a selection structure, is case
where in the algorithm, one has to make a choice of two alternatives by making decision
depending on a given condition. Selection structures are also called CASE selection
structures when there are two or more alternatives to choose from.
iii. Repetition structure causes the certain steps to be repeated.
Any program instruction that repeats
some statement or sequence of statements a number of times is called an iteration or a
loop.
o.
(8 ½ marks)
p.
i. The WHILE loop: The second type of iteration to be considered is the while iteration.
This type of conditional loop tests for terminating condition at the beginning of the loop.
In this case no action is performed at all if the first test causes the terminating condition
to evaluate as false.
The syntax is WHILE (a condition is true)
A statement or block of statements
ENDWHILE
ii. The FOR Loop : The third type of iteration, that can be used when the number of
iterations is known in advance, is a for loop. This, in its simplest form, uses an
initialisation of the variable as a starting point, a stop condition depending on the value
of the variable. The variable is incremented on each iteration until it reaches the
required value.
59 / 2 = 29, remainder 1
29 / 2 = 14, remainder 1
14 / 2 = 7, remainder 0
7 / 2 = 3, remainder 1
3 / 2 = 1, remainder 1
1 / 2 = 0, remainder 1
Now read the binary number from the bottom to the top: 111011011.
Hence 47510 = 1110110112
r.
Low-level languages are designed to operate and handle the entire hardware and instructions set
architecture of a computer directly. A program written in a low level language can be made to run very
quickly, and with a very small memory requirement when compared with the equivalent program in a
high-level language. However, they are considered difficult to use, due to the numerous technical
details such as the computer instruction set architecture which must be remembered. Examples of low
level languages are: machine language and assemply language
High Level languages have replaced machine and assembly language in all areas of programming.
Programming languages were designed to be high level if it is independent of the underlying machine.
High-level languages (also known as problem-oriented languages) enable a programmer to write
programs that are more or less independent of a particular type of computer. Such languages are
considered high-level because they are closer to human languages and farther from machine languages.
High level languages are portable (machine independent) as it can be run on different machines with
little or no change. High-level languages provide a richer set of instructions and support, making the
programmer’s life even easier. High level languages use translator programs such as compiler and
interpreter to convert it into a machine language program. Examples are pascal, C, C++, python etc.
(3 marks for explanation, 1 mark for each example= 9 marks)
s.
(one mark should be deducted for each missing arrow or arrow in wrong direction; total mark= 7 ½
marks)
t. NOT, OR, AND, XOR, NAND, NOR (1 mark each for any five)
u.
5 marks