This set of MCQ(multiple choice questions) focuses on the **An Introduction to Programming Through C++ NPTEL 2022 Week 7 Answers**.

### Course layout

*Answers COMING SOON! Kindly Wait!*

**Week 0: ****Assignment answers** **Week 1**: Introduction to computers using graphics.

*Programming Assignment***Week 2:** Basic data types.

*Programming Assignment***Week 3:****Statements of C++ for conditional execution and looping.**

*Programming Assignment***Week 4: Statements of C++ for conditional execution and looping.**

*Programming Assignment*

**Week 5:**Functions.

*Programming Assignment*

**Week 6:**Recursive algorithms and recursive drawings.

*Programming Assignment*

**Week 7:**Arrays.

*Programming Assignment*

**Week 8:**Multidimensional arrays.

*Programming Assignment*

**Use of the standard library in designing programs.**

Week 11:

**Week 9**: Structures. Pointers with structures.*Programming Assignment***Week**10: Dynamic memory allocation.Week 11:

**NOTE:** You can check your answer immediately by clicking show answer button. **An Introduction to Programming Through C++** NPTEL 2022 Week 7 Assignment Answers” contains 12 questions.

Now, start attempting the quiz.

**An Introduction to Programming Through C++** NPTEL 2022 Week 7 Assignment Answers

**Q1.** Consider the line of code

int x[4] = {10, 20, 30, 40};

What is the value of x[3]?

**Answer:** 40

**Q2.** Suppose students can obtain any (integer) mark from 0 to 100. I would like a histogram giving the number of students getting marks in the range 0-4, 5-9, 10-14, … 95-99, 100. What size array do I need to store the histogram?

**Answer:** 21

**Q3.** Consider the following program fragment:

a) The program outputs true if elements of a are in increasing order, i.e. a[i] < a[i+1] for i=0..8

b) The program outputs true if elements of a are in decreasing order, i.e. a[i] > a[i+1] for i=0..8

c) The program outputs true if elements of a are in non-increasing order, i.e. a[i] >= a[i+1] for i=0..8

d) The program always outputs true if elements of a are in non-decreasing order, i.e. a[i] <= a[i+1] for i=0..8

**Answer:** b)

**Q4.** Consider the following function which is supposed to return true if all the numbers in an array A are even and false otherwise:

**Answer:** n

**Q5.** What should blank1 be?

**Answer:** n

**Q6.** What should blank2 be?

**Answer:** i

**Q7.** What should blank3 be?

**Answer:** j

**Q8.** Suppose that we wanted the program to print whether T is obtained by taking the sum of 3 numbers chosen from S with replacement, i.e. the same number can be used several times. The code above will work, but the blanks will need to be filled possibly differently. What should blank2 be for this case?

**Answer:** n

**Q9.** State what value is printed by the statement in line 2.

**Answer:** 25

**Q10.** State what value is printed by the statement in line 3.

**Answer:** 1508

**Q11.** State what value is printed by the statement in line 4.

**Answer:** 1500

**Q12.** Which of the following statements are true?

a) Line 5 contains a valid C++ statement.

b) Line 6 contains a valid C++ statement.

**Answer:** a)

### An Introduction to Programming Through C++ NPTEL Week 7 Programming Assignment Answers

### Programming Assignment 7.1

Write a program that keeps track of the money in your wallet. As an example, suppose only notes of denominations 2000, 500, 200, 100, 50,20, 10 are in use. And suppose you have respectively 2, 5, 8, 4, 1, 1, 1 notes of the denominations. Thus you have a total of 4000 + 2500 + 1600+ 400 + 50 + 20 + 10 = 8580 rupees.

**CODE:**

```
main_program {
int n, m, i;
int a[10], d[m], sum = 0, rup, max = 0;
char com;
cin>>n;
for(i=0; i<n; i++) {
cin>>a[i];
}
m = a[i-1];
for(i=1; i<=m; i++) {
d[i] = 0;
}
for(i=0; i<n; i++) {
cin>>d[a[i]];
sum = sum + a[i] * d[a[i]];
}
while(1) {
cin>>com;
switch(com) {
case 'P': cout<<sum<<endl;
break;
case 'S': cin>>rup;
if(d[rup]>0) {
d[rup]--;
sum = sum - rup;
}
break;
case 'E': exit(1);
}
}
return 0;
}
```

### Programming Assignment 7.2

Write a function that takes an array of integers as an argument (in the usual manner, so two arguments including the length), and returns the mode of the elements in the array, i.e. an integer that occurs the maximum number of times. If there are several integers that occur the maximum number of times, then you should return that integer whose first appearance in the array is at the largest index. So for example, if the array contains 9, 8, 3, 4, 2, 4, 2, 9, 7, 4, 9, then there are 2 integers, 4 and 9 that appear the maximum number of times, i.e. 3 times. The first appearance of 9 is at index 0, while the first appearance of 4 is at index 3. Thus the function should return 4.

**CODE:**

```
int mode(int arr[], int n) {
int max;
max = arr[0];
int count[n];
int c=1, val=arr[0];
for(int i=0; i<n; i++) {
if(max < arr[i])
max = arr[i];
}
for(int i=0; i<n; i++)
count[arr[i]]=1;
for(int i=0; i<n-1; i++) {
for(int j=i+1; j<n; j++) {
if(arr[i]==arr[j]) {
count[arr[i]]++;
if(c <= count[arr[i]]) {
c = count[arr[i]];
val = arr[i];
}
}
}
}
if(c == 1)
val = arr[n-1];
return val;
}
```

🏆🏆🏆 Thank YouPratyush Kumarfor correction.👏

**<< Prev- An Introduction to Programming Through C++ Week 6 Solutions**

**>> Next- An Introduction to Programming Through C++ Week 8 Solutions**

DISCLAIMER:Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

*For discussion about any question, join the below comment section. And get the solution of your query.* Also, try to share your thoughts about the topics covered in this particular quiz.

Harshitwhere is the second code?? Please provide second code of arrays..

Prathameshint mode (int arr[], int n)

{

int i, j, max, count[max], c=1, val;

max=val=arr[0];

for (i=0;i<n;i++)

{

if(max<arr[i])

max=arr[i];

}

for (i=0;i<n; i++)

{

count[arr[i]]=1;

}

for (i=0;i<n-1; i++)

{

for(j=i+1;j<n; j++)

{

if(arr[i]==arr[j])

{

count [arr[i]]++;

if(c<=count[arr[i]])

{

c=count[arr[i]];

val=arr[i];

}

}

}

}

if(c==1)

{

val=arr[n-1];

}

return val;

}

samint mode(int arr[],int n){

int i,j,max,count[max],c=1,val;

max=val=arr[0];

for(i=0;i<n;i++){

if(max<arr[i]){

max=arr[i];

}

}

for(i=0;i<n;i++){

count[arr[i]]=1;

}

for(i=0;i<n-1;i++){

for(j=i+1;j<n;j++){

if(arr[i]==arr[j]){

count[arr[i]]++;

if(c<=count[arr[i]]){

c=count[arr[i]];

val=arr[i];

}

}

}

}

if(c==1){

val=arr[n-1];

}

return val;

}

PrathameshProgramming Assignment 7.2

int mode (int arr[], int n)

{

int i, j, max, count[max], c=1, val;

max=val=arr[0];

for (i=0;i<n;i++)

{

if(max<arr[i])

max=arr[i];

}

for (i=0;i<n; i++)

{

count[arr[i]]=1;

}

for (i=0;i<n-1; i++)

{

for(j=i+1;j<n; j++)

{

if(arr[i]==arr[j])

{

count [arr[i]]++;

if(c<=count[arr[i]])

{

c=count[arr[i]];

val=arr[i];

}

}

}

}

if(c==1)

{

val=arr[n-1];

}

return val;

}

riyaplz give us code of 7.1

sumanthsir where is week 8 answers sir please provide the week-8 answerswith programming assignments