**NPTEL An Introduction To Programming Through C++ Assignment 2 Answers 2022 :- **Here All The Questions and Answers Provided to Help All The Students and NPTEL Candidate as a Reference Purpose, It is Mandetory to Submit Your Weekly Assignment By Your Own Understand Level.

Are you looking for the Assignment Answers to **NPTEL An Introduction To Programming Through C++ Assignment 2 Answers 2022? **If Yes You are in Our Great Place to Getting Your Solution, This Post Should be help you with the Assignment answer to the **Nation**** al Programme on Technology Enhanced LearningÂ (NPTEL)** Course “

**NPTEL An Introduction To Programming Through C++Â Week 2Â**

**Solution 2022**”

Table of Contents

## An Introduction To Programming Through C++

*From My Side : This course provides an start to problem solving and programming using the C++ programming language. The topics tallying together occurring:
Basic programming notions. Control flow, variables and assignments statements, conditional be swift, looping, action calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.
Program design. How human beings solve problems manually. Strategies for translating calendar strategies to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants.
Programming applications. Arithmetic going a propos for polynomials, matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary buoyancy. A rudimentary graphics system will be discussed.
Standard Library of C++. The string, vector and map classes.
C++ is an slant-oriented programming language which gives a sure structure to programs and allows code to be reused, lowering fee costs
*

**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.

**INTENDED AUDIENCEÂ : BE/BTechÂ in all disciplines BCA/MCA/M. Sc**

**INDUSTRY SUPPORTÂ Â : All IT Industries**

**CRITERIA TO GET A CERTIFICATE**

This course can have Associate in Nursing unproctored programming communication conjointly excluding the Proctored communication, please check announcement section for date and time. The programming communication can have a weightage of twenty fifth towards the ultimate score.

- Assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
**( All assignments in a particular week will be counted towards final scoring – quizzes and programming assignments).Â**- Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam – out of 100
- Proctored Exam score =50% of the proctored certification exam score out of 100

**YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF ASSIGNMENT SCORE >=10/25 AND**

**UNPROCTORED PROGRAMMING EXAM SCORE >=10/25 AND PROCTORED EXAM SCORE >= 20/50.Â**

**If any one of the 3 criteria is not met, you will not be eligible for the certificate even if the Final score >= 40/100.Â**

**CHECK HERE OTHERS NPTEL ASSIGNMENTS ANSWERSÂ **

*BELOW YOU CAN GET YOUR NPTEL An Introduction To Programming Through C++ Assignment 2 Answers 2022***?** :

**?**:

## NPTEL An Introduction To Programming Through C++ Assignment 2 Answers 2022

We want to print the following pattern up to N lines :

*

**

***

****

.

.

**********(N times)

Given is an incomplete code for it.

int N;

cin>>N;

int num=blank1;

repeat(blank2){

num=num+1;

repeat(blank3){

â€‹â€‹cout<<â€ś*â€ť;

}

cout<<endl;

}

Q1. What should come in blank 1?

a) 0

b) 1

c) N

d) (N*(N+1))/2

Answer By SciShowEngineer

Answer: a) 0

Q2. What should come in blank 2?

a) num

b) N

c) N + num

d) (N*(N+1))/2

Answer By SciShowEngineer

Answer: b) N

Q3. What should come in blank 3?

a) num

b) N

c) N + num

d) (N*(N+1))/2

Answer By SciShowEngineer

Answer: a) num

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

OPTIONS =

a) initCanvas(â€świn1â€ť,1000,1000);

Turtle t1;

repeat(4){

t1.forward(100);

t1.right(90);

}

b) initCanvas(â€świn1â€ť,1000,1000);

Turtle t1,t2;

t2.right(90);

repeat(2){

t1.forward(100);

t2.forward(50);

t1.right(90);

t2.forward(50);

t2.left(90);

}

c) initCanvas(â€świn1â€ť,1000,1000);

Rectangle r1(500,500,100,100);

d) initCanvas(â€świn1â€ť,1000,1000);

Rectangle r1(550,550,100,100);

Answer By SciShowEngineer

Answer: c)

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 By SciShowEngineer

Answer: c) 23.6

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 By SciShowEngineer

Answer: a) 23

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 By SciShowEngineer

Answer: c) char

Q8. Which of the following is a correct identifier?

OPTIONS =

a) hello-world

b) char

c) 7wonders

d) first_var

Answer By SciShowEngineer

Answer: d) first_var

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

OPTIONS =

a) myname

b) my-name

c) my00name

d) my_name

Answer By SciShowEngineer

Answer: b) my-name

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 By SciShowEngineer

Answer: a), c), d)

Q11. What does the following code snippet calculate?

int n; cin>>n;

int sum = 0;

int term = 1;

repeat(n){

sum+=term;

term+=2;

}

cout<<sum;

OPTIONS=

a) N(N+1)/2

b) 2N-1

c) (N-1)*(N-1)

d) N*N

Answer By SciShowEngineer

Answer: d) N*N

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

int n; cin>>n;

int sum = 0, term = 1;

repeat(n){

int sum = 0;

sum+=term;

term++;

}

cout << sum;

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 By SciShowEngineer

Answer: a) â€śsumâ€ť variable defined inside the repeat block shadows the â€śsumâ€ť variable that is printed.

## NPTEL An Introduction To Programming Through C++ Programming Assignment 2 Answers 2022

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.

For example, the sum of the numbers 12945 and 89597 is 102542. Then the first input will be 5, the number of digits in A,B. Then the least significant digits will be given, 5 and 7. Then next least significant, 4, 9 and so on. This example is shown in full in the third Sample Test Case below.

Note: Please do not include the header files. Start writing your code from main_program. Input

### First line contains an integer ###

N- the number of digits in the numbers

0<N<100

### Followed by N lines ###

A1 B1

A2 B2

.

.

AN BN

Ai is the ith least significant digit of the number A.

Bi is the ith least significant digit of the number B.

0<= Ai , Bi <=9

Output

The output should be N+1 digits of the sum A+B starting from the least significant. The (N+1)th digit can be 0 in case there is no carry. Note that each digit must appear in a new line.

If S=A+B, the output should be

S1

S2

.

.

SN

SN+1Where Si is the ith least significant digit of the sum S.

CODE:

int main() {

int N, i, A, B;

int C = 0, D, S;

cin >> N;

repeat(N)

{

cin >> A >> B;

S = A + B + C;

if(S > 9) {

D = S % 10;

C = S / 10;

}

else {

D = S;

C = 0;

}

cout << D << endl;

}

cout << C << endl;

}

Programming Assignment 2.2

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.

Note: Please do not include the header files. Start writing your code from main_program.

Input

### First line contains an integer ###

N- the number of items

0<N<20

### Followed by N lines ###

c1 q1

c2 q2

.

.

cN qN

ci is the unit cost of the ith item

qi is the qty purchased of the ith item

0<= ci , qi <=100

Output

An integer denoting the total amount spent on purchasing the items.

CODE:

int main() {

int n, c, q;

int sum = 0;

cin >> n;

repeat(n) {

cin >> c >> q;

sum += c * q;

}

cout << sum << endl;

}

Yhaa You have done it but next? if YOU Want to your Others * NPTEL An Introduction To Programming Through C++ Assignments Answers* Then

**Follow US HERE**and Join Telegram.