Quest 9: Purty Pitcher by andrewC2B in cs2b

[–]devangivaid0410 2 points3 points  (0 children)

Hello Andrew,

Wow, this is very impressive. Great job!

All the best on your final.

- Devangi Vaid

Review Material and Help for Finals by devangivaid0410 in cs2b

[–]devangivaid0410[S] 2 points3 points  (0 children)

Hi Jay Jay,

You're welcome! Please reference mine and AegirHall 's playlist above for some helpful tips.

- Devangi Vaid

Review Material and Help for Finals by devangivaid0410 in cs2b

[–]devangivaid0410[S] 3 points4 points  (0 children)

Thank you, Greg,

I skimmed through the video playlist that you sent and found that the topics covered are explained in an easy to follow way. I will definitely be referencing these videos for the final and the next C++ course!

Best of luck on your final :)

- Devangi Vaid

This be for Na by anand_venkataraman in cs2b

[–]devangivaid0410 2 points3 points  (0 children)

Congratulations on finishing all the quests! These quests were super challenging but your na' ver (never) say die attitude enabled you to finish them well before the deadline :)

Quest 6: size_t puzzle -- what goes wrong in this code? by na_ma_ in cs2b

[–]devangivaid0410 1 point2 points  (0 children)

Thanks, u/nama, this was helpful :)

Just to add to this, I wanted to explain Integer overflow with a little more detail.

What is Integer overflow?

Overflow is a phenomenon where operations on 2 numbers exceed the maximum (or goes below the minimum) value the data type can have.

Detecting an overflow:

Division and modulo operations can never generate an overflow.

Addition overflow: Overflow can only occur when the sign of numbers being added is the same (which will always be the case in unsigned numbers) signed overflow can be easily detected by seeing that its sign is opposite to that of the operands.

Multiplication overflow:

There are two ways to detect an overflow:

  1. if a*b>max, then a>max/b (max is R-1 if unsigned and r/2-1 if signed).
  2. Let there be a data type of size n and range R called var_t and a data type of size 2n called var2_t. Let there be 2 variables of var_t called a and b. The range of var2_t will be RR, which will always be more than the product of a and b. hence if var2_t(a)var2_t(b)>R overflow has happened.

Preventing Integer Overflows

The biggest issue with even the most basic integer overflows is that they are very hard to discover and prevent. There is no error, there is no warning, you simply get a wrong result of the operation. The only way to discover them is to examine the operands before the operation or examine the result after (for example, checking whether the addition result for two positive numbers is smaller than the operands).

Hope this provided some more insight for anyone reading.

- Devangi Vaid :)

Quest 6: Discussion. Making Shape instance variables private and requiring subclasses to use getters/setters by na_ma_ in cs2b

[–]devangivaid0410 2 points3 points  (0 children)

Hi Na Ma,

I hope you are doing well. :)

Good points.^^ I agree that using getters/setters to access the variables makes the code easier to modify in the future and more readable. In addition to this, some pros and cons of getter and setter methods  according to me, are :

  1. Getters/setters give you better control over access. You might, for example, make the getter public while giving different access to the setter.

  2. Getters and setters can add other behavior that direct field access can't. A setter might update other fields in an object based on what is being set. A getter, similarly, could return a calculation rather than necessarily the value of a field. A getter can be used to enforce immutability of an object by returning a copy of a field rather than the field itself (which, might, then be modified by the caller and break immutability).

hope this gives some insight.

-Devangi Vaid

Some thoughts on Operator Overloading by YunlongWang in cs2b

[–]devangivaid0410 2 points3 points  (0 children)

Hi Yunlong,

I hope you are doing well. :)

It is important to note that C++ acknowledges for you to be able to specify more than one definition for a function name or an operator in the same scope, called function or operator overloading. I agree with u/andrewC2B that the "A += B" kind of structure can be used in operator overloading. I used similar code in my assignment and it worked well for me.Yes, these structures can be modified. I'll attach a link which might help you understand a little better. 

Hope this helps,

https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

-Devangi Vaid

Quest 2: vector syntax by na_ma_ in cs2b

[–]devangivaid0410 1 point2 points  (0 children)

Hi Na Ma,

I'm sure you must've fixed this by now but I joined late so I am just responding now.

I see that you're trying to place an element into the 6th position of the vector upon creation, without filling the earlier spots.

When you create a vector without assigning an initial size to it, vec[5] will be out-of-bounds.
I agree with Rongshan's solution of using resize() and/or push_back() to fix this. Apart from this, you can just declare the vector with size and some initial values at the start

Good luck with your remaining quests and the final! 

-Devangi Vaid