An Introduction to Programming Through C++ | NPTEL 2022 | Week 10 Answers

This set of MCQ(multiple choice questions) focuses on the An Introduction to Programming Through C++ NPTEL 2022 Week 10 Answers.

Course layout

Answers COMING SOON! Kindly Wait!

NOTE: You can check your answer immediately by clicking show answer button. An Introduction to Programming Through C++ NPTEL 2022 Week 10 Assignment Answers” contains 13 questions.

Now, start attempting the quiz.

An Introduction to Programming Through C++ NPTEL 2022 Week 10 Assignment Answers

Q1. To create an array of integers which can be accessed as A[0],…,A[4] residing on the heap the code to be executed is:

a) int A[5];
b) int *A = new int[5];
c) int A = new int[5];
d) int new A[5];

Answer: b)

Q2. My program contains the line:
delete x;
It does not cause a compile time error. Which of the following is a possible declaration for x?

a) int x;
b) double x;
c) double *x;
d) int x[10];

Answer: c)

Q3. What is a memory leak? Pick the nearest description from those below.

a) The term refers to a pointer which does not point to a valid memory location.
b) The term refers to a location in heap memory which has been allocated but to which your program has no pointer.
c) The term refers to a memory location which is faulty.
d) The term refers to a pointer which points to memory that has been deallocated.

Answer: b)

Q4. What is a dangling pointer? Pick the nearest description from those below.

a) The term refers to a pointer which does not point to a valid memory location.
b) The term refers to a location in heap memory which has been allocated but to which your program has no pointer.
c) The term refers to a memory location which is faulty.
d) The term refers to a pointer which points to memory that has been deallocated.

Answer: d)

Q5. When we created the String class we redefined the = operator because

a) There is no default definition of =, and we wanted to allow assignments of one String to another.
b) There is a default definition of =, and it makes a copy of the pointer but not the characters in the String.
c) There is a default definition of =, but it does not make a copy of the pointer but only copies the characters in the string.
d) Every time we define a class it is compulsory to define the = operator.

Answer: c)

An Introduction to Programming Through C++ NPTEL Week 10 Assignment Answers

Q6. When I define the destructor for a class, under what circumstances should it delete the heap memory that a data member points to?

a) You should always delete.
b) You should delete if you know there is no other pointer in your program pointing to the same memory.
c) You should print a message and ask the user if it is safe to delete the memory.
d) You should never delete, i.e. it is never safe.

Answer: b)

Consider the following code fragment (assume appropriate header files have been loaded and using namespace commands issued)
vector<vector <int>> x(10,vector<int>(9,8));cout << x.size() << x[3].size() << x[5][5] << endl;

Q7. What is the first number printed?

Answer: 10

An Introduction to Programming Through C++ NPTEL Week 10 Assignment Answers

Q8. What is the second number printed?

Answer: 9

Q9. What is the third number printed?

Answer: 8

Q10. Consider the following code fragment (assume appropriate header files have been loaded and using namespace commands issued)
map<string,double> xchgRate = {{“Euro”, 84}, {“Dollar”,75}};
blank1
for(auto c : xchgRate)
cout << blank2 <<“: “<<blank3<<endl;
The first statement creates a map and initializes it to contain the rates for the Dollar and the Euro as 75 and 84 respectively (in terms of rupees).
What should blank1 be if it is meant to create an entry for the Yen, with the rate being 0.64. Give your answer using proper capitalization, no unnecessary blanks. Include semicolons and all other characters as you would have typed instead of “blank1”, and use the minimum characters possible.

Answer: xchgRate[“Yen”]=0.64

An Introduction to Programming Through C++ NPTEL week 10 Assignment Solutions

Q11. What should blank2 be?

Answer: xchgRate->first

Q12. What should blank3 be?

Answer: xchgRate->second

Q13. For which currency is the exchange rate printed first by the third statement?

a) Dollar
b) Euro
c) Yen
d) It is not possible to say

Answer: a)

An Introduction to Programming Through C++ NPTEL Week 10 Programming Assignment Answers

Programming Assignment 10.1

CODE:

Programming Assignment 10.2

CODE:

<< Prev- An Introduction to Programming Through C++ Week 9 Solutions

>> Next- An Introduction to Programming Through C++ Week 11 Solutions


DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

1 thought on “An Introduction to Programming Through C++ | NPTEL 2022 | Week 10 Answers”

Leave a Comment

Your email address will not be published. Required fields are marked *