Professional Documents
Culture Documents
DICT 2B
GROUP MEMBERS
1.ANNLITA
2.CYNTHIA
3.HELLEN
B) Explain the difference between a constructor and a destructor citing the advantage of
Each
Constructor - Allocates memory to an object
Advantage:
Object initialization
Allows initialization of object data member when an instance of the class is created
F) With the aid of a c++ segment, explain the role of a friend function in OOP
include <iostream>
using namespace std;
class Box
{
private:
int length;
public:
box(): length ( 0 ) { }
friend int printLength(Box); // friend function
};
int printLength (Box b)
{
b.length += 10;
return b.length;
}
int main()
{
Box b;
Cout << “Length of box:” <<printLength(b)<<endl;
Return 0;
}
A friendship function allows a function or another class to access the private and
protected members of a class.
ii). 13-(8%5)>=9%7-3+6*2
1.Modulo
8%5=3
9 % 7 =2
2.Multiplication
6 * 2 = 12
3.Subtraction and addition
13 – 3=10
2 – 3 = -1
-1 + 12 = 11
4.Comparison
10 >= 11
The statement is false because 10 is not greater than or equal to 11