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

NPTEL An Introduction to Programming Through C++ Assignment 7

Are you looking for the Answers to NPTEL An Introduction to Programming Through C++ Assignment 7? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course “ NPTEL An Introduction to Programming Through C++ Assignment 7

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.

Below you can find the answers for NPTEL An Introduction to Programming Through C++ Assignment 7

Assignment No.Answers
An Intro to Programming C++ Assignment 1 Click Here
An Intro to Programming C++ Assignment 2 Click Here
An Intro to Programming C++ Assignment 3 Click Here
An Intro to Programming C++ Assignment 4 Click Here
An Intro to Programming C++ Assignment 5 Click Here
An Intro to Programming C++ Assignment 6 Click Here
An Intro to Programming C++ Assignment 7 Click Here
An Intro to Programming C++ Assignment 8 Click Here

NPTEL An Introduction to Programming Through C++ Assignment 7 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: int a[10]; for(int i=0; i<10; i++) cin >> a[i]; bool s=true; for(int i=0; i<9; i++)      if(a[i] < a[i+1]) s = false; cout << s; Which of the following are true?

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: bool allEven(int a[], int n){    int i=0;    for(i=0; i<n; i++)         if(a[i] %2 != 0) break;    if(i == blank) return true;    else return false; } What should be in place of blank? Answer without any quotes or spaces.

Answer: n

Next Week Assignment Answers

quizxp telegram

Q5. What should blank1 be?

Answer: n

Q6. What should blank2 be?

Answer: i

Q7. What should blank3 be?

Answer: j

If there are any changes in answers will notify you on telegram so you can get a 100% score, So Join

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 Consider the following code fragment. int q[4]={25, 26, 27, 28}; cout << q[0] << endl; cout << &q[2] << endl; cout << q << endl; q[0] = 6; q = 1600; Assume q[0] is stored at address 1500. Also assume that each int is 4 bytes wide, so q[1] will be stored at 1504, q[2] at 1508 and so on. Note that normally when you print an address, it will get printed in hexadecimal; but just for the exercises below assume that addresses are also printed in decimal.

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

Answer: 25

For Online programming test help and final exam preparation material Click Me

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)

Programming Assignment

Q1. 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:-

For Online programming test help and final exam preparation material Click Me

main_program 
{
int n,m, a[10],d[m],i, 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;
}
  

Q2. 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 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;
}

For other courses answers:- Visit

For Internship and job updates:- Visit

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.