Programming in Modern C++ | Week 6
Course Name: Programming in Modern C++
Course Link: Click Here
These are Nptel Programming in Modern C++ Assignment 6 Answers
Quiz
Q1. Consider the following code segment.
What will be the output?
a) 13
b) 14
c) 23
d) 24
Answer: b) 14
Q2. Consider the following code segment.
What will be the output/error?
a) 10 6
b) 10 4
c) 8 6
d) 8 4
Answer: a) 10 6
These are Nptel Programming in Modern C++ Assignment 6 Answers
Q3. Consider the following code segment.
What will be the output?
a) ABC ~C ~B ~A
b) ABC ~C ~B
c) ABC~B~A
d) ABC ~A
Answer: d) ABC ~A
Q4. Consider the following code segment.
Which line/s will give you error?
a) LINE-1
b) LINE-2
c) LINE-3
d) LINE-4
Answer: b, c
These are Nptel Programming in Modern C++ Assignment 6 Answers
Q5. Consider the following code segment.
Which line/s will give you error?
a) LINE-1
b) LINE-2
c) LINE-3
d) LINE-4
Answer: a, d
Q6. Consider the following code segment.
What will be the output?
a) A::f(0) B::g() C::h()
b) C::f() C::g() B::h()
c) C::f() B::g() B::h()
d) C::f() C::g() C::h()
Answer: a) A::f(0) B::g() C::h()
These are Nptel Programming in Modern C++ Assignment 6 Answers
Q7. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print 2.
a) cb->B::fun()
b) B::fun()
c) B::cb->fun()
d) cb->fun()
Answer: a) cb->B::fun()
Q8. Consider the following code segment.
Identify the abstract classes.
a) Vehicle, Car, MotorCycle
b) Vehicle, Car, SUV
c) Vehicle, Car
d) Vehicle, Car, SportsCar, SUV
Answer: b) Vehicle, Car, SUV
These are Nptel Programming in Modern C++ Assignment 6 Answers
Q9. Consider the following code segment.
What will be the output?
a) 0
b) 1
c) 2
d) Garbage
Answer: a) 0
Programming Assignment of Programming in Modern C++
Question 1
Complete the program with the following instructions.
• Fill in the blank at LINE-1 with proper access specifier.
• Fill in the blanks at LINE-2 to declare area() as a pure virtual function.
The program must satisfy the given test cases.
Solution:
#include<iostream>
using namespace std;
class Shape
{
protected:
double ar;
public:
virtual void area()=0;
void show()
{
cout << ar << " ";
}
};
These are Nptel Programming in Modern C++ Assignment 6 Answers
Question 2
Consider the following program with the following instructions.
• Fill in the blank at LINE-1 with appropriate destructor declaration.
• Fill in the blank at LINE-2 with appropriate initialization list of derived class constructor.
The program must satisfy the sample input and output.
Solution:
#include<iostream>
using namespace std;
class Base
{
public:
Base()
{
cout << "1 ";
}
Base(int n)
{
cout << n << " ";
}
virtual ~Base()
{
cout << "2 ";
};
};
class Derived : public Base
{
int num;
public:
Derived()
{
cout << "3 ";
}
Derived(int n) : Base(n), num(n*3)
{
cout << num << " ";
}
virtual ~Derived()
{
cout << "4 ";
}
};
These are Nptel Programming in Modern C++ Assignment 6 Answers
Question 3
Consider the following program. Fill in the blanks as per the instructions given below:
• Fill in the blanks at LINE-1 with an appropriate keyword.
• Fill in the blank at LINE-2 with an appropriate function declaration.
• Fill in the blank at LINE-3 with an appropriate statement.
such that it will satisfy the given test cases.
Solution:
#include<iostream>
using namespace std;
class B
{
protected:
int s;
public:
B(int i=0) : s(i)
{}
virtual ~B()
{}
virtual int fun(int x)=0;
};
class D : public B
{
public:
D(int i) : B(i)
{}
~D();
int fun(int x)
{
return s+x;
}
};
class Z
{
public:
void fun(int a, int b)
{
B *t = new D(a);
int i = t->fun(b);
cout << i << " ";
delete t;
}
};
These are Nptel Programming in Modern C++ Assignment 6 Answers
* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.
These are Nptel Programming in Modern C++ Assignment 6 Answers
More Solutions of Programming in Modern C++: Click Here
More NPTEL Solutions: https://progiez.com/nptel/
More from PROGIEZ
