[Solved] COEN79-Homework 2

$25

File Name: COEN79-Homework_2.zip
File Size: 160.14 KB

SKU: [Solved] COEN79-Homework 2 Category: Tag:
5/5 - (1 vote)
  1. What is encapsulation in OOP? Give an example
  1. What is the time complexity of fun(). Please show your proof.

int fun(int n)

{

int count = 0;

for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count += 1; return count;

}

  1. Give a concise formula that gives the approximate number of digits in a positive integer. The integer is written in base 10.
  1. What are the differences between references and pointers?
  1. What are the three ways we can use items defined in a namespace. Include examples in your answer.
  1. Discuss about the output of the following code. How the result will change if we replace struct with class?
1. struct Test {
2. int x;
3. }; 4.
5. int main() {
6. Test t;
7. t.x = 20;8. cout<t.x<endl;9. return 0;
10. }
  1. A The header of the point class is as follows:
1. class point2. {
3. public:4. // CONSTRUCTOR
5. point (double initial_x = 0.0, double initial_y = 0.0); 6.7. // MODIFICATION MEMBER FUNCTIONS8. void set_x (double& value);9. void set_y (double& value);10.
11. // CONST MEMBER FUNCTIONS12. point operator+ (double& in) const;13.
14. private:15. double x; // x coordinate of this point16. double y; // y coordinate of this point
17.
18. };
  • Which line of the following code results in an error? Explain why. Whats the solution?
  1. What is the output of this code? Discuss your answer.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COEN79-Homework 2
$25