Vous êtes sur la page 1sur 9

MOUNT KENYA UNIVERSITY

RONALD NGODA

BIT/2019/41872

BIT 1102: INTRODUCTION TO PROGRAMMING & ALGORITHM

CAT 1
QUESTION ONE

A) DESCRIBE THE THREE CONTROL STRUCTURES THAT MAKE UP A

COMPUTER PROGRAM [6 MARKS]

There are three control structures namely; selection structure, the repetition structure and

Sequence structure.

1. Selection structure: this structure is used for branching and making decisions. That is

choosing from two or more options. The types of selections are if, if/else and switch.

2. Sequence Structure: this is a structure in which all lines of codes are executed in order. The

execution of programs follows breaking and skipping of statements. It looks like a recipe.

3. The repetition structure: this structure is used for looping pieces of code several times in a

row. The types of loops are while do/while and for. These statements enable the program to

perform the statements repeatedly.

B) EXPLAIN THE QUALITIES OF A GOOD PROGRAM [4 MARKS]

1. Efficiency: a program should be the least amount of processing time and memory since they

are the essential resources.

2. Flexible: a good program should meet new requirements like the addition of new features.

3. Maintainability: a good program should be easy to maintain. This is achieved when the

program is easy to read and understand.

4. Portability: all kinds of computers should support a good program. The program should run

smoothly on all platforms.

5. Readability: it should be written in a way such that all programmer to understand its logic.
C) KK SECURITY LTD. PAYS ITS GUARDS WAGES ON WEEKLY BASIS. THE

GUARDS’ WORKS ON AN EIGHT HOURS PER DAY SHIFT AT A RATE OF KSH. 320

PER DAY, 5 DAYS A WEEK. HOURS WORKED ON SATURDAY ARE PAID AT 15%,

WHILE SUNDAY HOURS ARE PAID AT 20% MORE THAN THE NORMAL WEEK

DAY RATE. REQUIRED DERIVE THE ALGORITHM TO AUTOMATE THE WAGES

CALCULATION AT THE END OF EACH WEEK AND REPRESENT IT USING A

FLOW CHART AND PSEUDO-CODE. [10 MARKS]

ALGORITHM AND PSEUDO-CODE

Step1: Start;

Step2: Initialize the known variables: max hours worked with no overtime (MaxNoOvertime),

bonus rate for overtime hours (BonusRate), non taxable payroll amount (MaxNoDue), tax rate

(Due);

Step3: Enter hours worked overtime (HoursWorked) and hourly rate (HourRate);

Step4: If (HourWorked-MaxNoOvertime)<=0 Then

GrossPay=HoursWorked*HourRate;

Else

GrossPay=HourRate*(MaxNoOvertime + BonusRate*(HoursWorked-MaxNoOvertime));

Step5: If GrossPay<=MaxNoDue Then

NetPay=GrossPay;

Else

NetPay=GrossPay-Due*(GrossPay-MaxNoDue);
Step6: Display GrossPay, NetPay;

Step7: End.

FLOWCHART

QUESTION TWO

a) DIFFERENTIATE BETWEEN PSEUDO-CODE AND FLOW-CHART [4 MARKS]


i. Pseudo code conveys programming ideas that are easy to interpret while the flowchart is

difficult to interpret and only capture the direction of its code.

ii. Pseudo code is a high-level description of algorithms, while flowcharts are pictorial

representations of algorithms.

iii. Pseudo code is a text representation which is in grammatical language that shows how

software applications flow through code while A flow chat is a graphical representation that

shows how software applications through a code.

iv. The pseudo code uses written language to display information while flowcharts use graphics

to show data and information.

B. A PROGRAM IS REQUIRED TO ACCEPT THE LENGTH AND WIDTH OF A

SQUARE AND DISPLAY ITS AREA. DERIVE AN ALGORITHM FOR THE

PROGRAM AND REPRESENT USING PSEUDO CODE [8 MARKS]

Algorithm

Step 1: Start

Step 2: Input Width

Step 3: Input Length

Step 4: Calculate Area = Width * Length

Step 5: Output Area of the Wall

Step 6: Stop

The Pseudo code


L=Input ("Enter Length :")

W=Input ("Width :")

Area=LxW

Print(area)

b) EXPLAIN THE MAIN OBJECTIVES / GOALS OF PROGRAMMING [8

MARKS]

1. Giving learners the necessary skills and foundation for future jobs in the industry of

computing.

2. To provide practical and theoretical knowledge of computing to professionals to

contribute globally to economic development.

3. It gives intellectual abilities that enable professional to adapt to the ever-changing

field of computing.

4. Another objective is to advance education in computer technology and the

development of professionals.

5. Enables learners to understand the terms and concepts that are used in describing

languages that support logic, functional and imperative programming paradigms.

6. To teach how programming techniques can be used to solve problems.

7. It is also used in the evaluation of which questions can be suited for paradigm and

language.

8. To enable learners to use computational techniques in designing and implementing

solutions in real world problems.

QUESTION THREE
a) EXPLAIN THE CHARACTERISTICS OF A GOOD ALGORITHM [6 MARKS]

1. Precision: steps should be explicit and listed one at a time. This prevents any

misinterpretation.

2. Uniqueness: the results for each step should be defined uniquely and should only depend on

the input and results of the preceding step. The directions from each point should be different.

3. Finiteness: the algorithm should stop after a limited number of instructions for execution.

The program should stop once the destination is reached.

4. Output: the algorithm should produce one or several outputs (guidelines)

5. Input: the algorithm should receive input by inputting the start and ending the address.

6. Generality: it should apply for a set of units.

B) EXPLAIN WHY YOU WOULD CHOOSE TO USE THE HIGH LEVEL

PROGRAMMING LANGUAGES OVER THE OTHER TYPES OF PROGRAMMING

LANGUAGES [6 MARKS]

1. Flexible: High-level programming languages are flexible to understand and edit, unlike low-

level programming.

2. High-level programming languages are friendlier to programmers because of their easiness

to debug, maintain, and write.

3. High-level programming languages provide high levels of abstractions from all kinds of

machine languages, unlike other programming languages.

4. High productivity: High-level languages give better results in productivity than other

languages.

5. Less time: High-level languages takes less time than other languages.
6. Lesser prone to errors: High-level languages less prone to mistakes and its easy to debug the

errors than low-level languages.

7. Portability: High-level language is portable, unlike other languages.

8. Support: High-level programming languages have more support than other programming

languages. The high level has an enormous number of professionals than a low-level language.

C) USING A PROGRAM EXAMPLE EXPLAIN THE STRUCTURE OF A C PROGRAM

(8 MARKS)

"Hello World" Program

/* Author: www.cyrusmbithi.com

Date: 2019-09-30

Description:

describes the words "Hello, World!" on the screen */

#include<stdio.h>

int main()

printf("Hello, World!\n");

return 0;
}

 #include <stdio.h> is the Preprocessor directive.

 int main() is the main function. This is where the program execution begins.

 /.../ program comments. Allows for additional comments in the program.

 Printf (...) is the program variable. This makes the message displayable on the screen.

 Return 0; is the Program termination. It ends the main function () and then return the

value 0.

REFERENCES

Ali, M., Deo, R. C., Downs, N. J., & Maraseni, T. (2018). Cotton yield prediction with Markov
Chain Monte Carlo-based simulation model integrated with genetic programing
algorithm: A new hybrid copula-driven approach. Agricultural and forest
meteorology, 263, 428-448.
Haibt, L. M. (1959, March). A program to draw multilevel flow charts. In Papers presented at
the the March 3-5, 1959, western joint computer conference (pp. 131-137). ACM.
Kobayashi, N., & Yonezawa, A. (1994). Type-theoretic foundations for concurrent object-
oriented programing. ACM SIGPLAN Notices, 29(10), 31-45.

Vous aimerez peut-être aussi