Special Topic ESA QP - Programming With C++ (UE19CS208B)
Special Topic ESA QP - Programming With C++ (UE19CS208B)
Special Topic ESA QP - Programming With C++ (UE19CS208B)
#include <iostream>
using namespace std;
int main ()
{
int numbers[5];
int * p;
p = numbers;
*p = 10;
p++;
*p = 20;
p = &numbers[2];
*p = 30;
p = numbers + 3;
*p = 40;
p = numbers;
*(p + 4) = 50;
for (int n = 0; n < 5; n++)
cout << numbers[n] << ",";
return 0;
}
c) How are Inline functions different from other functions? Give syntax 2M
SRN
2 a) Explain the structure of a class with the help of an example. Show different ways 4M
of Object initialization in class.
3 a) If class B inherits class A privately. And class B has a friend function. Will the 2M
friend function be able to access the private member of class A?
b) Define a “Complex” class. Create two objects of this class which represents a 5M
complex number storing real and imaginary values as integer type. Use a friend
function to overload “+” operator to add two complex number.
c) Fill in the blank 1 and write the conversion function definition under the public 3M
specifier in class test which gives output “converted”.
#include <iostream>
#include <string>
using namespace std;
class test
{
public:
__________________
__________________ // conversion function definition?
};
int main()
{
test t;
string s = ___; // Fill in the blank 1
cout << s << endl;
return 0;
}
Output: Converted
SRN
b) How many VPTR (Vtable pointer) will be created internally for following program? 2M
Justify your answer.
class A {
public:
virtual void f(){
cout<<"A:f()"<<endl;
}
};
class D:public A{
void f(){
cout<<"B:f()"<<endl;
}
};
c) Create an abstract base class EMPLOYEE with data members: Name, EmpID and 6M
BasicSal and a pure virtual function Cal_Sal().
Create one derived class MANAGER (with data members: DA and HRA)
Write member functions to initialize the data, read and write the data and to calculate
the net salary. [Hint: DA = 10% of Basic Salary, HRA = 20% of Basic Salary, Net
salary = Basic Salary + DA + HRA].