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

NPTEL An Introduction to Programming Through C++ Assignment 9

Are you looking for the Answers to NPTEL An Introduction to Programming Through C++ Assignment 9? 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 9

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 9

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 9 Answers:-

Q1. Which of the following is true

a. The code creates a structure type named x. 
b. The code creates a structure variable named x. 
c. The code creates variables y and z. 
d. The code has a syntax error.

Answer:- a

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

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

Q2. What is the value of Q.x?

Answer: 60

Q3. What is the value of L2.p1.y?

Answer: 12

Q4. Which of the following statements will be syntactically incorrect following the code given above?

  • L1 = L2; 
  • L1.p1 = L2; 
  • L1.p2 = L2.p1; 
  • L2.p2.x = L2.p1.y;

Answer: b

Q5. What should blank1 be?

Answer: marklist[i].name[0]

Q6. What should blank2 be?

Answer:- marklist[i].marks

Q7. What is the first number printed?

Answer: 12

Q8. What is the second number printed?

Answer: 9

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

Q9. Which of these lines give a compiler error:

  • Line 1, Line 2 
  • Line 2, Line 3 
  • Only Line 3 
  • Only Line 1

Answer: c

Q10. We can prevent the compiler error by:

  • Writing a constructor for the Counter class 
  • Changing the access specifier for the member variable x 
  • Changing the access specifier for the member function inc 
  • Including iostream in the program

Answer:b

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

Q11. Which the following is true?

Answer: b

Q12. Which of the following is true?

Answer: c

Q13. What is the first number printed by this code?

Answer: 15

Q14. What is the second number printed by this code?

Answer: 5

Q15. What is the third number printed by this code?

Answer: 16

Q16. What is the fourth number printed by this code?

Answer: 5

Programming Assignment

Q1. Define a class for storing time durations. A time duration is a triple h, m, s of non negative integers, respectively denoting the number of hours, minutes and seconds. The numbers should satisfy the natural condition that h >= 0, 60 > m >=0, and 60 > s >= 0. Define constructors that create a duration given arguments h, m, s, and also a constructor with no arguments which creates a duration of 0 hours 0 minutes 0 seconds. It should be possible to add durations but in the result duration you should ensure that the natural condition is satisfied. Similarly it should be possible to multiply a duration D by a non negative integer I, this should result in a duration that is I time as large as D. Again the result should satisfy the natural constraints. Thus 4 times 1 hour 30 minutes 23 seconds should give the duration 6 hours 1 minute 32 seconds. Finally the class should support a member function print which prints h,m,s i.e. only with intervening commas and no spaces nor new lines.

Code:-

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

class Duration
{
int hour, min, sec;
public:
Duration(int h, int m, int s)
{
hour = h;
min = m;
sec = s;
}
Duration()
{
hour = 0;
min = 0;
sec = 0;
}
void format()
{
min = min + sec / 60;
hour = hour + min / 60;
sec = sec % 60;
min = min % 60;
}
Duration operator +(Duration &d)
{
Duration t;
t.sec = sec + d.sec;
t.min = min + d.min;
t.hour = hour + d.hour;
t.format();
return (t);
}
Duration operator *(int i)
{
Duration t;
t.sec = sec*i;
t.min = min*i;
t.hour = hour*i;
t.format();
return(t);
}
void print()
{
cout << hour << "," << min << "," << sec;
}
}; 

Q2. Rectangles whose sides are parallel to the coordinate axes can be represented by specifying the coordinates of diagonally opposite vertices.Suppose the southwest and northeast corners are (x1, y1) and (x3, y3). Clearly these 4 numbers determine the other two corners as well:they will be (x1, y3) and(x3 , y1). Define a struct Rect with integer members x1, y1, x3, y3. Define a function intersect which takes 2

Code:-

struct Rect
{
int x1, y1, x3, y3;
};
struct Rect intersect(struct Rect r1, struct Rect r2)
{
struct Rect r;
if((r1.x1 >= r2.x3) || (r2.x1 >= r1.x3) || (r1.y1 >= r2.y3) || (r2.y1 >= r1.y3))
{
r.x1 = r.x3 = r.y1 = r.y3 = 0;
}
else
{
if(r1.x1 > r2.x1)
r.x1 = r1.x1;
else
r.x1 = r2.x1;
if(r1.y1 > r2.y1)
r.y1 = r1.y1;
else
r.y1 = r2.y1;
if(r1.x3 < r2.x3)
r.x3 = r1.x3;
else
r.x3 = r2.x3;
if(r1.y3 < r2.y3)
r.y3 = r1.y3;
else
r.y3 = r2.y3;

}
return (r);
} 

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.

NPTEL An Introduction To Programming Through C++ Assignment 9 Answers 2022:-In This article, we have provided the answers of An Introduction To Programming Through C++ Assignment 9. You must submit your assignment to your own knowledge.