Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Programming Fundamentals 2019

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

Programming Fundamentals 2019

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

Republic of Rwanda

Ministry of Education
TVET NATIONAL COMPREHENSIVE ASSESSMENT
ACADEMIC YEAR 2019

EXAM TITLE: Programming Fundamentals /100Marks


RTQF LEVEL IV
OPTION: SOFTWARE DEVELOPMENT
DURATION: 3HOURS
INSTRUCTION TO CANDIDATES:
This exam has three section A, B and C
Section A: Answer all questions 55Marks
Section B: Choose Three Questions 30Marks
Section C: Compulsory question 15Marks

SECTION ONE: Answer all questions 55Marks

MAKING GUIDE: PROGRAMMING FUNDAMENTALS


01. The five basic elements in programming are:

1. input: getting data and commands into the computer


2. output: getting your results out of the computer
3. arithmetic: performing mathematical calculations on your data
4. conditional: testing to see if a condition is true or false
5. looping: cycling through a set of instructions until some condition is met

02. There are three types of errors that occur in programs:

1. Syntax errors 1mark: these occur when the program is not written
according to the rules of the language. 1mark
2. Runtime errors 1mark: these occur with programs that, even though
they are syntactically correct, they might execute instructions that

Page 1 of 10
violate some other rules of the language or some other set condition.
1mark
3. Semantic errors or logic error 1mark: these are the cases in which a
program might run without generating error messages, but it will not do
the right thing. As you can imagine, these are generally the most difficult
to figure out. 1mark

03. Pseudocode allows nonprogrammers, such as business analysts, to review


the steps to confirm the proposed code matches the coding specifications but
the programming languages re difficult to read for most people. 2Marks
04. Low-level languages are closer to the language used by a computer, while
high-level languages are closer to human languages. 2marks

High Level Language: allow us to write computer code using instructions


resembling everyday spoken language (for example: print, if, while) which are
then translated into machine language to be executed. 2marks

05.

Data types Size in bits on memory


Char 8bits 1mark
Integer 32bits 1mark
Float 32bits 1mark
Double 64 bits 1mark
Boolean 8bits 1mark

06. Five examples of programming languages: C language, Java, C++, C#,


Python, Cobol, PHP, Pascal.. 1mark per each (select only five)

Page 2 of 10
07.
Truth table of AND Truth table of OR

A b a||b
A b a&&b
1 1 1 0.5
1 1 1 0.5
1 0 1 0.5
1 0 0 0.5
0 1 1 0.5
0 1 0 0.5
0 0 0 0.5
0 0 0 0.5

08.
Local Variable Global variable
Declaration: Variables are declared Declaration: Variables are declared
inside a function. 1mark outside any function. 1mark
Scope: Within a function, inside Scope: Throughout the program.
which they are declared. 0.5marks 0.5marks
Access: Accessed only by the Access: Accessed by any statement in
statements, inside a function in the entire program. 1mark
which they are declared 1mark

09. Advantages of using functions

- writing functions avoids rewriting the same code over and over 1mark
- using functions, it becomes easier to write programs and keep track of
what they are doing 1mark
-reduction in the amount of work and development time 1mark
-functions can be accessed repeatedly 1mark
-reduction in size of the program 1mark
-modular programming 1mark

Page 3 of 10
10. Objects: are instance of a class, that interact with each other at runtime
1.5 marks but class is known as a collection of similar objects or objects
of the same type. 1.5marks
11. a) #include<iostream.h> 3marks
main()
{
double n, cube;
cout<<”enter any number\n”;
cin>>n;
cube=n*n*n;
cout<<”its cube is”<<cube;
}
b) 3marks

12. #include<iostream.h>
main()
{
int max,min; 0.5marks
cout<<”enter any two numbers\n”;
cin>>min>>max;
if(max>min) 1mark

Page 4 of 10
cout<<”the maximum is”<<max; 0.5marks
else if(max<min) 1mark
cout<<”the maximum is”<<min; 0.5marks
else 1mark
cout<<”numbers are equal”; 0.5marks
}

SECTION TWO: Choose Three Questions 30Marks

13. Define the following terms:


a) Object oriented programming: is a method of programming where a
system is considered as a collection of objects that interact together to
accomplish certain task. 2Marks
b) Encapsulation – Encapsulation is capturing data and keeping it safely
and securely from outside interfaces. 2Marks
c) Inheritance- This is the process by which a class can be derived from
a base class with all features of base class and some of its own. This
increases code reusability. 2Marks
d) Abstraction- The ability to represent data at a very conceptual level
without any details. 2Marks
e) Polymorphism- This is the ability to exist in various forms. For
example an operator can be overloaded so as to add two integer
numbers and two floats. 2Marks

14. #include<iostream.h> 10Marks


int factorial(int x);
main()
{
int a,fact;
cout<<”enter a number\n”;
cin>>n;
fact=factorial(a);
cout<<”factorial of”<a<<”is”<<fact<<endl;

Page 5 of 10
}
int factorial(int x)
{
int f=1,i;
for(i=x;i>0;i--)
{
f=f*i;
return(f);
}

15. #include<iostream.h> 10Marks


main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
cout<<”\t”<<”*”;
}
cout<<”\n”;
}
}

16. (a)
1. window.alert(): Display data into an alert box. 1Mark
2. document.write(): Display data into the HTML output. 1Mark
3. innerHTML: Display data into an HTML element. 1Mark
4. console.log(): Display data into the browser console. 1Mark
(b) Developing a program involves a set of steps

 Define the problem 1Mark

Page 6 of 10
 Outline the solution 1Mark
 Develop an algorithm 1Mark
 Test the algorithm for correctness 1Mark
 Code the algorithm using a suitable programming language 1Mark
 Compile and correction of compile errors 1Mark
 Run the program on the computer 1Mark
 Test, document and maintain the program 1Mark

17.
Features of OOP Features of POP

Emphasis is on data rather than Emphasis is on doing things(algorithms)


procedure 1Mark 1Mark

Programs are divided into what we call Large programs are divided into smaller
objects 1Mark programs known as functions. Most of
functions share global data 1Mark

Function and data both are tied together In POP(procedure oriented language)
in a single unit. 1Mark groups of instructions are written which
are executed by compiler in a serial
manner 1Mark

Data is not accessible by external Data move openly around the system
functions as it is hidden 1Mark from function to function 1Mark

It is easy to add new data and functions Functions transform data from one form
whenever required 1Mark to another 1Mark

Follow bottom-up approach in program Employs top-down approach in program


design 1Mark design 1Mark

Page 7 of 10
SECTION THREE: Choose One question 15Marks

18.
Expression Binary value Decimal value

a 01001101 77

b 00010111 23

a&b 00000101 1.5Marks 5 1.5Marks

a|b 01011111 1.5Marks 95 1.5Marks

a^b 01011010 1.5Marks 90 1.5Marks

b<<2 01011100 1.5Marks 92 1.5Marks

b>>1 00001011 1.5Marks 11 1.5Marks

19. (a) 9marks


<html>
<head>
<title>Multiplication Table</title>
<script type="text/javascript">
var rows = prompt("How many rows for your multiplication
table?");
var cols = prompt("How many columns for your
multiplication table?");
if(rows == "" || rows == null)
rows = 10;
if(cols== "" || cols== null)

Page 8 of 10
cols = 10;
createTable(rows, cols);
function createTable(rows, cols)
{
var j=1;
var output = "<table border='1' width='500'
cellspacing='0'cellpadding='5'>";
for(i=1;i<=rows;i++)
{
output = output + "<tr>";
while(j<=cols)
{
output = output + "<td>" + i*j + "</td>";
j = j+1;
}
output = output + "</tr>";
j = 1;
}
output = output + "</table>";
document.write(output);
}
</script>
</head>
<body>
</body>
</html>
(b)

Page 9 of 10
Compiler Interpreter

Scans the entire program and Translates program one statement at


translates it as a whole into machine a time. 1mark
code. 1mark

It generates the error message only Continues translating the program


after scanning the whole program. until the first error is met, in which
Hence debugging is comparatively case it stops. Hence debugging is
hard. 1mark easy. 1mark

It takes large amount of time to It takes less amount of time to


analyze the source code but the analyze the source code but the
overall execution time is overall execution time is slower.
comparatively faster. 1mark 1mark

Page 10 of 10

You might also like