- The sequences insert member function normally puts a new item before the current item. What does insert do if there is no current item?
- 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
- 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;
}
- 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.
- Explain why heap variables are essentially global in scope. Please present an example as well.
- Is it possible to use the keyword this inside a friend function? Please explain your answer.
- 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.