9. In the following code, indicate if the selected lines are legal or illegal: #
ID: 3711336 • Letter: 9
Question
9. In the following code, indicate if the selected lines are legal or illegal: #include class small public: small( ) {size-01); void k() consti void h(int i) friend void f (small z)i private: int sizej di void small::k) const small x, yi x = y; // LEGAL/ILLEGAL? x.size = y.size; // LEGAL/ILLEGAL ? x.size3 1/ LEGAL/ILLEGAL? di void small: :h(int i) Ii void f(small z) small x, yi x = y; // LEGAL / ILLEGAL? x.size- y.size; 1/ LEGAL/ILLEGAL? x.size= 3; // LEGAL/ILLEGAL? x.h(42)i 1/ LEGAL/ILLEGAL? int main) [ small x, y; x - yi // LEGAL/ILLEGAL? x.size=y.size; // LEGAL/ILLEGAL? x.size -3 17 LEGAL/ILLEGAL? x.h(42) // LEGAL/ILLEGAL? return 0;Explanation / Answer
Program:
#include <iostream>
using namespace std;
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
x.size=y.size; // LEGAL
x.size=3; // LEGAL
};
void small::h(int i)
{
} ;
void f(small z)
{
small x, y;
x = y; // LEGAL
x.size= y.size; // LEGAL
x.size = 3; // LEGAL
x.h(42); // LEGAL
};
int main() {
small x, y;
x=y; // LEGAL
x.size = y.size; // ILLEGAL
x.size = 3; // ILLEGAL
x.h(42); // LEGAL
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.