0% found this document useful (0 votes)
20 views15 pages

MG - Software Development - L4 - Programming Fundementals

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

MG - Software Development - L4 - Programming Fundementals

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

NATIONAL TVET COMPREHENSIVE ASSESSMENT

ACADEMIC YEAR 2020-2021

MARKING GUIDE

SECTOR: INFORMATION COMMUNICATION AND TECHNOLOGY


TRADE: SOFTWARE DEVELOPMENT
RTQF LEVEL: IV
MODULE CODE AND TITLE: SFDPF401, PROGRAMMING FUNDAMENTALS

DURATION: 3HOURS

INSTRUCTION TO CANDIDATES:
This exam has three sections: A, B and C.
- Section A: Answer all the questions (55 marks)
- Section B: Attempt all tree questions (30 marks)
- Section C: Choose one question (15 marks)

Page 1 of 15
SECTION A: Answer all the questions (55 marks)

Q1. Define the following terms. (5 marks)

a. Program
b. Variable
c. Loop
d. Array
e. Class

MARKING SCHEME

a. A computer program is a collection of instructions that can be executed by


a computer to perform a specific task. A computer program is usually
written by a computer programmer in a programming language. 1mark

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 1:


Describe basic concepts of programming, Page 269.

b. Variables are the names you give to computer memory locations which
are used to store values in a computer program. 1mark

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 2:


Apply declaration of variables, its data types and operators, Page 274.
c. In computer science, a loop is a programming structure that repeats a
sequence of instructions until a specific condition is met. Programmers
use loops to cycle through values, add sums of numbers, repeat
functions, and many other things. 1mark

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 3:


Conditional and control flow, Page 281.
d. An array is a data structure consisting of a collection of elements (values
or variables), each identified by at least one array index or key. 1mark

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit


4: Define a function, Page 284.

e. In object-oriented programming, a class is an extensible program-code-


template for creating objects, providing initial values for state (member

Page 2 of 15
variables) and implementations of behavior (member functions or
methods). 1mark

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit


5: Apply basic object-oriented principles in the target language Page 288.

Q2. What are the basic concepts used in the Object-Oriented Programming
language? /5marks

MARKING SCHEME

- Object
- Class
- Data Abstraction and Encapsulation
- Polymorphism
- Inheritance
- Message passing
- Dynamic binding

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 5:


Apply basic object-oriented principles in the target language Page 288.

Q3. Give the difference between local and global variables. /2marks
MARKING SCHEME
Global variables can be referred anywhere in the code within any function,
whenever it is after its declaration. Global variables are usually declared
outside of any function. but
Local variables are variables declared within the body of the function. They are
limited to the function in which they are declared.

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 2:


Apply declaration of variables, its data types and operators, Page 274.
Q4. List the Components of a C++ function. (5 marks)
MARKING SCHEME
Every function has the following elements associated with it:
1. Function declaration or prototype.
2. Function parameters (formal parameters)
Page 3 of 15
3. Function definition (function declaration and a function body).
4. Return statement.
5. Function call.
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 4:
Define a function, Page 286.

Q5. Complete the following table: /5marks

Operator Operation Value of Sum Value of Sum


before after
Addition Sum+=2 8
Subtraction Sum&=3 8
Division Sum=Sum||4 8
Multiplication !Sum 8
Modulus Sum%=6 8

MARKING SCHEME
Operator Operation Value of Sum Value of Sum
before after
Addition Sum+=2 8 10
Subtraction Sum&=3 8 2
Division Sum=Sum||4 8 1
Multiplication !Sum 8 1
Modulus Sum%=6 8 1

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 2:


Apply declaration of variables, its data types and operators, Page 277.

Q6. Answer by true or false/5marks

a. In computer programming, a program is not limited to a linear of


sequence of instructions during its process. It may also repeat code or
take decision.

Page 4 of 15
b. A program written in high-level language is called a source code. We
need to convert the source code into machine code and it is
accomplished by compilers and interpreters.
c. To specify the kind and size of value to be stored in a variable we use
data type.

d. It is not allowed to use special characters in naming a variable, except


when you are working with pointers.
e. Recursive function is referred to as a user defined function that calls
itself.

MARKING SCHEME

a. True. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,


Learning unit 1: Describe basic concepts of programming, Page 269.
b. False REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,
Learning unit 1: Describe basic concepts of programming, Page 269.

c. True. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,


Learning unit 3: Conditional and control flow, Page 281.

d. False. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,


Learning unit 3: Conditional and control flow, Page 281.

e. True REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,


Learning unit 4: Define a function, Page 284.

Q7. Analyze the following code and give its output. /4Marks

#include <iostream>
using namespace std;
void foo(int*pValue)
{
*pValue=75;
}
int main(int argc, char** argv) {
int nValue;

Page 5 of 15
foo(&nValue);
cout<<"nValue="<<nValue<<endl;
return 0;
}
MARKING SCHEME
The output will be
nValue=75
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 4:
Define a function, Page 284.

Q8. Analyze the following code and give its output. /4Marks

#include<iostream>
using namespace std;
int main()
{
int a=6,b=12,c,d;
b%=a;
c=(d=1,d+2);
d+=2;
b/=5;
cout<<”This means that:”<<endl;
cout<<”A IS=”<<a<<”\n B IS=”<<b<<”\n C IS=”<<c<<”\n D
IS=”<<d<<endl;
}

MARKING SCHEME
The output will be
This means that:
A IS=6
B IS=0
C IS=3
D IS=3
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 2:
Apply declaration of variables, its data types and operators, Page 277.

Page 6 of 15
Q9 Choose the correct answer according to the expression

i) A continue statement causes execution to skip to /4Marks


A. The return 0; statement
B. The first statement after the loop
C. The statement following the continue statement
D. The next iteration of the loop
ii) int i = 4;

int x = 6;
double z;
z = x / i;
printf(“z=%.2f\n”, z);
What will print when the sample code above is executed?(1mark)
a. Choice 1 z=0.00
b. Choice 2 z=1.00
c. Choice 3 z=1.50[Ans]
d. Choice 4 z=2.00
e. Choice 5 z=NULL

iii) A pointer pointing to a variable that is not initialized is called


____ /4Marks

A. Void Pointer
B. Null Pointer
C. Empty Pointer
D. Wild Pointer
iv) Default constructor has ____ arguments. /4Marks

A. No argument
B. One Argument
C. Two Argument
D. None of these
V) Which one of the following variable names is NOT valid?(1mark)
A. Choice 1 go_cart
B. Choice 2 go4it
C. Choice 3 4season[Ans]
D. Choice 4 run4
E. Choice 5 _what

Page 7 of 15
MARKING SCHEME

i. D. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,


Learning unit 3: Conditional and control flow, Page 282.
ii. B. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,
Learning unit5: Apply basic object-oriented principles in the target
language Page 289.
iii. B. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning
unit 4: Define a function, Page 284.
iv. A. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS,
Learning unit 5: Apply basic object-oriented principles in the target
language Page 289.
v. C. REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning
unit 3: Conditional and control flow, Page 281.

Q10. Match the following terms with their meaning respectively./5marks

Answer Term Meaning


A.Description of
1. Correspond to….. 1. Flowchart computer program
without strict
programming
language

B. Pictorial or graphical
2. Correspond to….. 2. Computer Program representation of an
algorithm /
pseudocode

C. Program that
3. Correspond to….. 3. Pseudocode converts high level
language into
machine language

D. Sequence of
4. Correspond to….. 4. Compiler instructions given to

Page 8 of 15
the computer to
perform a specific
task.

5. Correspond to….. E. Memory location to


5. Variable store data or value

MARKING SCHEME
Answer Term Meaning
A.Description of
4. Correspond to…..B 1. Flowchart computer program
without strict
programming language

B.Pictorial or graphical
A. Correspond to…..D 2. Computer Program representation of an
algorithm / pseudocode

C.Program that converts


B. Correspond to…..A 3. Pseudocode high level language into
machine language

D.Sequence of
4. Correspond to…..C 4. Compiler instructions given to the
computer to perform a
specific task.

6. Correspond to…..E E.Memory location to


5. Variable store data or value

Page 9 of 15
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit
1: Describe basic concepts of programming, Page 269.

Q11.The use of functions offers flexibility in the design, development, and


implementation of the program to solve complex problems. What are the
advantages of using functions in programming?/5marks

MARKING SHEME

The advantages of functions include the following:

 Modular programming
 Reduction in the amount of work and development time
 Program and function debugging is easier
 Division of work is simplified due to the use of divide-and-conquer
principle.
 Reduction in size of the program due to code reusability
 Functions can be accessed repeatedly without redevelopment, which in
turn promotes reuse of code.
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 4:
Define a function, Page 283.

SECTION B: ATTEMPT ALL QUESTIONS 30 marks

Q.11 Rewrite the following program using nested if condition./10marks

1. #include <iostream>
2. using namespace std;
3. int main() {
4. char oper;
5. float num1, num2;
6. cout << "Enter an operator (+, -, *, /): ";
7. cin >> oper;
8. cout << "Enter two numbers: " << endl;
9. cin >> num1 >> num2;
10.

Page 10 of 15
11. switch (oper) {
12. case '+':
13. cout << num1 << " + " << num2 << " = " << num1 + num2;
14. break;
15. case '-':
16. cout << num1 << " - " << num2 << " = " << num1 - num2;
17. break;
18. default:
19. // operator is doesn't match any case constant (+, -, *, /)
20. cout << "Error! The operator is not correct";
21. break;
22. }
23.
24. return 0;

25. }

MARKING SCHEME
#include <iostream>
using namespace std;
int main() {
char oper;
float num1, num2;
cout << "Enter an operator (+, -, *, /): ";
cin >> oper;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;

Page 11 of 15
if(oper=='+'){
cout << num1 << " + " << num2 << " = " << num1 + num2;
}
else if(oper='-')
{
cout << num1 << " - " << num2 << " = " << num1 - num2;
}
// operator is doesn't match any case constant (+, -, *, /)
else
cout << "Error! The operator is not correct";
return 0;
}
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 3:
Conditional and control flow, Page 281.

Q12. What are the difference and similarities between constructor and
destructor? /10marks

MARKING SCHEME

Two differences between constructor and destructor

-Constructor may have unlimited number of parameters whereas destructor


does not have parameters
- Constructor does not have tilde sign whereas destructor is shown by tilde
sign (~)
Two similarities between constructor and destructor
-Both have the same name as class
-Both do not return a value

REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit5:


Apply basic object-oriented principles in the target language Page 288.

Q13. Using class, write a program to display the sum of all numbers from 1 to
10./10marks
MARKING SCHEME
#include<iostream.h>
Page 12 of 15
class number
{
int i, sum;
public:
void display()
{
sum=0;
for(i=1;i<=10;i++)
{
sum+=i;
}
cout<<”sum is”<<sum;
}
};
void main()
{
number n;
n.display();
}
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 4:
Define a function, Page 284.

SECTION C : CHOOSE ONLY ONE QUESTION 15marks

Q14. Write a program allows entering 15 numbers and sorting them in


ascending order, using arrays.

MARKING SCHEME

1. #include<iostream.h>
2. void main()
3. {
4. int t[15];
5. int temp;
6. cout<<”give 15 values(whole)”<<endl;
7. for(int i=0;i<15;i++)
Page 13 of 15
8. cin>>t[i];
9. for(i=0;i<15;i++)
10. for(int j=i+1;j<15;j++)
11. if(t[i]>t[j])
12. {
13. temp=t[i];
14. t[i]=t[j];
15. t[j]=temp;
16. }
17. cout<<”there are your values in growing order”<<endl;
18. for(i=0;i<15;i++)
19. cout<<t[i];
20. }
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 4:
Define a function, Page 284.

Q15. Information needed to record a book is book name, price and number of
pages. Write a C++ program using structure to record information of five different
books and then display them on the screen

MARKING SCHEME

1. #include<iostream.h>
2. struct book
3. {
4. char name[10];
5. float price;
6. int pages;
7. };
8. main()
9. {
10. book b[5];
11. int i;
12. for (i =0; i<5; i++)
13. {
Page 14 of 15
14. cout<< "Enter the name price and no of pages\n";
15. cin>> b[i].name;
16. cin>> b[i].price;
17. cin>> b[i].pages;
18. }
19. cout<<"you entered\n";
20. cout<<"names"<<"\t"<<"price"<<"\t"<<"no of pages"<<endl;
21. for (i=0; i<5; i++)
22. {
23. cout<< b[i].name <<"\t"<<b[i].price <<"\t"<<b[i].pages<<endl;
24. }
25. }
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit 5:
Apply basic object-oriented principles in the target language Page 288.

Page 15 of 15

You might also like