Given the program, which of the following class member accesses are legal?

```
#include using namespace std; class DayOfYear { public: void input(); void output(); // other public members private: int month; int day; // other private members
}; int main() {
DayOfYear birthDay;
birthDay.input(); // a)
birthDay.day = 25; // b)
cout << birthDay.month; // c)
cout << birthDay.output(); // d)
if(birthDay.month == 1) // e)
cout << "January\n";
}
```


Actual compiler error messages follow:
```
Error b): 'DayOfYear::day' is not
accessible in function main()
Error c): 'DayOfYear::month' is not
accessible in function main()
Error e): 'DayOfYear::month' is not
accessible in function main()
```

The declaration of birthDay as a DayOfYear object is OK. a) and d) are accesses to a public input and output functions. b) attempts to write a private member, c) and e) attempt to fetch a value from a private member month. In d), output is public, so d) is OK

Computer Science & Information Technology

You might also like to view...

Identify four high-level functions that are required for a proper evaluation program.

What will be an ideal response?

Computer Science & Information Technology

A keyword is recognized as part of the ____ definition.

A. language B. method C. property D. parameter

Computer Science & Information Technology

Items passed to a function are always placed within the function name parentheses and are called ____.

A. variables B. data types C. identifiers D. arguments

Computer Science & Information Technology

Within an if or an else statement, how can you code as many dependent if statements as you need and why is this useful?

What will be an ideal response?

Computer Science & Information Technology