Programming in Modern C++ Week 5 Assignment Answers
Are you looking for the NPTEL Programming in Modern C++ Week 5 Assignment Answers? You’ve come to the right place! This resource provides comprehensive solutions to all the questions from the Week 5 assignment, helping you navigate through the complexities of modern C++ programming.
Course Link: Click Here
Table of Contents
Programming in Modern C++ Week 5 Assignment Answers (July-Dec 2024)
Q1.Consider the following code segment.
What will be the output?
a)1, 2,3
b) 1, 2, 3-3, 1, 2, 3-3,
c) 1,2, 3-3, 4, 5, 6-6,
d) 1-1, 2, 3, 4-4, 5, 6,
Answer: d) 1-1, 2, 3, 4-4, 5, 6,
Q2 Consider the following code segment.
What will be the output?
a) AB C- C -B -A
b)A A B C -C A -A
c) A C -C -A
d) A A B C -C -B- A- A
Answer: d) A A B C -C -B- A- A
For answers or latest updates join our telegram channel: Click here to join
Q3.Consider the following code segment.
What will be the output?
a) Vehicle created, Car created, Vehicle created, Bike created, SportsCar created, SportsCar destroyed, Bike destroyed, Vehicle destroyed, Car destroyed, Vehicle
destroyed,
b) Vehicle created, Car created, SportsCar created, Vehicle created, Bike created, Bike destroyed, Vehicle destroyed, SportsCar destroyed, Car destroyed, Vehicle
destroyed,
c) Vehicle created, Car created, SportsCar created, Bike created, Bike destroyed, SportsCar destroyed, Car destroyed, Vehicle destroyed,
d) Vehicle created, Car created, Sports Car created, Bike created, Vehicle destroyed, Car destroyed, Sports Car destroyed, Bike destroyed,
Answer: a) Vehicle created, Car created, Vehicle created, Bike created, SportsCar created, SportsCar destroyed, Bike destroyed, Vehicle destroyed, Car destroyed, Vehicle
destroyed,
Q4.Consider the following code segment.
Choose the appropriate option to fill in the blank at LINE-1 such that the output of the code becomes Instrument: :play().
a) g.play()
b) Instrument: :play()
¢) g.Instrument: :play()
d) Instrument::g.play()
Answer: ¢) g.Instrument: :play()
For answers or latest updates join our telegram channel: Click here to join
Q5.Consider the following code segment.
Choose the appropriate option(s) to fill in the blank at LINE-1 such that the output becomes |
25 15 5
a) this->value << ” ” << Parent::value << ” ” << value |
b) Child::value << ” ” << Parent::value << ” ” << value |
c) value << ” ” << Parent::value << ” ” << ::value |
d) Child: :value << ” ” << Parent::value << ” ” << ::value |
Answer: c) value << ” ” << Parent::value << ” ” << ::value |
d) Child: :value << ” ” << Parent::value << ” ” << ::value |
Q6. Consider the following code segment.
a) memberVar = 6, globalVar = 7
memberVar = 1, globalVar = 8
b) memberVar = 6, globalVar = 8
memberVar = 1, globalVar = 0
c) memberVar = 1, globalVar = 7
memberVar = 2, globalVar = 8
d) memberVar = 1, globalVar = 7
memberVar = 1, globalVar = 0
Answer: d) memberVar = 1, globalVar = 7
memberVar = 1, globalVar = 0
For answers or latest updates join our telegram channel: Click here to join
Q7. Consider the following code segment.
‘What will be the output /error?
a) 12345:Sedan:
b) 12346:Sedan:101
c) compiler error at LINE-1: Vehicle is an inaccessible base of Car
d) compiler error at LINE-2: ‘display’ was not declared in this scope
Answer: d) compiler error at LINE-2: ‘display’ was not declared in this scope
Q8. Consider the following code segment.
‘What will be the output /error?
a) 40 30
b) 40 40
c) Compiler error: ’Basek operator=(const Basek)’ is private
d) Compiler error: ’Base(const Basek obj)’ is private
Answer: c) Compiler error: ’Basek operator=(const Basek)’ is private
For answers or latest updates join our telegram channel: Click here to join
Q9.Consider the following code segment.
What will be the output /error(s)?
a) 10 20 30
b) compiler error at LINE-1: X::x is not accessible
c) compiler error at LINE-2: X::x is not accessible
d) compiler error at LINE-3: Y::y is not accessible
Answer: c) compiler error at LINE-2: X::x is not accessible
For answers or latest updates join our telegram channel: Click here to join
For answers to additional Nptel courses, please refer to this link: NPTEL Assignment
Programming in Modern C++ Week 5 Assignment Answers (JAN-APR 2024)
Course Name: Programming in Modern C++
Course Link: Click Here
For answers or latest updates join our telegram channel: Click here to join
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 ‘Derived::calculate()’
Answer: d) Compilation error: no matching function for call to ‘Derived::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
Q3. Consider the following code segment.
What will be the output?
a) 1 2 3 -3 -2 -1
b) 1 2 1 2 3 -3 -2 -1 -2 -1
c) 1 3 -3 -1
d) 1 1 2 3 -3 -2 -1 -1
Answer: b) 1 2 1 2 3 -3 -2 -1 -2 -1
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 5 Answers
Q4. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print Father.
a) Father::print();
b) Father.print();
c) (new Father)->print();
d) Father->print();
Answer: a), c)
Q5. Consider the following code segment.
Fill in the blank at LINE-1 so that the output is 1.
a) obj.Base->f ()
b) obj. Base::f()
c) obj.Base.f()
d) Base : : f()
Answer: b) obj. Base::f()
Q6. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print 30 20 10.
a) Class2::x << ” ” << Class1 : : x << ” ” << x
b) Class2::x << ” ” << Class1 : : x << ” ” << : : x
c) x << ” ” << Class1 : : x << ” ” << : : x
d) : : x << ” ” << Class1 : : x << ” ” << : : x
Answer: b), c)
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 5 Answers
Q7. Consider the following code segment.
Fill in the blank at LINE-1 so that the program will print 23.
a) Print (_x), y(_y)
b) Print (_y), y(_x)
c) y(_y), Print (_x)
d) y(_x), Print (_y)
Answer: a), c)
Q8. Consider the following code segment.
What will be the output /error?
a) 1 2
b) 1 3
c) 1 1
d) Compilation error: int A::x is inaccessible
Answer: d) Compilation error: int A::x is inaccessible
Q9. Consider the following code segment.
Fill in the blank at LINE-1 such that the program will run successfully without any error.
a) private
b) protected
c) public
d) friend
Answer: c) public
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 5 Answers
Programming Assignment
Question 1
Complete the program with the following instructions.
• Fill in the blank at LINE-1 with appropriate inheritance statement,
• Fill in the blanks at LINE-2 appropriate initializer list,
The program must satisfy the given test cases.
Solution:
class DD : public B, public D {
int d;
public:
DD(int x) : B(x * 2), D(x * 3), d(x * 1) {}
void show() {
cout << d << ", " << b1 << ", " << b2;
}
};
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 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 Student{
string n;
string s;
int m;
protected:
Student(string _n, string _s, int _m) : n(_n), s(_s), m(_m) {}
public:
friend void studDetails(const Student&);
};
class Bengali : public Student{
public:
Bengali(string n, int m) : Student(n, "Bengali", m){}
};
class English : public Student{
public:
English(string n, int m) : Student(n, "English", m){}
};
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 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 with appropriate return statement,
• Fill in the blank at LINE-2 with appropriate return statement,
The program must satisfy the given test cases.
Solution:
class Sphere : public Area, public Volume{
int r;
public:
Sphere(int _r) : r(_r){ }
double getArea(){ return Area::getVal(r); }
double getPerimeter(){ return Volume::getVal(r); }
};
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 5 Answers
More Weeks of Programming in Modern C++: Click here
More Nptel Courses: Click here
Programming in Modern C++ Week 5 Assignment Answers (JULY-DEC 2023)
Course Name: Programming in Modern C++
Course Link: Click Here
These are Programming in Modern C++ Week 5 Answers
Programming Assignment
Question 1
Consider the following program. Fill in the blanks as per the instructions given below:
• Complete the variable declaration at LINE-1,
• Complete the function prototype at LINE-2 and LINE-3 with appropriate keywords
such that it will satisfy the given test cases.
Solution:
class Cube : public Volume, public SurfaceArea { //LINE-1
int _a;
public:
Cube(int a) : _a(a) { }
double getVolume() { return Volume::getValue(_a); } //LINE-2
double getSurfaceArea() { return SurfaceArea::getValue(_a); } //LINE-3
};
These are Programming in Modern C++ Week 5 Answers
Question 2
Consider the following program. Fill in the blanks as per the instructions given below.
• at LINE-1 with appropriate forward declaration,
• at LINE-2 with appropriate statement
such that it will satisfy the given test cases
Solution:
#include <iostream>
using namespace std;
class Vehicle{
string vehicleName;
int noOfWheels;
protected:
Vehicle(string s, int w) : vehicleName(s), noOfWheels(w) { }
public:
friend 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 Programming in Modern C++ Week 5 Answers
Question 3
Consider the following program. Fill in the blanks at LINE-1, LINE-2 and LINE-3 with appropriate statements such that it will satisfy the given test cases.
Solution:
class D : public B1, public B2 {
int d;
public:
D(int x) : B1(x+5), B2(x+10), d(x) {}
These are Programming in Modern C++ Week 5 Answers
More Weeks of Programming in Modern C++: Click here
More Nptel Courses: Click here
Session: JULY-DEC 2022
Course Name: Programming in Modern C++
Course Link: Click Here
These are Nptel Programming in Modern C++ Week 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++ Week 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++ Week 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++ Week 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++ Week 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
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++ Week 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++ Week 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++ Week 5 Answers