Page 199 - C++
P. 199
z*=(x-y); }
void out(int z,int y, int &x)
{ x*=y;
y++;
z/=(x+y); }
void main()
{ int a=10, b=5, c=12;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl;
in(b,c,a);
cout<<a<<"@"<<b<<"@"<<c<<"@"<<endl;
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}
f. Predict the correct output among the given options (i to iv) given below. Name the 2
header files required to execute the code.
int x=10;
void main()
{ randomize();
int x= ::x +random(3);
for (int i=10;i<=x;i++)
cout<< (x*2)<<"&";
}
i. 20& iii. 20&22&24&
ii. 20&22& iv. 20&22&24&26&
2 a. How encapsulation and abstraction are implemented in C++ language? Explain with an 2
example.
b. Answer the questions (i) to (iv) after going through the following class :
class schoolbag
{ int pockets;
public:
schoolbag() //Function 1
{ pockets=3; cout<<"The bag has pockets"<<end1; }
void company() //Function 2
{ cout<<"The company of the Bag is ABC"<<end1; }
schoolbag(int D) //Function 3
{ pockets=D;
cout<<"Now the Bag has pockets"<<pockets<<end1;}
~schoolbag() //Function 4
{ cout<<"Thanks"<<end1; }
};
i. In Object Oriented Programming, what is Function 4 referred as and when ½
does it get invoked/called?
ii. In Object Oriented Programming, which concept is illustrated by Function 1 ½
and Function 3 together?
iii. What is the difference between the following statements: 1
SchoolBag S1(10); //Statement 1
SchoolBag S2=SchoolBag(8); // Statement 2
c. Define a class Customer with the following specifications. 4
Private Members : Customer_no integer
Customer_name char (20)
Qty integer
Page 2 of 6