Ooad 3
Ooad 3
QUESTION TWO
(a) Debug the following C++ program. (10 Marks)
#include "iostream"
Main[]
{ integer num, square; /declaration of variables
cout<<" Enter a number ";
cin>num;
1
Square = num*num;
QUESTION THREE
(a) Write a single C++ statement for each of the following:
(i) cin object to read two integer variables, a and b using a single statement.
(ii) Scope resolution operator (::) to define a method titled void readEmployee( )
which belongs to a class Employee
(iii) cout object to output three variables x, y and z followed by new line
(iv) Test if a variable newSalary s equal or greater than oldSalary and if true display
the message “New salary is higher”
(v) Derive a class mobilePhone from another class Phone
(vi) Decrement the variable counter by 1 then print its value.
(12 Marks)
(b) Describe four basic data types in C++ (8 Marks)
QUESTION FOUR
(a) List five comparison operators used in C++ and state their meaning. (5 Marks)
(b) Identify errors in the following program. (8 Marks)
#include<iostream.h>
class car
{ private
character colour[10];
int wheelsNumber;
2
public:
void readcar();
void showcar() };
void car::readcar()
{
cout<< "Enter colour of car ";
cin>colour;
cout<< "Enter number of wheels ";
cin>>wheels Number;
}
void car:showcar()
{
cout<< "The car is painted "<<colour;
cout<< "The number of wheels is "<<wheelsNumber;
}
main()
{
car testCar;
testCar.Readcar();
testCar.showcar();
}
(c) Give the syntax of an “if” statement when two alternative outcomes are involved
(3 Marks)
(d) Using examples, differentiate between an attribute and a method. (4 Marks)
QUESTION FIVE
(a) Using examples, briefly discuss the following program components:
(i) Header file
3
(ii) Comment
(iii) Keyword
(iv) Output statement
(v) Input statement
(10 Marks)
(b) Explain the role of the main() function in a C++ program. (2 Marks)
(c) “C++ language is case sensitive”. Explain this statement. (2 Marks)
(d) Discuss two types of loops used in C++. (4 Marks)
(e) Define the term “array” as used in a C++ program and give the syntax of declaring an array.
(2 Marks)