An Introduction To Programming Through C++ Assignment 9 Answers

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.

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.

An Introduction To Programming Through C++Answers
Assignment 1Click Here
Assignment 2Click Here
Assignment 3Click Here
Assignment 4Click Here
Assignment 5Click Here
Assignment 6Click Here
Assignment 7Click Here
Assignment 8Click Here
Assignment 9Click Here
Assignment 10Click Here
Assignment 11NA
Assignment 12NA

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

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. The code creates a structure type named x. 

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

An Introduction To Programming Through C++ Assignment 9 Answers

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. L1.p1 = L2; 

Q5. What should blank1 be?

Answer: marklist[i].name[0]

👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇

An Introduction To Programming Through C++ Assignment 9 Answers

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

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

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

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

Q11. Which the following is true?

Answer: b

Q12. Which of the following is true?

Answer: a

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

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

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);
} 

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.

Leave a Comment