[SOLVED] COEN79-Homework 3

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 HW3-foxtvd.zip (182.3 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. The sequence’s insert member function normally puts a new item before the current item. What does insert do if there is no current item?

 

 

 

 

 

 

 

  1. Modify the following code to generate the given output. Do not modify the main

 

 

 

Output:

Number of box objects created so far: 1

Number of box objects created so far: 2

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. In the following code, indicate if the selected lines are legal or illegal:

 

#include <iostream>

 

class small { public:     small( ) {size = 0;};     void k() const;     void h(int i);     friend void f(small z);

private:

int size;

};

 

void small::k() const

{     small x, y;     x = y; // LEGAL/ILLEGAL?

x.size = y.size; // LEGAL/ILLEGAL?

x.size = 3; // LEGAL/ILLEGAL?

};  void small::h(int i)

{

 

};  void f(small z)

{     small x, y;     x = y; // LEGAL/ILLEGAL?

x.size = y.size; // LEGAL/ILLEGAL?

x.size = 3; // LEGAL/ILLEGAL?

x.h(42); // LEGAL/ILLEGAL?

};

 

int main() {          small x, y;     x = y; // LEGAL/ILLEGAL?

x.size = y.size; // LEGAL/ILLEGAL?

x.size = 3; // LEGAL/ILLEGAL?

x.h(42); // LEGAL/ILLEGAL?

return 0;

}

 

 

 

 

 

 

 

 

  1. We create an array of fruit in the main How can we make sure that for all the items in array fruit_ptr the values of weight and color are equal to 1 and 2, respectively? Please show your solution. Do not modify the main function.

 

 

 

 

 

 

 

 

 

 

  1. Explain why heap variables are essentially global in scope. Please present an example as well.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. Is it possible to use the keyword “this” inside a friend function? Please explain your answer.

 

 

 

 

 

 

 

 

 

  1. Does the following code compile? Does it run? Is there any problem with the code? If yes, how do you fix it?

 

19.         cout << “Employee::foo()”;
20.         c -> process();
21.     }
22. };   23.
24. int main() {
25.     Employee ob;
26.     ob.foo();
27.     return 0;
28. }
   

 

  • HW3-foxtvd.zip