






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Object Oriented programming questions with answers
Typology: Exercises
1 / 10
This page cannot be seen from the preview
Don't miss anything!







a) Describe three types of classes required to work with data (disk): [3 Marks]
b) List and Explain the access Specifiers used in OOP [6Marks]
Public: data members and member functions are accessible outside the class. Protected: data members and member functions are only available to derived classes. Private: data members and member functions can’t be accessed outside the class.
c) What is public accessor method and why is it necessary? [4 Marks]
This is a class member function that other parts of the program call to either read or set the value of a private member variable. The general rule to ensure security and accessibility of the data is to keep class data private and create a public function called public accessor method.
d) Differentiate between the following.
i. Function overloading. [2 Marks]
Compile time polymorphism. The function is overloaded
ii. Operator overloading [2 Marks]
Compile time polymorphism. The function is overloaded. Requires creation of a function called operator function
e) Using a syntax code explain the following terms as used in C++ Programming.
i. Destructor [4 Marks] This is a special function in a class which has the same name as its class, has no return type and returns no value. Used to free computer when the data members of the class are destroyed/. Class rectangle { Int length;
a) Explain the term Abstract class [2 Marks]
This is a class designed to be specifically used as a base class. It contains at least one pure virtual function.
b) Using a simple program briefly explain the concept for multiple inheritance in C++
[4 Marks]
Process of creating new class from more than one existing classes.
class A //Base class
{}
class B //Base class
{}
class C : public A , public B // derived class
{}
c) (^) When is a virtual function made “pure”? And what is purpose of a having a pure function? [8 Marks]
d) Write a program that saves/writes students names to a disk file. [6 Marks]
// #include
#include
using namespace std;
int main ()
ofstream myfile; //object of type ofstream created
myfile.open ("example.txt");
myfile << "Names for Students.\n 1. Silas\n 2. Nkirote\n 3. Faith \n 4. Caleb\n 5. Patience\n";
myfile.close();
.1 return 0;
account::getdata(); cout <<"Enter Interest\n"; cin >>interest; cout<<"Enter Withdrawal amount\n"; cin>>withdrawal; } void putdata (void) { account::putdata(); cout<<"Interest\n :"<<interest; cout<<"Withdraw amount\n: "<<withdrawal; } }; int main () { saving s1; cout << "Enter data for savings account customer 1:"; s1.getdata(); cout<<"Display data on savings account customer 1:"; s1.putdata(); return 0; }
b) Discuss the three major components of the Standard Template Library [5 Marks]
a) List and explain three types of programming errors [6 Marks]
b) Explain the following terms in exceptions handling mechanism
[6 Marks]
b)..i Hit the exception - Find the problem
b)..ii Throw an exception - Inform that an error has occurred
b)..iii Catch the exception - Receive the error information
b)..iv Handle the exception - Take the corrective action
c) Explain the concept of templates. Differentiate between function and class
templates [4 Marks]
d) Explain the term namespace [4 Marks]
The format of namespaces is:
namespace identifier
{
Entities;
}
To avoid use of goto tightly controlled looping commands have been introduced: for, while, do---while. Use of goto is always a sign of bad design. Avoid using it.
c) Using a simple diagram show an example of an inheritance hierarchy for university
community members. [6 Marks]
End of Exam