The Harshad or Niven numbers are positive integers >= 1 that are divisible by the sum of their digits. For example, 42 is a Harshad number as 42
Continue ReadingC++: AVL Tree
In computer science, an AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by a
Continue ReadingC++: Closures/Value Capture
Task: Create a list of 10 functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may
Continue ReadingC++: Generic Swap
The task is to write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that
Continue ReadingC++: Mode
Write a program to find the mode value of a collection. The case where the collection is empty may be ignored. Care must be taken to handle the case w
Continue ReadingC++: Pythagorean Means
Compute all three of the Pythagorean means of the set of integers 1 through 10. Show that for this set of positive integers. The most common
Continue ReadingC++ Interview Question 17 Answer
Answer This question is compilable and deterministic. Its output is "B". Explanation The "trick" here is that B::f() is called even though i
Continue ReadingC++ Interview Question 16 Answer
Answer This question is compilable and deterministic. Its output is "abBA". Explanation The base class constructor is called before the inhe
Continue ReadingC++ Interview Question 15 Answer
Answer This question is compilable and deterministic. Its output is "abBA". Explanation Member variables are initialized before the construc
Continue ReadingC++ Interview Question 14 Answer
Answer This question is compilable and deterministic. Its output is "acabBA". Explanation Static local variables are initialized the first t
Continue Reading