# An Introduction To Programming Through C++ Assignment 10 Answers

NPTEL An Introduction To Programming Through C++ Assignment 10 Answers 2022:-In This article, we have provided the answers of An Introduction To Programming Through C++ Assignment 10. You must submit your assignment to your own knowledge.

## What is An Introduction to Programming Through C++?

This course provides an introduction to problem-solving and programming using the C++ programming language. The topics include:

• Basic programming notions. Control flow, variables and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.
• Program design. How human beings solve problems manually. Strategies for translating manual strategies to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants.
• Programming applications. Arithmetic on polynomials, matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed.
• Standard Library of C++. The string, vector and map classes.

## CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

## NPTEL An Introduction to Programming Through C++ Assignment 10 Answers 2022:-

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

a. int A;
b. int *A = new int;
c. int A = new int;
d. int new A;

Answer:- b. int *A = new int;

Q2. My program contains the line:

delete x;

It does not cause a compile time error. Which of the following is a possibledeclaration for x?

• int x;
• double x;
• double *x;
• int x;

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

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

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

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

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

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

Q7. What is the first number printed?

Q8. What is the second number printed?

Q9. What is the third number printed?

If there are any changes in answers will notify you on telegram so you can get a 100% score, So Join

Q10. Consider the following code fragment (assume appropriate header files have been loaded and using namespace commands issued)

Q11. What should blank2 be?

Q12. What should blank3 be?

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

Q1. Write a program which reads in and executes very simple programs in a very simple programming language which is as follows. The language has 4 statements, with the following formats.

Code:-

``````#include<iostream>
#include<map>
using namespace std;

int main(){
string s;
map<char,int>m;
while(getline(cin,s)){
if(s=='d'){
m[s]=s-'0';
}
else if(s=='p'){
for(auto x:m){
if(x.first==s){
cout<<x.second<<endl;
}
}
}
else if(s=='a'){
auto it1 = m.find(s);
auto it2 = m.find(s);
it2->second += it1->second;
}
else if(s=='e'){
return 0;
}
}
return 0;
}``````

Q2. You are to write a function addM to add together two matrices, which are implemented as vectors of vectors. The matrices will only contain integers. If the matrices to be added are A,B and the sum is C, then we want C[i][j]=A[i][j]+B[i][j] for all i,j.

Code:-

``````vector<vector<int>> addM(const vector<vector<int>>& A, const vector<vector<int>>& B) {
vector<vector<int>> matrix(A);
for (size_t i = 0; i < matrix.size(); i++)
for (size_t j = 0; j < matrix.size(); j++)
matrix[i][j] += B[i][j];
return matrix;
}``````

NPTEL An Introduction To Programming Through C++ Assignment 10 Answers 2022:-In This article, we have provided the answers of An Introduction To Programming Through C++ Assignment 10. You must submit your assignment to your own knowledge.