Programming in Modern C++ | Week 5
Course Name: Programming in Modern C++
Course Link: Click Here
These are Nptel Programming in Modern C++ Assignment 5 Answers
Quiz
Q1. Consider the following code segment.
What will be the output /error?
a) 6.75
b) 0
c) 675
d) Compilation error: no matching function for call to ’FDInterest::calculate()’
Answer: d) Compilation error: no matching function for call to ’FDInterest::calculate()’
Q2. Consider the following code segment.
What will be the output?
a) C Programming
C++ Programming
b) C++ Programming
C Programming
c) C Programming
C Programming
d) C++ Programming
C++ Programming
Answer: c) C Programming
C Programming
These are Nptel Programming in Modern C++ Assignment 5 Answers
Q3. Consider the following code segment.
What will be the output?
a) 1 2 3 -3 -2 -1
b) 1 1 2 3 -3 -1 -1
c) 1 3 -3 -1
d) 1 1 2 3 -3 -2 -1 -1
Answer: d) 1 1 2 3 -3 -2 -1 -1
Q4. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print Base.
a) Base::print();
b) Base.print();
c) (new Base)->print();
d) Base->print();
Answer: a, c
These are Nptel Programming in Modern C++ Assignment 5 Answers
Q5. Consider the following code segment.
What will be the output /error?
a) 5 10
b) 0 10
c) Compilation error generated from LINE-1
d) Compilation error generated from LINE-2
Answer: d) Compilation error generated from LINE-2
Q6. Consider the following code segment.
What will be the output?
a) A::2 B::2 C::2 A::3 B::3 C::3 A::1 B::1 C::1 ~C ~B ~A ~C ~B ~A ~C ~B ~A
b) A::2 B::2 C::2 A::3 B::3 C::3 ~C ~B ~A A::1 B::1 C::1 ~C ~B ~A ~C ~B ~A
c) C::2 B::2 A::2 C::3 B::3 A::3 C::1 B::1 A::1 ~C ~B ~A ~A ~B ~A ~C ~B ~A
d) C::2 B::2 A::2 C::3 B::3 A::3 C::1 B::1 A::1 ~A ~B ~C ~A ~B ~C ~A ~B ~C
Answer: b) A::2 B::2 C::2 A::3 B::3 C::3 ~C ~B ~A A::1 B::1 C::1 ~C ~B ~A ~C ~B ~A
These are Nptel Programming in Modern C++ Assignment 5 Answers
Q7. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print Base::£().
a) Base.obj.f()
b) Base.obj::f()
c) obj.Base::f()
d) Base::0bj.f()
Answer: c) obj.Base::f()
Q8. Consider the following code segment.
What will be the output /error?
a) Partha CSE
b) unknown CSE
c) Compilation error at LINE-1: void ’Staff::print1()’ is inaccessible in this context
d) Compilation error at LINE-2: void ’Staff::print2()’ is inaccessible in this context
Answer: c) Compilation error at LINE-1: void ’Staff::print1()’ is inaccessible in this context
These are Nptel Programming in Modern C++ Assignment 5 Answers
Q9. Consider the following code segment.
Fill in the blank at LINE-1 such that the program will print 10 20.
a) A2(_t1, _t2)
b) A2(_t2, _t1)
c) AL(_t1), A2(_t2)
d) A2(_t1), A2(_t1, _t2)
Answer: a) A2(_t1, _t2)
Programming Assignment of Programming in Modern C++
Question 1
Complete the program with the following instructions.
• Fill in the blank at LINE-1 with appropriate initializer list,
• Fill in the blanks at LINE-2 and LINE-3 to complete the return statements.
The program must satisfy the given test cases.
Solution:
class Sphere:public Volume,public Area{
public:
Sphere(int _r):Volume(_r), Area(_r){}
double getVolume(){
return Volume::getVal();
}
double getArea(){
return Area::getVal();
}
};
These are Nptel Programming in Modern C++ Assignment 5 Answers
Question 2
Consider the following program with the following instructions.
• Fill in the blank at LINE-1 with appropriate keyword.
• Fill in the blanks at LINE-2 and LINE-3 to complete the constructor statements.
The program must satisfy the sample input and output.
Solution:
#include <iostream>
using namespace std;
class Vehicle
{
public:
string vehicleName;
int noOfWheels;
Vehicle(string s,int w):vehicleName(s),noOfWheels(w)
{}
void vehicleDetails(const Vehicle&);
};
class Twowheeler:public Vehicle
{
public:
Twowheeler(string n):Vehicle(n,2)
{}
};
class Fourwheeler:public Vehicle
{
public:
Fourwheeler(string n):Vehicle(n, 4)
{}
};
These are Nptel Programming in Modern C++ Assignment 5 Answers
Question 3
Consider the following program. Fill in the blanks as per the instructions given below:
• Fill in the blank at LINE-1 to complete the inheritance statement.
• Fill in the blank at LINE-2 with the appropriate initializer list,
The program must satisfy the given test cases.
Solution:
class ReTest:public Test1,public Test2
{
int t;
public:
ReTest(int x):Test1(x+5),Test2(x+10),t(x)
{}
void show()
{
cout << t << ", " << t1 << ", " << t2;
}
};
These are Nptel Programming in Modern C++ Assignment 5 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 5 Answers
More Solutions of Programming in Modern C++: Click Here
More NPTEL Solutions: https://progiez.com/nptel/
More from PROGIEZ
