0% found this document useful (0 votes)
61 views4 pages

Ics 2104 Object Oriented Programming I

The document contains a past exam paper for an Object Oriented Programming course. It consists of 5 questions testing various concepts in OOP like encapsulation, inheritance, polymorphism, function overloading and more. Code examples are provided to demonstrate array declaration, class definition, function definition inside and outside a class, and use of switch statements. Students are asked to write programs applying OOP concepts like defining classes with methods, performing type casting, computing largest of three numbers, and grading coffee quality.

Uploaded by

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

Ics 2104 Object Oriented Programming I

The document contains a past exam paper for an Object Oriented Programming course. It consists of 5 questions testing various concepts in OOP like encapsulation, inheritance, polymorphism, function overloading and more. Code examples are provided to demonstrate array declaration, class definition, function definition inside and outside a class, and use of switch statements. Students are asked to write programs applying OOP concepts like defining classes with methods, performing type casting, computing largest of three numbers, and grading coffee quality.

Uploaded by

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

ICS 2104

W1-2-60-1-6
JOMO KENYATTA UNIVERSITY
OF
AGRICULTURE AND TECHNOLOGY
University Examinations 2014/2015
SECOND YEAR FIRST SEMESTER EXAMINATION FOR THE DEGREE
OF BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY
ICS 2104: OBJECT ORIENTED PROGRAMMING I
DATE: AUGUST 2015 TIME: 2 HOURS
INSTRUCTIONS: ANSWER QUESTION ONE (COMPULSORY) AND ANY OTHER
TWO QUESTIONS

Question One (30 Marks)

a) State the main different between the following terms as used in object oriented
programming. (8 Marks)

(i) Call by value and call by reference

(ii) Constructors and variables

(iii) Public and private variables

(iv) Encapsulation and data construction

b) Using switch statement write a C++ program to display the day depending ion the choice
entered by the user from the key board i.e 1 15 Monday, 2 1 5 Tuesday, 3
Thursday: …….. 7 1 5 Sunday (5 Marks)

c) What is an array? With the help of a code show how an array is declared in C++.
(3
Marks)

d) Explain three (3) reasons as to why object oriented programming is gaining more
popularity as compared to procedural programming. (3 Marks)

e) Explain the output of the following program: (4 Marks)

# include < iostream>


1
ICS 2104

# include < string>


int. main ( )
{
String mystring;
Mystring = “This is the initial string content”;
Cout < < mystring < < end!;
Mystring < < This is a different string content’
Cout < < mystring < < end!;
return 0;
}

f) Given that .. a = 20, b = 5, ( = 9. What is the value of the following expressions


(4
Marks)

(i) a>b&&b>.c

(ii) = = b| |a>=c

g) All variables listed in any program should be associated with their respective data types.
Explain any four data types used in C++. (4 Marks)

Question Two (20 Marks)

a) Briefly explain how to access array in C++ programming. (4 Marks)

b) Write a statement to declare and instantiate an array to hold marks obtained by students
in different subjects in a class. Assume that the class can hold up to 60 students and there
are 8 subjects. (4 Marks)

Char g;
int marks;
if (marks > . 69)
g = ‘A’
else if (if (marks > 59)
g = ‘B’
else if (if (marks > 49)
g = ‘C’
else if (marks > 39)
g = ‘D’
else
g = ‘E’

c) Show how the same piece of program can be implemented using the switch statement.
(5
Marks)

d) What do we mean by Dynamic Binding? How it is useful in OOPs? (3 Marks)


2
ICS 2104

e) Outline the purpose or use of the return. Statement in a function. (3 Marks)

Question Three (20 Marks)

a) Using illustration, describe three (3) types of inheritance. (6 Marks)

b) What is type casting and how is it achieved in C++? (4 Marks)

c) Write a program that declares a class called Rectangle that contains two data members for
length and width. The class should demonstrate the use of functions that are defined
within the class and those that are declared within the class are defined externally. The
program should show the definition of both types of functions. (6 Marks)

d) Give any six (6) rules for a valid constructor in C++. (4 Marks)

Question Four (20 Marks)

a) Describe the following terms: (2 Marks)

(i) Recursivity

(ii) Function overloading

b) At JKUAT, the admission criteria require that an applicant must get a grade equivalent to
60 marks. To enroll for BSc in Computer Science, an applicant must have minimum of
60 marks in group one subject: Physics, Mathematics and English. However, a
candidate with 65 marks in group 2 subjects: English, Physics and Chemistry also
qualified for admission. Write an object oriented program that accepts input from an
applicant and advises whether one qualifies for admission or not.

Required:

The two groups must be implemented as functions: group 1 and group 2 inside your
class.

The program should have menu with 1 and 2 such that if a user enters 10/he has selected
group 1 subjects; and 2 for selecting group 2 subjects. (10 Marks)

c) Discuss the following object oriented concept; use a simple example in each case:

(i) Encapsulation (4 Marks)

(ii) Polymorphism (4 Marks)

Question Five (20 Marks)


3
ICS 2104

a) Outline any five (5) characteristics of C++. (5 Marks)

b) Discuss the main five (5) access specifiers in a class declaration. (5 Marks)

c) Using the concepts of filling, write a C++ program for computing the largest of three
numbers. (5 Marks)

d) Use the switch statement to write a program that accepts the grade of a certain type of
coffee and then outputs an appropriate message based on the following table.
Declare the appropriate variables. (5 Marks)

Grade Message
A Export quality
B Local market
C Goal for blending
All other Rejected

You might also like