[SOLVED] COEN79-Homework 2

20.99 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon HW2-rrskpu.zip (3621.6 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product
  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 point

2.  {

3.       public:

4.       // CONSTRUCTOR

5.     point (double initial_x = 0.0, double initial_y = 0.0);           6.

7.       // MODIFICATION MEMBER FUNCTIONS

8.       void set_x (double& value);

9.       void set_y (double& value);

10.

11.      // CONST MEMBER FUNCTIONS

12.      point operator+ (double& in) const;

13.

14.      private:

15.      double x; // x coordinate of this point

16.      double y; // y coordinate of this point

17.
18. };
   

 

  • Which line of the following code results in an error? Explain why. § What’s the solution?

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. What is the output of this code? Discuss your answer.

 

 

 

  • HW2-rrskpu.zip