NPTEL » Intro to Programming Through C++ Assignment 2021

objective assignment

NPTEL Intro to Programming Through C++ With the growth of Information and Communication Technology, there is a need to develop large and complex software. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the C++ programming language emerges as the best programming environment. This course provides an introduction to problem-solving and programming using the C++ programming language.

Intro to Programming Through C++ is a MOOC based course that is 12 weeks in duration and can fulfill the criteria of 4 credits in a year. You can visit the NPTEL SWAYAM platform and register yourself for the course. This course is brought to you by Prof. Partha Pratim Das received his BTech, MTech, and Ph.D. degrees in 1984, 1985, and 1988 respectively from IIT Kharagpur.

Intro to Programming Through C++ 2021 Details:-

  1. Who Can Join: First and second-year students in degree programs including Engineering and Science degree programs
  2. Requirements/Prerequisites: Standard XII in the Science stream
  3. INDUSTRY SUPPORT: Programming in C++ is so fundamental that all companies dealing with systems.
  4. These include – Microsoft, Samsung, Xerox, Yahoo, Google, IBM, TCS, Infosys, Amazon, Flipkart, etc.

Intro to Programming Through C++ Objective Assignment Week 12 Answers:-

Q1.I want to write a program that answers questions of the form “Is X a scientist?”, for whatever X the user might request. My program will answer using a data structure in which I will first store names of as many scientists I know.

Answer:-A – vector<string>

Q2. The first line of the code below defines a data structure “children” for storinginformation about the children of an individual. The second line says

Answer:- B – string

Q3. What should blank2 be?

Answer:- D – Ashok

Q4. Suppose we have entered information about Vikramaditya’s children and alsograndchildren into “children”. What should R be if I want the statement

Answer:- C – children[children[“Vikramaditya”][0]].size()

Q5. What is BLANK_1?

Answer:- 0

Q6. What is BLANK_2?

Answer:- second

Q7. What is BLANK_3?

Answer:- first

Consider the below code which fills (in order as given in the input) and sorts a vector.Give the blank values without any n, nums;

Q8. What is BLANK_1?

Answer:- push_back

Q9. What is BLANK_2?

Answer:- begin()

Q10. What is BLANK_3?

Answer:- end()

Q11. What is the output if input is 10?

Answer:- YES

Q12. What is the output if input is 30?

Answer:- NO

Intro to Programming Through C++ Objective Assignment Week 11 Answers:-

Q1. What is the output printed by loop 1?


Q2. What is the output printed by loop 2?

Answer:- Dhruv,Raaghav,Yash,

Q3. What should be Blank1?

Answer:- u.second.count(sub)

Q4. What should be Blank2?


Q5. What does the following code fragment print?set<int> s; s.insert(20); s.insert(30); s.insert(30); s.insert(10);for(auto u: s) cout<<u<<”,”;


Q6. I want to write a program that (1) reads the file, (2) reads names from the keyboard, and prints the name of the father of each, if this information is present in the file. For this, the information in the file must be stored in suitable data structures. Given below are some possible ways of doing this. State which is most convenient i.e. easiest for you to write.

Answer:- C- map, where map and string are from the standard library.

Q7. Consider the following code snippetset<int, greater<int> > sp;sp.insert(3);sp.insert(5);sp.erase(2);sp.insert(10);sp.erase(3);sp.insert(10);cout<<sp.size();
What would be the output of the program?

Answer:- 2

Q8. Consider the following code segmentvector<pair<string, int> > pt;pt.push_back(pair<string, int>(“abc”, 1));pt.push_back(pair<string, int>(“bac”, 1));pt.push_back(pair<string, int>(“abc”, 2));pt.push_back(pair<string, int>(“ab”, 10));sort(pt.begin(), pt.end());cout<<pt[2].first<<” “<<pt[2].second;

Answer:-abc 2

Q9. What will come in blank1 ? Do not include unnecessary spaces

Answer:- second.first

Q10. What will come in blank2 ? Do not include unnecessary spaces

Answer:- first

Intro to Programming Through C++ Objective Assignment Week 10 Answers:-

Q1. Consider the following code segment

void func() {
	int *ptr = new int(10);

int main() {

Answer:- A,B,D

Q2.Consider the following code segment

int* func() {
	int x = 10;
	return &x;

int main()
	int* ptr = func();

Answer:- A

int dist(string a, string b, map<string, string>
int d = 0;
string curr = a;
return Blank-1;
else if(father.count(curr)==Blank-2){
return -1;
curr = Blank-3;
d = d+Blank-4;

Q3. Blank-1

Answer:- father[d]

Q4. Blank-2

Answer:- 1

Q5. Blank-3

Answer:- b


Q6. Blank-4

Answer:- 1

void f (vector<int> v)
for (int i = 0; i < v.size()/2; ++i)
int temp = v[i];
v[i] = v[v.size()-1-i];
v[v.size()-1-i] = temp;

Q7. Which of the following are true ?

Answer:- a,b

vector<size_t> findall (string s, string sub)
(1) occurrences;
size_t i = s.find(sub);
while(i != string::(2))
i = s.find(sub, i+(3));
return (4);

Q8. (1)

Answer:- vector<size_t>

Q9. (2)



Q10. (3)


Q11. (4)


Intro to Programming Through C++ Objective Assignment Week 09 Answers:-

Q1. Consider the following code fragment :
struct mystruct{int i, j;};struct mystruct *a[100];

The above declaration defines ‘a’ to be

Answer:-A – An array, each element of which is a pointer to a structure of type mystruct

Q2. Consider the following structures

Answer:- C – It is valid and declares a member variable of employee_data with the type address

Q3. What is the output of the following program?

Answer:- C – 100

Q4. What is the output of the following program?

Answer:- A – ERROR

Q5. What is the output of the following program?

Answer:- pqp

Q6. Private data members cannot be used inside public member functions.

Answer:- B – FALSE

Q7. What is the output of the following code? (If the code does not compile or gives a
runtime error, enter 0 as answer)

Answer:- 0

Q8. What is wrong with the access type of the member function print() ?

Answer:-B – It is private by default but it should be public

Q9. What is the output of the following code after making all data members, constructors and member functions public? (If the code does not compile or gives a runtime error, enter 0 as answer)

Answer:- 0

Q10. What sort of connections does the following code make? x->y means that
points to y, x<-y means that y.prev points to x, x<->y means both of these.

Answer:- B – A<->B<->D<->C

Q11. Suppose we want to change this structure and assign to D. Which of the following accomplishes this?

Answer:-D –>next->next->next =>next

Intro to Programming Through C++ Objective Assignment Week 08 Answers:-

int main(){
	int A[3][3]={{1,2,3},{4,5,6},{7,8,9}};
	for(int j=0;j<3;j++){
		for(int i=0;i<3;i++){

Q1. What is the final value of A[2][1]?

Answer:- A – 14

Q2. How many entries in A are equal to 10?

Answer:- 2

Q3. The value of A[2][2] is 18.

Answer:- A – TRUE

Q4. When an executable is run, with some command line arguments, then where is the first command line argument stored?

Answer:- B – At the 1st index in array argv


Q5. Consider the code snippet below:char buff[5];cin.getline(buff,4);cout<<buff;Suppose the string “hello” is given as input (without the quotes). What will be printed?

Answer:- hel

Q6. When an executable named “a.out” is run named for a program “program.cpp”, with some command line arguments, what does argv[0] represent?

Answer:- C – the filename of the executable i.e. “a.out”

Q7. Given Tn = 3*Tn/2 + n/2 , and T1 = 0. What is the value of T64?

Answer:- 665

Intro to Programming Through C++ Programming Assignment Week 08 Answers

Q8. What piece of code fills B1?

Answer:- B – A[i][j]

Q9. What piece of code fills B2?

Answer:- C- !A[i-1][j]


Q10. What piece of code fills B3?

Answer:- B – !A[i][j-1]

Intro to Programming Through C++ Objective Assignment Week 07 Answers:-

Q1. Which of the following is(are) the correct way(s) to initialise an array?

Answer:- A,C,D

Q2. What is the input for a[2] for the above program to print 10 20 0 5 ?

Answer:- -20

Q3. What is the final value of s for the inputs: 10 5 -20 10?

Answer:- 5

Consider the following code fragment. long long int A[4]={625,246,207,1280}; Assume A[0] is stored at address 400. Also assume that each long-long int is 8 bytes wide, so A[1] will be stored at 408 and so on. Note that normally when you print an address, it will get printed in hexadecimal;

Q4. cout<<A;

Answer:- 400

Q5. cout<<*A;

Answer:- 625

Q6. cout<<&A[2]

Answer:- 416

Q7. Blank 1

Answer:- 0

Q8. Blank 2

Answer:- continue

Q9. Blank 3

Answer:- n

Q10. Blank 4

Answer:- completed

Q11. Blank 5

Answer:- ==

Q12. Blank 6

Answer:- reward[pos]

Q13. Is it possible that the above code gets into a non terminating loop?

Answer:- A

C++ Objective Assignment Week 06 Answers:-

Q1. The difference between .c and .h files is that the body of the function can exist in .c files but not in .h files.

Ans:- A – TRUE

Q2. Which is the always the correct way to use a function(say void f() ) not part of any namespace?

Ans:- C – Using the statement  “::f()”

Q3. Which is the correct way to give default value to the parameter a in a function f?

Ans:- D – All the options are wrong

Q4. Consider the function declarations

void f(int x, int y);
void g(int z);
int main(){
void f(int x,int y){
void g(int z){
int main(){

Consider the commands:
1) g++ f1.cpp header1.h
2) g++ f2.cpp header1.h

Ans:- B – Both the commands work correctly

Q5. What is the output of the program if the input is 5?

Ans:- 26

Consider the program:

#include <iostream>

#include <functional>

using namespace std;

int main(){

int n; cin >> n;

int i=4;

cout << [n](int i){i=7;return n*i+n*n;}(6)<<endl;



Q6. What is A ?

Ans:- 30

Q7. What is B ?

Ans:- 4

Q8. What value is printed when the following set of instructions executes?
    cout << [](double x, double y){return sqrt(x*x + y*y);}(6,8)<<endl;

Ans:- 10


    int f(int a, int b, int c = 1, int d = 2){

        return a+b+c+d;

    int main(){

Q9. What will be printed by the above program?

Ans:- C

Q10. How many different poetic meters can you have of duration 3?

Ans:- 4

Q11. Suppose T(n) denotes the number of poetic meters of total duration 3. Which of the following equals T(n) if n>2?

Ans:- A – T(n-1) + T(n-2) + T(n-3)

C++ Objective Assignment Week 05 Answers:-

Q1. In each option below we have a function definition and a call to that function. Which of them is the correct method to pass arguments by reference

Answer:- A – void swap(int &a, int &b){ //body of function}

The “signature” of a function is the first line that gives the return type, the name of the function and the parameters with their types. Thus the signature of the gcd function is int gcd(int m, int n) . You are given a function whose signature is as follows void multiprint(char c, int count).

Q2. What is the value of BLANK-A?

Answer:- *

Q3.What is the value of BLANK-B?

Answer:- 3

Q4.What is the value of BLANK-C?

Answer:- z

Q5. What is the value of BLANK-D?

Answer:- 4

Q6. What is the value of BLANK-E?

Answer:- @

Q7. What is the value of BLANK-F?

Answer:- 3

Given below is an implementation of multiplication via addition. It is based on the idea that axn = a+a…n times.

		int mult_add(int a, int n){
			if(n==BLANK-A) return 0
			int recurse = mult_add(BLANK-B, BLANK-C);
			int ans = a+ recurse;
			return ans;

Q8. What is BLANK-A?

Answer:- 0

Q9. What is BLANK-B?

Answer:- a

Q10. What is BLANK-c?

Answer:- n-1

Q11. What is the maximum number of activation frames that might be present for the call f(2,13), where f is defined as follows? (Include the activation from the main_program in both cases in the count).

int f(int a, int b)
if(a>b) return a-b;
else return f(a+1,b/2);

Answer:- 4

Q12. What does the call f(3,32) return?

Answer:- 2

Q13. Is there some value of a, b for which the recursive function f does not terminate. If yes, give the value of a (as a string with no spaces) as the answer, else give the answer as ”-” ( without quotes).


Q14. What will the following program do?

void S(int s, int n){
if(s == n) return;


Answer:- B – It will draw a closed figure with 10 sides

Consider the code below for computing a mystery value.

#include <iostream>
using namespace std;
int mystery(int a, int b)
		if (b == 0)
			return 0;
		if (b % 2 == 0)
			return mystery(a + a, b/2);
		return mystery(a + a, b/2) + a;
int main()
	cout << mystery(7, 3) ;
	return 0;

Q15. What does the program print?

Answer:- 21

Q16. In general, what is printed by mystery(a, b)? Hint: Try more examples.

Answer:- D -a*b

C++ Objective Assignment Week 04 Answers:-

1.Suppose we wish to approximate the area under the curve e-x between 0 and some positive x0 by numerical integration. The numerical integration program discussed in the lecture estimates the area under a curve f(x) between p+iw and p+(i+1)w by f(p+iw)*w. Which of the following is true?

Answer:- B – The answer produced by the program will be larger than the actual area.

2. We have studied the bisection method in the class. Now consider a new technique called the trisection method. Herein suppose we start with an error threshold(epsilon) and x1 and x2 and a function f such that f(x1)>0 and f(x2)<0.

Answer:- D – This algorithm will converge to a point that is at a maximum distance of eps from the a root of f, given that f is continuous

3. Suppose I want to find the root of the polynomial: p(x)=x3 – 7x2/2 + 4x using the Newton-Raphson method. Then which of the following initialisations of x0 may cause the algorithm to not converge to a point that is at maximum eps distance from a root of p(x) ?

Answer:- A – 1

4. Which is the correct approximation of cos(x) using taylor polynomial ?

Answer:- A – 1 – x2/2 + x4/24

quizxp telegram

5. Is the below code correct?

double y; cin >> y;
for(double xi=1; abs(xi*xi – y) > 0.001; xi = (xi + y/xi)/2){}
// yes, empty body
cout << xi << endl;

Answer:- A – Yes

6. Is the below code correct?

double y; cin >> y;
double xi;
for(xi=1; ; xi = (xi + y/xi)/2){
if(abs(xi*xi – y) > 0.001) break;
cout << xi << endl;

Answer:- B – No

int x;
cin >> x;
int d = 0, n=BLANK_P;
while(x BLANK_Q n){
n *= BLANK_R;

7. What is BLANK_P

Answer:- 1

8. What is BLANK_Q

Answer:- C – >=

9. What is BLANK_R

Answer:- 10

10. 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?

Answer:- C – It can be done if the digits are given most significant to least significant and need to be printed in the same order

11. What is BLANK_A ?

Answer:- A – dist += sp*1

12. What is BLANK_B ?

Answer:- A- dist += sp*1

C++ Objective Assignment Week 03 Answers:-

int income;
cin >> income;
double tax = 0;
if (income <= 100000) tax = blankA1 + blankA2 * income;
else if (income <= 500000) tax = blankB1 + 0.05 * (income - blankB2 );
else tax = blankC1 + blankC2 * (income - 500000);
cout << tax << endl;

Q1. What is the value of blankA1?

Answer:- 0

Q2. What is the value of blankA2?

Answer:- 0.02

Q3. What is the value of blankB1?

Answer:- 2000

Q4.What is the value of blankB2?

Answer:- 100000

Q5. What is the value of blankC1?

Answer:- 22000

Q6. What is the value of blankA2?

Answer:- 0.02

int req_sum = 0;
	int x=0;
		cin >> x;
		if (x%7==0) B2;

Q7. What is B1?

Answer:- x!=-1

Q8. What is B2?

Answer:- req_sum += x

Q9. There is no need to iterate further once we have encountered a divisor of the number. What should be the command to be replaced by BlankZ?

Answer:- Break

Q10. What does the program above print?

Answer:- 56,1

Q11. I f the program in the previous question is modified to read ‘n’ from keyboard (instead of assigning a constant inside the program). In general, what does such a modified program print?

Answer:- A -The program prints the sum of proper divisors of n, followed by 1 if it is a perfect number and 0 if it is not

Q12. What will the following program fragment print?

int sum = 0;
	for(int i=1; i<100; i=i*3) sum = sum + i;

Answer:- 121

C++ Objective Assignment Week 02 Answers:-

Q1. I have to read the string “What is your name?” into a variable x. Which of the following is the appropriate command sequence?

Answer:- C

Q2. What is OUTPUT1 ?

Answer:- 0

Q3. What is OUTPUT2 ?

Answer:- 0

Q4. What is OUTPUT3 ?

Answer:- -1

Q5. What is OUTPUT4 ?

Answer:- 3.3333

Q6. What will be printed by the following code:

int x=2; repeat(4){ x = 3*x + 1; } cout << x << endl;

Answer:- 202

quizxp telegram

Q7. What is the correct initialisation of a

Answer:- 2

Q8. What is the correct initialisation of b

Answer:- 3

Q9. What is OUTPUT1 ?

Answer:- 48

Q10. What is OUTPUT2 ?

Answer:- 90

Also Check :-

Q11. What is OUTPUT3 ?

Answer:- 187

Q12. What is OUTPUT4 ?

Answer:- A

Q13. What is BLANK-P ?

Answer:- 1

Q14. What is BLANK-Q ?

Answer:- 2

Q15. What is BLANK-R ?

Answer:- -5

Q16. What is BLANK-S ?

Answer:- 10

Also check:-

quizxp telegram

C++ Objective Assignment Week 01 Answers:-

Q1. What is B1?

Answer:- 120

Q2. What is B2?

Answer:- 100

Q3. What is B3?

Answer:- 120

Q4. What is B1?

Answer:- 2

Q5. What is B2?

Answer:- 3

Q6. What is B3?

Answer:- 2

quizxp telegram

Q7. What is B4?

Answer:- 3

Q8. What is command B1?

Answer:- A

Q9. What is command B2?

Answer:- B

Q10. What is B3?

Answer:- 60

Q11. Suppose we flatten the image into an array(let’s call it A, and it is indexed from 0) such that pixel number i goes into the array at index i. What is the index of a pixel in column a and row b? (Note that first row has a=0 and first column has b=0)

Answer:- C

Q12. Which of the indices in the array correspond to black pixels ?

Answer:- B

Q13. What is the total number of white pixels?

Answer:- 20

Q14. For the pixel at index i in the array, what are the corresponding row and column number  (first row has row number 0, and second row has 1)?

Answer:- A


Find Other Quiz Here:

Amazon Fashion Quiz Answers & Win ₹1000

Amazon Great Indian Festival Quiz Answers: Win Rs. 50,000

NPTEL » Programming In Java Assignment week 6 Sep-2020

NPTEL » Programming In Java Assignment week 7 Sep-2020

NOTE: These codes are based on our knowledge. Answers might be incorrect, we suggest you to not the copy-paste answers blindly.

[foobar id=”1315″]