Q1. What is a copy constructor in c++? How it is declared ? Explain with a suitable example.
Q2. How can the unary operator ++ be overloaded in C++ for postfix operation ? Demonstrate with a suitable example.
Q3. How does C++ help with the trade-off of safety vs. usability?
Q4. What is the output of following program? Justify your answer.
#include
using namespace std;
class Test
{
static int x;
public:
Test() { x++; }
static int getX() {return x;}
};
int Test::x = 0;
int main()
{
cout << Test::getX() << " ";
Test t[5];
cout << Test::getX();
}
Q5.What is difference between a template and a macro? Give suitable example of each.
Q6. Implement a function f that takes three arguments: pointers to two integer arrays A and B and the size N. It then populates B where B[i] is the product of all A[j] where j ≠ i.
For example : if A = { 2,1,5,9 } then B will be { 45,90,18,10 }.
Q7. How can we create an abstract class in C++ ? Explain with suitable example.
Q8.Write a C++ program to copy one file into another.
Q9.What will be the result of following expressions when they are executed in sequence?
#include
#include
void main()
{
int a = 10, b = 20,c,d,e,f;
c = ++a + ++a + ++a;
b=b++ + b++;
e=a++ + --a + b--;
f=b-- & ++a + b++;
cout< getch();
}
Q10.Write a C++ program using classes and objects to simulate result preparation system for 20students. The data available for each student includes:Name (includes first, mid and last name each of size 20 characters), Rollno, Marks in 3 subjects. The percentage marks and grade are to be calculated from the following information:
Percentage marks
|
Grades
|
<50
|
F
|
≥ 50<60
|
D
|
≥ 60<75
|
C
|
≥ 75<90
|
B
|
≥ 90<100
|
A
|