Programming Fundamentals 2019
Programming Fundamentals 2019
Ministry of Education
TVET NATIONAL COMPREHENSIVE ASSESSMENT
ACADEMIC YEAR 2019
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
05.
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
- 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
}
Page 5 of 10
}
int factorial(int x)
{
int f=1,i;
for(i=x;i>0;i--)
{
f=f*i;
return(f);
}
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
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
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
Page 7 of 10
SECTION THREE: Choose One question 15Marks
18.
Expression Binary value Decimal value
a 01001101 77
b 00010111 23
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
Page 10 of 10