Assignment It
Assignment It
Class: Form3
Subject: Information technology
Due Date: 11th June 2008
Software Engineering
Software engineering is the application of a systematic, disciplined, quantifiable
approach to the development, operation, and maintenance of software. It
encompasses techniques and procedures, often regulated by a software
development process, with the purpose of improving the reliability and
maintainability of software system. The discipline of software engineering
includes knowledge, tool, and methods for software requirements, software
design, software construction, and software testing and software maintenance
tasks.
While-Do loop
A while-do loop contains the statements that are to be repeated. These statements
are enclosed by the reserved word BEGIN and END, forming what is called a
compound statement. A comment is frequently placed at the of loop so you know
which loop the END terminates. When using a While-Do loop, a variable is use to
determine whether the loop should be executed or not.
Examples of While-Do loops
The following problem is an example of a SENTINEL CONTROLLED
PROCESS:
Read in integers until a -1 is encountered. The output is to consist
of (1) the number of integers entered; (2) their real average; (3) the
largest integer entered. All variables are declared integer, except
Average is declared real.
{ read next number only after previous number has been completely
processed }
Read(Number)
End;
If Count > 0
Then
Begin
Average := Sum / Count;
Writeln('There were ', Count, 'numbers entered.');
Writeln('Their average is: ', Average :0:2);
Writeln('The largest number entered was: ', Largest)
End
Else
Writeln('There was no data processed.');
Number_to_read := 50;
Count := 0;
Sum := 0;
If Count > 0
Then
Begin
Average := Sum / Count;
Writeln('Their average is: ', Average :0:2)
End
Else
Writeln('There was no data processed.');
Uses
Crt;
Const
Max_row = 9;
Max_col = 9;
Var
Row, Column, Product: Integer;
Begin
Clrscr;
Row := 1;
Writeln(' x | 1 2 3 4 5 6 7 8 9');
Writeln('---|---------------------------------------------');
While (Row <= Max_row) Do
Begin
Column := 1;
Write(Row :2, ' |');
While (Column <= Max_col) Do
Begin
Product := Row * Column;
Write(Product :5);
Column := Column + 1
End;
Writeln;
Row := Row + 1
End;
Readln
End.
PROGRAM OUTPUT:
x| 1 2 3 4 5 6 7 8 9
---|---------------------------------------------
1| 1 2 3 4 5 6 7 8 9
2| 2 4 6 8 10 12 14 16 18
3| 3 6 9 12 15 18 21 24 27
4| 4 8 12 16 20 24 28 32 36
5| 5 10 15 20 25 30 35 40 45
6| 6 12 18 24 30 36 42 48 54
7| 7 14 21 28 35 42 49 56 63
8| 8 16 24 32 40 48 56 64 72
9| 9 18 27 36 45 54 63 72 81
Repeat-Until loop
A Repeat-Until loop contains the statements that are to be repeated because the
reserved woras REPEAT AND UNTIL are sufficient to let the compiler know
what statements constitute the loop. A repeat until loop is similar to a while-do
loop. The repeat until loop always executes the loop once while-do loop does not
execute the loop at all.
Examples of repeat-until loops
The Repeat loop is a bottom driven loop (i.e., the Boolean test follows the
execution of the loop body). Notice that:
(1) The loop body will ALWAYS be executed at least once, since the Boolean test
comes after carrying out the instructions in the loop. Thus a REPEAT UNTIL
loop should NEVER be used when it is a logical possibility that the loop
should never execute. REPEAT LOOPS ALWAYS EXECUTE AT LEAST
ONCE!
(2) A BEGIN-END pair is not necessary around the loop body in a REPEAT
UNTIL loop,
since the key words REPEAT and UNTIL encapsulate the instructions in the
loop
body.
(3) Notice the primary distinction between WHILE and REPEAT loops: a
WHILE loop
executes while (as long as) the Boolean test is TRUE. A REPEAT loop
executes
until the Boolean becomes true (i.e., while the Boolean is FALSE).
Count := 1;
Base := 4;
Power := 1;
REPEAT
Power := Power * Base;
Count := Count + 1;
UNTIL (Count = 5);
Writeln('Four to the fifth power is ', Power);
Program Menu;
Uses
Crt;
Var
Count, Sum, Value, Largest: Integer;
Average: Real;
Choice: Char;
Begin
Largest := 0;
Count := 0;
Sum := 0;
Randomize;
REPEAT
Clrscr;
Writeln('A. Generate a new value.');
Writeln('B. Report average to this point.');
Writeln('C. Report highest value to this point.');
Writeln('Q. QUIT');
Writeln;
Write('Enter your selection ==> ');
Readln(Choice);