An Introduction To Programming Through C++ Assignment 2 Answers

An Introduction To Programming Through C++ Assignment 2 Answers 2022:-In This article, we have provided the answers of An Introduction To Programming Through C++ Assignment 2 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 4NA
Assignment 5NA
Assignment 6NA
Assignment 7NA
Assignment 8NA
Assignment 9NA
Assignment 10NA
Assignment 11NA
Assignment 12NA

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

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

*

**

***

****

.

.

.

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

Given is an incomplete code for it.

<!-- wp:paragraph -->
<p>int N;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>cin&gt;&gt;N;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>int num=blank1;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>repeat(blank2){</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;&nbsp;&nbsp; num=num+1;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;&nbsp;&nbsp; repeat(blank3){</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;&nbsp;&nbsp; &nbsp; ​​cout&lt;&lt;"*";</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>}</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>cout&lt;&lt;endl;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>}</p>
<!-- /wp:paragraph -->

Q1. What should come in blank 1?

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

Answer:- A) 0 

Q2. What should come in blank 2? 

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

Answer:- (B) N

Q3. What should come in blank 3? 

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

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:- (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:- (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:- (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:- (C) char 

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

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

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:- (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:- (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:- (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:- (A) “sum” variable defined inside the repeat block shadows the “sum” variable that is printed.

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