MG - Software Development - L4 - Programming Fundementals
MG - Software Development - L4 - Programming Fundementals
MARKING GUIDE
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)
a. Program
b. Variable
c. Loop
d. Array
e. Class
MARKING SCHEME
b. Variables are the names you give to computer memory locations which
are used to store values in a computer program. 1mark
Page 2 of 15
variables) and implementations of behavior (member functions or
methods). 1mark
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
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.
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
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.
MARKING SCHEME
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
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
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
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.
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
D.Sequence of
4. Correspond to…..C 4. Compiler instructions given to the
computer to perform a
specific task.
Page 9 of 15
REFERENCE: SFDPF401, PROGRAMMING FUNDAMENTALS, Learning unit
1: Describe basic concepts of programming, Page 269.
MARKING SHEME
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.
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
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.
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