0% found this document useful (0 votes)
84 views

CCS 2101 Computer Programming CAT 1 Marking Scheme

Uploaded by

ioenga741
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

CCS 2101 Computer Programming CAT 1 Marking Scheme

Uploaded by

ioenga741
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CAT 1

CCS 2101 Computer Programming


Time: 1 HOUR (Feb 2024)
Civil (Bse & Bed), Bsc Mechatronic

Question One
i) Explain the role of machine language when writing program [2 marks]
Machine language - directly understood by the computer's CPU. Higher-level programming languages
must be translated into machine language for execution
ii) Discuss the principle of structured programming. [3 Marks]
a. Sequence: Programs are composed of sequences of statements that are executed in
order, one after the other. This is the most basic form of control flow and is present in
all programming languages.
b. Selection: Programs can make decisions based on the evaluation of conditions. This
is usually done using if-else statements or switch statements. The program can
choose between different paths of execution based on the outcome of the conditions.
c. Iteration: Programs can repeat a sequence of statements multiple times. This is
usually done using loops, such as for loops, while loops, or do-while loops. The
program can execute the same sequence of statements multiple times, potentially
with different inputs or outputs each time.

iii) Identify the output of the following program:


#include void main ( ) { int x =10; float z, y =3.0; z = x%y; printf (“z=%f”,z); } [2 marks]
Error message
i. The main function should return an integer, and the correct signature for the main function is
int main().
ii. Modulus division operator produces the remainder of an integer division

iv) Explain the following concepts as used in structured programming:


a) Modularity
b) Algorithm
c) Flow chart [6 Marks]

i) Modularity:
Modularity in structured programming refers to the practice of breaking down a program
into smaller, more manageable pieces or modules. Each module is responsible for a
specific task or function within the program. By breaking the program into modules, it
becomes easier to understand, modify, and maintain. Modularity promotes code reuse, as
modules can be reused in different parts of the program or in other programs altogether.
This approach also facilitates team-based development, as different team members can
work on different modules simultaneously.

ii) Algorithm:
An algorithm is a step-by-step procedure or set of rules for solving a problem or
accomplishing a task. In structured programming, algorithms are used to describe the
logical flow of a program. Algorithms are typically expressed in pseudocode or a
programming language, and they are often represented using flowcharts or other visual
aids. Good algorithms are efficient, meaning they accomplish the desired task with
minimal resources (such as time and memory).

iii) Flowchart:
d) A flowchart is a visual representation of the logical flow of a program or algorithm. It
uses symbols and arrows to represent the different steps or processes in the program,
as well as the order in which they are executed. Flowcharts are useful for
understanding the structure of a program, as they provide a high-level overview of
the program's logic. They can also be used to document the program, making it
easier for others to understand and modify. In structured programming, flowcharts
are often used in the design and analysis phases of software development.

v) Explain any THREE types of errors in computer programming [6 marks]


i)Syntax Errors:
Syntax errors occur when the rules of a programming language are not followed. These errors are
detected by the compiler or interpreter before the program is executed. Examples of syntax errors
include missing semicolons at the end of statements, misspelled keywords, or incorrect use of
punctuation. Since syntax errors prevent the program from being compiled or executed, they are
typically easy to detect and fix.
ii)Logical Errors:
Logical errors occur when the program's logic is flawed, leading to incorrect results. Unlike syntax errors,
logical errors do not prevent the program from being compiled or executed; instead, they cause the
program to produce incorrect output. Examples of logical errors include using the wrong variable in a
calculation, using the wrong operator, or failing to account for all possible conditions in a decision-
making process. Logical errors can be difficult to detect and fix because they often require a deep
understanding of the program's logic and the problem being solved.
iii)Runtime Errors:
Runtime errors, also known as exceptions or run-time errors, occur during the execution of a program.
These errors are not detected by the compiler or interpreter and can cause the program to crash or
produce unexpected behaviour. Examples of runtime errors include dividing by zero,

vi) Explain the following as used in programming:


a) Portability
b) Module re-use [4 marks]

Portability – ability of the same software to be used in different computer platforms/ operating systems/
architecture.

Module – Is a software design technique that emphasizes separating the functionality of a program independent
units, such each contains everything necessary to execute only one aspect of the desired functionality.
Module reuse- allows developers to create and use modules as building blocks for larger systems. Parts of
Modules can be reused in different parts of the same systems or in different systems as long as they have clear
interfaces and dependencies.

Question two
Write an algorithm , flowchart, pseudocode and a c program that check whether an integer number
typed is positive or negative.

To check positive or negative number

Step 1: Start
Step 2: get num
Step 3: check if(num>0) print a is positive
Step 4: else num is negative
Step 5: Stop
BEGIN
READ num
IF (num>0) THEN
DISPLAY num is positive
ELSE
DISPLAY num is negative
END IF
END

You might also like