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

Assignment 2 | Click Here |

Assignment 3 | Click Here |

Assignment 4 | NA |

Assignment 5 | NA |

Assignment 6 | NA |

Assignment 7 | NA |

Assignment 8 | NA |

Assignment 9 | NA |

Assignment 10 | NA |

Assignment 11 | NA |

Assignment 12 | NA |

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

**Q1. What is the value of variable count at the end of execution?**

A certain government levies taxes on a person’s total annual income. The taxes are calculated in the given manner. If a person earns an amount of less than or equal to Rs. 1,00,000 annually, the person doesn’t pay any tax.

If a person earns an amount of more than Rs. 1,00,000 and less than or equal to Rs. 5,00,000, then the person is charged 5% on the amount.

If a person earns an amount of more than Rs. 5,00,000, the person is charged with 5% of Rs. 5,00,000 and 10% of the remaining amount.

The following code snippet computes the total tax to be paid by a person given their annual income. You are to fill in the blanks so that the code computes the tax correctly.

**Answer:-** **39**

**👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇**

**Q2. What should be filled in blank1?**

a) 0

b) 100000

c) 500000

d) 1000000

**Answer:-** **b**

**Q3. What should be filled in blank2?**

a) 0

b) 100000

c) 500000

d) 1000000

**Answer:-** **c**

**Q4. What should be filled in blank3?**

a) 0

b) 0.05

c) 0.1

d) 0.5

**Answer:-** **b**

**Q5. What should be filled in blank4?**

a) income

b) income-100000

c) income-500000

d) Income+100000

**Answer:-** **c**

Given below is a program fragment that is meant to calculate the average of all odd numbers given in the input. You are to fill in the blanks so that the code computes the average correctly.

```
int sum=0;
int count=0;
for(int i=0; i<n; i++){
int num;
cin>>num;
if(num%2==0){
blank5;
}
blank6;
blank7;
}
cout<<sum/count<<endl;
```

**Q6.** What should be filled in blank5?

a) break

b) continue

c) sum+=num

d) return 0

**Answer:-** **b**

**Q7.** What should be filled in blank6?

a) continue

b) break

c) sum+=num

d) sum*=num

**Answer:-** **c**

**Q8.** What should be filled in blank7?

a) count+=1

b) count-=1

c) count+=num

d) count+=2

**Answer:-** **a**

The program given below is meant to read an unending sequence of non-negative numbers. This sequence may increase and decrease several times. We are interested in the last increasing portion, particularly its length. So having read a number, the program prints out the length of the last increasing portion. Suppose the sequence is 1, 4, 6, 2, 5, … Then having read 1, 4, 6 the program will print 3, because at this point the entire sequence forms the increasing portion.

On the other hand, having read 1, 4, 6, 2, 5 the program should print 2 because the last increasing portion is 2, 5, of length 2. You can see that the program will have to print out 1, 2, 3, 1, 2 and so on if the input was 1, 4, 6, 2, 5, …. You are to answer the questions below in order to fill in the blanks so that the program does its job.

**Q9.** What should be filled in blank8?

a) lastSeqLength=0

b) lastSeqLength=1

c) lastSeqLength+=1

d) lastSeqLength-=1

**Answer:-** **c**

**Q10.** What should be filled in blank9?

a) lastSeqLength=1

b) lastSeqLength=0

c)lastSeqLength+=1

d) lastSeqLength-=1

**Answer:-** **a**

## An Introduction to Programming Through C++ Programming Assignment Week 3

**Q1. You are currently at the origin (0, 0) and will be given commands to either go Right (R), Left (L), Up (U) or Down (D) by a certain number of steps. At the end of all these commands, you will be signaled to stop by reading the character ‘E’, after which you need to output your position in the x-y plane. The four kinds of movements are the following (direction followed by number of steps in that direction):**

**Code:-**

```
int main()
{
int x =0,y=0, nos;
char ch;
cin>>ch>>nos;
while(ch!= 'E')
{
switch(ch)
{
case 'R':
x=x+nos;
break;
case 'L':
x=x-nos;
break;
case 'U':
y=y+nos;
break;
case 'D':
y=y-nos;
break;
default :
break;
}
cin>>ch>>nos;
}
cout<<x<<" "<<y<<endl;
}
```

**👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇**

**Q2. Write a program to find the sum of the digits of a given integer N.**

Solving this problem is easy manually if the number is given to you on paper: you simply see the digits written down and you can add them up. A computer program does not “see” the digits. However, you can get the least significant digit by taking the remainder modulo 10, using the % operator. You can determine the number resulting from erasing the least significant digit of an integer x by dividing x by 10. As you know x/10 will equal the quotient, which is exactly what remains if you erase the last digit of x. If you now take the remainder of this modulo 10 you will get the second least significant digit. Thus by alternately taking the remainder modulo 10 and dividing by 10 you will be able to obtain the different digits. So then you can add them up. All that remains is to put this into a nice loop.

**Code:-**

```
main_program
{
int N, sum=0;
cin>>N;
while(N>0)
{
sum=sum+N%10;
N=N/10;
}
cout<<sum<<endl;
}
```

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

## 5 thoughts on “An Introduction To Programming Through C++ Assignment 3 Answers”