An Introduction To Programming Through C++ Assignment 6 Answers

NPTEL An Introduction To Programming Through C++ Assignment 6 Answers 2022:-In This article, we have provided the answers of An Introduction To Programming Through C++ Assignment 6. 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.

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 8NA
Assignment 9NA
Assignment 10NA
Assignment 11NA
Assignment 12NA

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

Q1. What is V(6), the number of poetic meters of total duration 6?

Answer: 13

Suppose I have a supply of red blocks (R) all of height 1 and blue blocks (B) all of height 3. I can stack the blocks one above the other to build a tower. For example, if I stack in the order RBR or BRR from bottom to top I will get towers of height 5. Let T(n) denote the number of towers possible of height n. Clearly T(1) is 1 because the only order possible is R.T(2) is 1 because the only possible order is RR.T(3) is 2, because the possible orders are RRR or B.
BR RB RRRR

Q2. What is T(4)?

Answer: 3

Q3. What is T(5)?

Answer: 4

Q4. Using the same logic as in the lecture, you could say that the bottom most block can either be red or it can be blue. Following this logic, what is T(n) equal to?

a) T(n-1) + T(n-2)
b) T(n-1) + T(n-2) + T(n-3)
c) T(n-1) + T(n-3)
d) T(n-2) + T(n-3)

Answer: c) T(n-1) + T(n-3)

Q5. What does the call f(100) return, if f is defined as follows?Int f(n){
if (n == 0) return 0;
else return f(n1) + 2;
}

Answer: 200

Q6. I will get an error if I execute s++ f1.cpp

a) True
b) False

Answer: a) True

Q7. I will get an error if I execute s++ -c f2.cpp

a) True
b) False

Answer: b) False

Q8. I will get an error if I execute s++ f1.cpp f3.cpp

a) True
b) False

Answer: a) True

Q9. What is the result of executing the following program, if the input given is 3? #include <simplecpp> #include <functional> double ssum(function<double(int)> f, int n){     double sum = 0;     for(int i=0; i<n; i++) sum = sum + f(i);     return sum; } int main(){     int n; cin >> n;     cout << ssum([](int i){return i*i;}, n)<<endl; }

Answer: 5

Consider the following program. #include <simplecpp> int f(int a, int b, int c=10, int d=20){return a+b+c+d;} int main(){         cout<<f(5,6,7,8)<<‘,'<<f(5,6,7)<<‘,'<<f(5,6); }

Q10. What is the first number printed?

Answer: 26

Q11. What is the second number printed?

Answer: 38

Q12. What is the third number printed?

Answer: 41

Programming Assignment

Q1. Suppose there are two types of blocks: Red blocks (R) of height 1 and Blue blocks (B) of height 4. These blocks can be stacked one above the other to build a tower. You have to write a program that counts the number of distinct towers of a given height n that can be built using these 2 types of blocks.
Note: 2 towers of the same height are called distinct if the order in which R and B blocks occur in them is different.

Write a recursive program that takes n and returns the number of distinct towers of height n.

Code:-

long int tower_count (int x) {
  
  if(x <= 3)
    return 1;
  return tower_count(x-4) + tower_count(x-1);
}

main_program {
  
  int n;
  cin >> n;
  cout << tower_count(n) << endl;
}

Q2. Given below is a main program with calls to a function inches. Given a distance measured in yards, feet and inches, the function is supposed toreturn the equivalent number of inches. In particular, given y, f, i as the values of the parameters yards, feet, inches, the function should returny*36+f*12+i. However, it is acceptable to call the function with just two arguments y, f, in which case they should be interpreted as yards and feet,and the value returned should be y*36+f*12. The function might also be called with a single argument y, in which case it should return y*36. Youhave to write the code for the function inches. Your code may implement inches using default values for the parameters or by overloading it. Youdo not need to give the main program. It will be added automatically. The main program is given below for your reference.
Note: You don’t need to write/copy the main program. You just need to write the inches function, without the main_program or any of theheader files. Ensure that the function is correctly named as inches.

main_program{
int y,f,i; cin >> y >> f >> i;
cout << inches(y,f,i) <<“,”<<inches(y,f) <<“,”<<inches(y) << endl;
}

Code:-

int inches(int y, int f = 0, int i = 0) {
  
  int inch;
  inch = y * 36 + f * 12 + i;
  return inch;
}

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

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

Leave a Comment