Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Special Topic ESA QP - Programming With C++ (UE19CS208B)

The document contains questions related to C++ programming concepts like classes, inheritance, polymorphism, templates and exception handling. 1. The first question asks to predict the output of code snippets involving pointers, arrays and references. It also asks about the differences between inline and regular functions. 2. The second question involves class concepts like structure of a class, different ways of object initialization, explicit constructor calls, parameterized and copy constructors. 3. The third question tests knowledge of inheritance concepts like private inheritance, friend functions, abstract base classes and pure virtual functions. 4. The remaining questions cover output of a code using multiple inheritance, use of class templates, and explanation of exception handling mechanism in C++

Uploaded by

lucifer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Special Topic ESA QP - Programming With C++ (UE19CS208B)

The document contains questions related to C++ programming concepts like classes, inheritance, polymorphism, templates and exception handling. 1. The first question asks to predict the output of code snippets involving pointers, arrays and references. It also asks about the differences between inline and regular functions. 2. The second question involves class concepts like structure of a class, different ways of object initialization, explicit constructor calls, parameterized and copy constructors. 3. The third question tests knowledge of inheritance concepts like private inheritance, friend functions, abstract base classes and pure virtual functions. 4. The remaining questions cover output of a code using multiple inheritance, use of class templates, and explanation of exception handling mechanism in C++

Uploaded by

lucifer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SRN

PES University, Bangalore UE19CS208B


(Established under Karnataka Act No. 16 of 2013)

Special Topic ESA


END SEMESTER ASSESSMENT (ESA) III SEMESTER- December 2020
UE19CS208B- Programming with C++
Time: 2 Hrs Answer All Questions Max Marks: 50

1 a) Fill in the blank 1 and blank 2 and predict the output. 4M


void square (int *x, int *y)
{
*x = (*x) * --(*y);
}
int main ( )
{
int number = 30;
square ( _____ ,______ ); //Fill in the blank1 and blank2 with arguments
cout << number;
return 0;
}

b) What will be the output of the following C++ code? 4M

#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.

b) Write a correct explicit call to a constructor of class A? 2M


class A {
int a;
public:
A (int i)
{
a = i;
}
}

c) Explain the parameterized and copy constructors with example. 4M

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?

a) Yes, because friend function can access all the members


b) Yes, because friend function is of class B
c) No, because friend function can only access private members of friend class
d) No, because friend function can access private member of class A also

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

4 a) Define Inheritance in C++. How does constructor work in Inheritance? 2M

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].

5 a) Write the output of the below program. 3M


#include<iostream>
using namespace std;
class A {
protected: int a;
public:
A(int a1){a=a1;cout<<"ctor A"<<endl;}
A(){cout<<"default ctor A"<<endl;}
~A(){cout<<"dtor A"<<endl;}
};
class B:public A {
protected: int b;
public:
B(int a1,int b1):A(a1){
b=b1; cout<<"ctor B"<<endl;}
~B(){cout<<"dtor B"<<endl;}
};
class C:public A {
protected: int c;
public:
SRN

C(int a1,int c1):A(a1){


c=c1; cout<<"ctor C"<<endl;}
~C(){cout<<"dtor C"<<endl;}
};
class D:public B,public C {
protected: int d;
public:
D(int a1,int b1,int c1,int d1):B(a1,b1),C(a1,c1){
d=d1; cout<<"ctor D"<<endl;}
~D(){cout<<"dtor D"<<endl;}
void show(){
cout<<"a="<<B::a<<" b="<<b<<" c="<<c<<" d="<<d<<endl;}
};
int main( ) {
D d(1,2,3,4);
d.show( );
return 0;
}

b) Illustrate the use of class templates. 3M

c) What is Exception Handling? Explain the mechanism of Exception Handling in 4M


C++.

You might also like