adplus-dvertising
NPTEL An Introduction To Programming Through C++ Assignment 4 Answers 2022

NPTEL An Introduction To Programming Through C++ Assignment 4 Answers 2022

NPTEL An Introduction To Programming Through C++ Assignment 4 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 4 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 National Programme on Technology Enhanced Learning (NPTEL) Course “NPTEL An Introduction To Programming Through C++ WeekSolution 2022

 

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.

Final score = Assignment score + Unproctored programming exam score + Proctored Exam 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 4 Answers 2022? :

 

NPTEL An Introduction To Programming Through C++ Assignment 4 Answers 2022

Given an integer N >=2, we need to output all its prime factors in increasing order. To do this, we exploit the fact that if N is composite, it has a prime factor that is <= √N. If it is prime, then N itself is the only prime factor of itself.
Eg:
Input: N=12
Output: 2 2 3
Input: N=17
Output: 17

int N;

cin >> N;

for(int x=2; blank1 ; x++){

while (N%x == 0)

{

// We print out x as long as N remains divisible by x

cout << x << “ “;

blank2 ;

}

}

if(N>1){

// The case when N is prime

blank3 ;

}
Q1. What would be blank1 (we need to check division by numbers upto what value of x):

a) x < 17
b) x*x <= N
c) x*x < N
d) x*x*x <= N

Answer By SciShowEngineer
Answer: b)

Q2. What would be blank2 (if N is divisible by x, then we print x as a factor and then must remove it from N):

a) N = N – 1
b) N = N*x
c) N = N/x
d) N = N%x

Answer By SciShowEngineer
Answer: c)

Q3. What would be blank3 (this case occurs when N is prime):

a) cout << “prime”
b) cout << N-1
c) cout << N
d) cout << x

Answer By SciShowEngineer
Answer: c)

Q4. The numerical integration program discussed in the lecture estimates the area under the curve f(x) between p+iw and p+(i+1)w by f(p+iw)*w. Which of these is correct:

a) If f(x) = 5-x, the answer found by numerical integration is less than the actual integration
b) If f(x) = 1/x, the answer found by numerical integration is less than the actual integration

 

c) If f(x) = 3x³, the answer found by numerical integration is less than the actual integration
d) None of these

Answer By SciShowEngineer
Answer: c)

Q5. We know that the roots of the functions f(x) = x² and g(x) = x⁴ are x = 0. However, we decide to employ the Newton-Raphson method to estimate their roots. We begin with x0 = 1 for both these functions. Consider the following statements:

For f(x), xn = (½)n
For g(x), xn = (⅔)n
x2 is closer to the root for f(x) than for g(x).
x2 is closer to the root for g(x) than for f(x).
Which of these statements are true:

a) 1 and 3
b) 2 and 3
c) 1 and 4
d) 2 and 4

Answer By SciShowEngineer
Answer: a)

Q6. What does the following program output for any given positive integers ‘a’ and ‘b’?

main_program {
int a; int b;
cin >> a >> b;
while(a – b >= 0) {
a = a – b;
}

cout << a;
}
a) a % b
b) a – b
c) a / b
d) none of the others

Answer By SciShowEngineer
Answer: a)

Q7. What is the output of the following code snippet?

main_program()
{
int k, j;

for(k=1, j=10; k <= 5; k++)
{
cout << k+j << ’ ‘;
}
}
a) Compile error
b) 10 10 10 10 10
c) 11 13 15 17 19
d) 11 12 13 14 15

Answer By SciShowEngineer
Answer: d)

Q8. What is the output of the following code snippet?

main_program()
{
int k, j;

for(k=9; k!=0; k–-)
{
cout << k– << ‘ ‘;
}
}
a) 9 8 7 6 5 4 3 2 1
b) 9 7 5 3 1
c) Infinite loop
d) None of the above

Answer By SciShowEngineer
Answer: c)

Given below is the code to find the number of digits in the binary representation (base 2)of a given number x, without leading zeros (x>0). Answer the following questions based on this.

main_program{
int x;
cin >> x;
int d = 0, n=BLANK_P;
while(x BLANK_Q n){
d++;
n *= BLANK_R;
}
cout<<d<<endl;
Q9. What is BLANK_P (Integer answer)

Answer By SciShowEngineer
Answer: 1

Q10. What is BLANK_Q

a) >
b) <
c) >=
d) <=

Answer By SciShowEngineer
Answer: c)

Q11. What is BLANK_R (Integer answer)

Answer By SciShowEngineer
Answer: 2

Q12. Suppose you are given a 1000 digit number(N) and without storing all the digits of either the number or the quotient we want to find the quotient when N is divided by another given number (small enough to be stored, say p). Which of the following is true?

a) It cannot be done
b) It can be done if the digits are given least significant to most significant and need to be printed in the same order.
c) It can be done if the digits are given most significant to least significant and need to be printed in the same order
d) It can be done if the digits are given in any order and need to be printed in the same order.

Answer By SciShowEngineer
Answer: c

NPTEL An Introduction To Programming Through C++ Programming Assignment 4 Answers 2022

In continuation of the topic of computing mathematical functions explored in the lectures, we see another method to find square roots.
Suppose we wish to find the square root of some k > 0. Consider the sequence (a0, a1, a2…)
defined by
a0 = k
an+1 = (an + (k/an))/2 for n >= 0
It can be shown that as n increases, the an converges to the square root of k . Write a program that takes as input a double k, and computes its square root using this method. Compute the value of an till (an – an-1 < 1e-5) and then report an correct to 2 decimal places.
Note: Start writing the program directly from main_program. To print a double x correct to 2 decimal places, use
cout.precision(2);
cout << fixed << x << endl;

INPUT
k (2 <= k <= 100, of type double)

OUTPUT
The square root of k correct to two decimal places

CODE:

main_program {

double k, a0, a1;
cin >> k;
a0 = k;
a1 = (a0 + (k/a0)) / 2;
while((a0-a1) >= 0.00001) {
a0 = a1;
a1 = (a0 + (k/a0)) / 2;
}
cout.precision(2);
cout << fixed << a1 << endl;
}
Programming Assignment 4.2
Write a program to keep track of a match consisting of a series of games between two people: player A and player B, and report the outcome. The input consists of a sequence of letters A or B. If the input is A, it indicates that A has won a game. If it is B, then it indicates B has won a game. The first player to win 5 or more games with a difference of 2 or more games between him and his opponent wins the match. If no player wins the match in 20 games then the match is declared a tie after these 20 games have been played.

CODE:

main_program {

char ch;
int A=0, B=0, count=1;

while(count <= 20) {
cin >> ch;
switch(ch) {
case ‘A’: A++;
break;
case ‘B’: B++;
break;
}
count++;
}

if(A==B)
cout << “Tie” << endl;
else if((A-B) > 1)
cout << “A” << endl;
else
cout << “B” << endl;

}

Related Posts

Leave a Reply

Your email address will not be published.