Introduction To Programming & Algorithm Cat 1
Introduction To Programming & Algorithm Cat 1
RONALD NGODA
BIT/2019/41872
CAT 1
QUESTION ONE
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
1. Efficiency: a program should be the least amount of processing time and memory since they
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
4. Portability: all kinds of computers should support a good program. The program should run
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
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);
GrossPay=HoursWorked*HourRate;
Else
GrossPay=HourRate*(MaxNoOvertime + BonusRate*(HoursWorked-MaxNoOvertime));
NetPay=GrossPay;
Else
NetPay=GrossPay-Due*(GrossPay-MaxNoDue);
Step6: Display GrossPay, NetPay;
Step7: End.
FLOWCHART
QUESTION TWO
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
iv. The pseudo code uses written language to display information while flowcharts use graphics
Algorithm
Step 1: Start
Step 6: Stop
Area=LxW
Print(area)
MARKS]
1. Giving learners the necessary skills and foundation for future jobs in the industry of
computing.
field of computing.
development of professionals.
5. Enables learners to understand the terms and concepts that are used in describing
7. It is also used in the evaluation of which questions can be suited for paradigm and
language.
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.
5. Input: the algorithm should receive input by inputting the start and ending the address.
LANGUAGES [6 MARKS]
1. Flexible: High-level programming languages are flexible to understand and edit, unlike low-
level programming.
3. High-level programming languages provide high levels of abstractions from all kinds of
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
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.
(8 MARKS)
/* Author: www.cyrusmbithi.com
Date: 2019-09-30
Description:
#include<stdio.h>
int main()
printf("Hello, World!\n");
return 0;
}
int main() is the main function. This is where the program execution begins.
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.