NPTEL An Introduction to Programming Through C++ Assignment 2 Answers 2022

NPTEL An Introduction to Programming Through C++ Assignment 2

Are you looking for the Answers to NPTEL An Introduction to Programming Through C++ Assignment 2? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course “ NPTEL An Introduction to Programming Through C++ Assignment 2

Join Our Official Telegram Channel

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.

Below you can find the answers for NPTEL An Introduction to Programming Through C++ Assignment 2

Assignment No.Answers
An Intro to Programming C++ Assignment 1 Click Here
An Intro to Programming C++ Assignment 2 Click Here
An Intro to Programming C++ Assignment 3 Click Here
An Intro to Programming C++ Assignment 4 Click Here
An Intro to Programming C++ Assignment 5 Click Here
An Intro to Programming C++ Assignment 6 Click Here
An Intro to Programming C++ Assignment 7 Click Here
An Intro to Programming C++ Assignment 8 Click Here

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

Q1. What should come in blank 1?

A) 0 
(B) 1 
(C) N 
(D) (N*(N+1))/2

Answer:- a

Q2. What should come in blank 2? 

(A) num 
(B) N
(C) N+num
(D) (N*(N+1))/2

Answer:- b

Q3. What should come in blank 3? 

(A) num 
(B) N 
(C) N+num 
(D) (N*(N+1))/2

Answer:- a

Q4. Which of the following creates a picture different from others (ignore the final position/orientation of the turtles)?

Answer:- d

???? Next Week Answers: Assignment 03 ????

quizxp telegram

Q5. What is the correct(closest) output of the following code snippet?

int a = 360;
cout << a/100.0+20;

OPTIONS=

(A) 23 
(B) 3 
(C) 23.6 
(D) 0

Answer:- c

Q6. What is the correct(closest) output of the following code snippet?

int a = 360;
cout << a/100+20.0;

OPTIONS=

(A) 23 
(B) 3 
(C) 23.6 
(D) 24

Answer:- a

Q7. Which of the following data types usually has the lowest number of bits allocated?
OPTIONS=  

(A) int 
(B) float 
(C) char 
(D) unsigned int

Answer:- c

Q8. Which of the following is a correct identifier?
OPTIONS=  

(A) hello-world 
(B) char 
(C) 7wonders 
(D) first_var

Answer:- d

Q9. Which of the following is NOT a valid identifier?
OPTIONS=  

(A) myname 
(B) my-name 
(C) my00name 
(D) my_name

Answer:- c

Q10. Which of the following are valid expressions for C++ ? OPTIONS=  

(A) 1 
(B) 2(a + b) 
(C) a+1 / b + 10 
(D) c % 10 / 2

Answer:- a,c,d

Q11. What does the following code snippet calculate?

(A) N(N+1)/2 
(B) 2N-1 
(C) (N-1)*(N-1) 
(D) N*N

Answer:- d

Q12. The following code snippet is supposed to print the sum of first N natural numbers but it doesn’t. Why is it so?

OPTIONS=

(A) “sum” variable defined inside the repeat block shadows the “sum” variable that is printed.
(B) term variable is not updated correctly.
(C) sum variable outside the repeat block is not initialised correctly.
(D) repeat block is executing for more than n times.

Answer:- a

Programming Assignment

Q1. Write a program that given the digits of two numbers A and B prints out the digits of the sum.    The first input is N, the number of digits in A as well as B.  After this,

the digits of A and B will be given one by one from least significant to the most significant.  Your program should print the ith digit of the sum before reading the (i+1)th digit of A and B. You should print N+1 digits for the sum, where the most significant digit can be 0. The length N of the numbers can be large, so in general it won’t be possible to store A or B in the “int” or “long long” data type.  Your program should mimic the manual addition process you learned in primary school, i.e. add digits consecutively together with the carry if any, with initially there being no carry.  Note that if a computer has to do arithmetic on numbers with hundreds of digits, it will be done in the manner of your program.

Code:-

int main()
{
int N,i,A,B,C=0,D, sum; 
  cin>>N;
  repeat (N)
  {  

cin>>A>>B;
    sum=A+B+C;
    if(sum>9)
    {
      D=sum%10; 
      C=sum/10;
    }
else
{

D=sum;
  C=0;
}
cout <<D<<endl;
  }
cout<<C<<endl;

}

Q2. We buy different quantities of N different items.  You are to write a program that

given the unit cost of each item and the quantity of the item purchased, prints the total amount spent in purchasing all the items. It is guaranteed that all the costs, qty and the total amount can fit into the “int” data type, so use it throughout your program.

Code:-

int main()

{

int N,c,q, sum=0; 
  cin>>N; 
repeat (N)
{

cin>>c>>q;
    sum=sum+c*q;

}
  cout<<sum<<endl;
  
}

For other courses answers:- Visit

For Internship and job updates:- Visit

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.