An Introduction To Programming Through C++ Assignment 12 Answers

NPTEL An Introduction To Programming Through C++ Assignment 12 Answers 2022:-In This article, we have provided the answers to An Introduction To Programming Through C++ Assignment 12. You must submit your assignment with 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.

An Introduction To Programming Through C++Answers
Assignment 1Click Here
Assignment 2Click Here
Assignment 3Click Here
Assignment 4Click Here
Assignment 5Click Here
Assignment 6Click Here
Assignment 7Click Here
Assignment 8Click Here
Assignment 9Click Here
Assignment 10Click Here
Assignment 11Click Here
Assignment 12NA

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

Q1. For answering this question you will need to see the program given in the announcement “The circuit simulator program” made on 2022-03-31. On line number 146, there is a call to a member function addNode. What is the number of the line starting from which this function is defined?

If you look at the program you will see one addNode member function starts on line number 32 and another on line number 91. You have to choose the correct line number out of these two.

Answer:- 91

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

An Introduction To Programming Through C++ Assignment 12 Answers

Q2. For answering this question you will need to see the program given in the announcement “The circuit simulator program” made on 2022-03-31. The program contains a selectNode member function. When this function executes, the computer waits for the user to click. What value will this function return if the user clicks on the third button from the top?

Answer: -1

Q3. What will be the value of A[5][6]?

Answer: -12

Q4. What will be the value of A[5][5]?

Answer: 50

Q5. Consider the definitionmap<string,set<string> > citiesInCountry;

where citiesInCountry maps the country name to its set of cities.

What does citiesInCountry.count(“India”) return?

  • How many cities are there in India, as stored in citiesInCountry. 
  • Whether any cities are stored for India in citiesInCountry, (0: none, 1: some). 
  • This expression is invalid.

Answer: b

👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇

An Introduction To Programming Through C++ Assignment 12 Answers

Q6. The following code is supposed to print the cities in India, as stored incitiesInCountry.
for(auto c : citiesInCountry[“India”]) cout << blank <<‘ ‘;
What should blank be?

Answer:- c

Q7. Suppose fdash is a constant function, i.e. the derivative is the same throughout. Suppose fdash(t) = 3 for all t, t0 = 0, t1= 1, f0=0 and n=4. These parameters are used to call euler1. Select the correct alternative(s) from the following by reasoning out or by manually executing the function. Ignore roundoff errors.

Answer: a, c

Q8. Suppose fdash is a linear function, say fdash(t) = 2t for all t. Suppose t0 = 0, t1= 1, f0=0 and n=4.Select the correct alternative(s) from the following by reasoning out or by manually executing the function. Ignore roundoff errors.

Answer: b, c

Programming Assignment Answers:-

Q1. Given below is the main program in a program to print the past tense of a verb in the English language. If the verb ends in “e”, then it simply adds a “d” and returns the result as the past tense. If the verb ends in any other letter, it adds “ed” and returns the result. However, both these behaviours are superseded if the verb supplied to it is in an exception table that it maintains.

The exception table also holds the past tense of each word in the table, and so that is returned instead. The program can also be told that a certain word x has a certain past tense y. If y can be obtained from x using the basic rules given above, the program does nothing. If y cannot be obtained from x using the basic rules, then x, y are added to the table.

The table is implemented as a map from strings to strings. In addition, the program has a command which causes it to terminate. The main program is given below, and already entered in your submission. You only have to supply the code for the functions it calls. The code will be placed above the main program so that separate declarations are not needed.

Code:-

string pasttense(map<string,string> &m,string &verb)
{
  if(m.find(verb)!=m.end())
    return m[verb];
  char lc=verb[verb.length()-1];
  if(lc=='e')
    return verb+"d";
  return verb+"ed";
}
void add(map<string,string> &m,string &verb,string &pt)
{
  char lc=verb[verb.length()-1];
  string past_tense="";
  if(lc=='e')
    past_tense=verb+"d";
  else past_tense=verb+"ed";
  if(past_tense!=pt)
    m[verb]=pt;
}

Q2. Suppose I have a box which contains some boxes, each of which contain more boxes and so on, for a total of n + 1 boxes. Suppose the boxes are numbered from 0 to n with the outermost box receiving the number 0. Now the configuration can be described by specifying numbers x_1, … , x_n,where x_i denotes the number of the box directly containing box i. For example, the configuration shown below is described by the sequence 0, 3,4, 0

Code:-

int open1box(vector<int> &x, int y) {

 int out = 1;

 while (true) {
  out++;
  int temp = x[y];
  if (temp == 0) break;
  y = temp;
 }
 return out;
}

int open2boxes(vector<int> &x, int y, int z) {

 int len_x = open1box(x, y),dis = 0;
 int len_y = open1box(x, z);
 int a[len_x], b[len_y];

 a[0] = y; b[0] = z;
 for (int i = 1; i < len_x; i++){
  a[i] = x[y];
  y = a[i];
 }

 for (int j = 1; j < len_y; j++) {
  b[j] = x[z];
  z = b[j];
 }

 int arr[len_x+len_y];
 for (int i = 0; i < len_x+len_y; i++) {
  if (i < len_x) arr[i] = a[i];
  else arr[i] = b[i-len_x];
 }

 for (int i = 0; i < len_x+len_y; i++) {
  bool flag = 1;
  for (int j = 0; j < i; j++) {
   if (arr[i] == arr[j]) {flag = 0; break;} 
  }
  if (flag) dis++;
 }
 return dis;

}

Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

Leave a Comment