[Solved] COEN79-Homework 3

$25

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

SKU: [Solved] COEN79-Homework 3 Category: Tag:
5/5 - (1 vote)
  1. The sequences 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. }

Reviews

There are no reviews yet.

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

Shopping Cart
[Solved] COEN79-Homework 3
$25