Professional Documents
Culture Documents
By Dr Derrick Ntalasha
Section A
1.What are case tools? [2 marks]
Answer
The spiral model is an evolutionary software process model that couples the iterative
nature of prototyping with the controlled and systematic aspects of the waterfall lifecycle
model.
It also has an emphasis on the use of risk management techniques.
3.Mention some of the process models appropriate for the software to be engineered? [3
marks]
Answer
4. What is Software Development Life Cycle? (SDLC) and draw a diagram for pure
waterfall life cycle. [6 marks]
Answer
System Development Life Cycle (SDLC) is the overall process of developing information
systems through a multi-step process from investigation of initial requirements through
analysis, design, implementation and maintenance.
Diagram
A generalization is an object class, which is a superset of another object class (or classes).
Generalization models the “is a” relationship set since members of the specialization class (or
classes) are always members of the generalization class. This means that members of the
specialization class have all of the same properties of the generalization class including
relationships with other objects as well as behaviour.
A generalization is used when two classes are similar, but have some differences. Look at the
generalization below
SECTION B
1. What are the features that make Pascal a good language in modern programming? [5
marks]
Answer
Pascal is a very structured language and uses the control structures like if-else, repeat-until
statements, etc.
- It is having different data structures that are included with the records, arrays, files, pointers,
etc.
- Pascal provides simplicity and provides a modular approach for machine implementation. It
allows the features to be related to the compiler.
- Pascal uses minimum ambiguity to represent the data and its structure it is processed with some
exceptions and provides smaller elements with their definitions.
- Pascal provides the exact sizes used by the operands and operators to perform on them. It
provides a way to process and use the efficient code.
Pascal can’t handle the string of characters and it is one of the disadvantages of the language.
- String of characters uses lots of data elements and characters and there need to be character
displacement using the string functions.
- The procedure is as follows:
- Declaration of the string take place and it is declared as the string of fixed length array like:
- The length of all the strings should be same and the length of the handler routines as well.
- The size of the array can be made according to the requirement but, there is no assigning of the
string constant to strings like:
const
strlen = 250; { our "big" string }
cstlen = 12; { our constant strings }
type
string = packed array [1..strlen] of char;
cstring = packed array [1..cstlen] of char;
var s: string;
procedure inistr(var s: string; c: cstring);
begin
for i := 1 to strlen do s[i] := ' '; { clear result }
for i := 1 to cstlen do s[i] := c[i] { place string }
end;
Pascal allows the conversion to take place of an integer to an enumerated type but it is not
possible to do it other way around.
- The integer value can be found by using the function ord of the enumerated value type that can
be used between the integers and enumerated.
- The space can be used with the speed penalty that can be used with the enumerated types and
use of “unord” function to get the output.
type enum = (one, two, three, four, five, six, seven, eight, nine, ten);
var ei: enum;
etran: array [10] of enum;
begin
- The translation of the integer to the enumeration type is difficult task and the use of array
lookup is being used. The translation array depends on the size of the enumerated type or enum.
5. Write a Pascal program and algorithm using a flow chart that can used to solve the
quadratic function Ax2+ Bx + C = 0 [10 marks]
Answer
program Quadratic;
var
A,B,C,D: integer;
begin
write('A = ');
readln(A);
if (A=0) then
begin
writeln('Not a quadratic equation.');
halt;
end;
write('B = ');
readln(B);
write('C = ');
readln(C);
D := B*B-4*A*C;
if (D=0) then
begin
writeln('x = ',-B/2.0/A);
halt;
end;
if (D>0) then
begin
writeln('x1 = ',(-B+Sqrt(D))/2.0/A);
writeln('x2 = ',(-B-Sqrt(D))/2.0/A);
end
else
begin
writeln('x1 = (',-B/2.0/A,',',Sqrt(-D)/2.0/A,')');
writeln('x2 = (',-B/2.0/A,',',-Sqrt(-D)/2.0/A,')');
end;
end.
6. Use the factorial example in Pascal to explain the difference between iteration and
recursion [8 marks]
Answer
An iterative function is one that loops to repeat some part of the code, and a recursive function
is one that calls itself again to repeat the code. Using a simple for loop to display the numbers
from one to ten is an iterative process.
Factorial is a mathematical computation which for instance, the factorial of n is the multiplation
of n * n-1 * n-2 * ... * 0. In factorial, multiplying by 0 results in 1, ie. factorial(0) = 1.
Example
Iteration
Begin
Result := n;
If (n <= 1) Then
Result := 1
Else
For i := n-1 DownTo 1 do
Result := Result * i;
Factorial := Result;
End;
Recursion
Begin
If n = 1 Then
Factorial := 1
Else
Factorial := n*Factorial(n-1);
End;
Answer
program matrix(multi);
uses crt;
var a,b,c:array [1..3,1..3] of integer;
i,j,k:integer;
begin\\{beginning of the program}
clrscr;
writeln('first matrix');
for i:=1 to 3 do \\{beginning of first for loop}
begin
for j:=1 to 3 do
begin
read(a[i,j]);
end;
end;
writeln('second matrix');
for i:=1 to 3 do
begin\\{end of first for loop}
for j:=1 to 3 do\\{beginning of second for loop}
begin
read(b[i,j]);
end;
end;\\{end of second for loop}
for i:=1 to 3 do\\{beginning of third for loop}
begin
for j:=1 to 3 do
begin
c[i,j]:=0;
for k:=1 to 3 do
begin
c[i,j]:=c[i,j]+a[i,k]*b[k,j];
end;
end;
end;\\{end of third for loop}
writeln('Sum of Matrices')
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(c[i,j]:3);
end;
writeln;
end;
end.