1. Fill in the blanks in each of the following 1) A class is an encapsulation of
ID: 3912102 • Letter: 1
Question
1. Fill in the blanks in each of the following 1) A class is an encapsulation of and inge data _ structure 2) A declaration ispeded to declare an object ofa classtype. It 3) The declared items in the 4) Member functions of a class are normally madeand data members of a-l Find the error(s) in each of the following and explain how to correct it causes a to execute. part ofa class may not be directly accessed outside the class. Those in thearre accessible outside the class. -part are accessible outside the class class are normally made 2. 1) Assume the followng prototype is declared in class Tme oid -Tima int ) 2) The following is a partial definition of class Time Public: // funetian prototypaa private: int ho 02 int minuta 0 int aacond 0 1 2Explanation / Answer
2.
Explanation:
1) void -Time(int) --->is invalid because function name should not start with a character other than alphabet or '_'(underscore)
For example: void _Time(int) is valid
void time(int) is valid
void -Time(int) isinvalid
Note: You cannot write class name as a function prototype
Example:
class Time{
public:
void Time(int);
}
**Compilation of above code gives an error.
2)
Explanation:
int hour-0; ----> is invalid because variable name should not contain any special character other than '_'(underscore).It can have alphabets(upper and lower), digits and underscore. It is also invalid to start variable name with digits.
For example:
int 1hour; ---> it is invalid
int _hour; ----> it is valid
int hour_1 ; ---->it is valid
int hour1; ------> it is valid
Hence change the variable names as above said conditions.
Re writing the given class.
class Time{
public:
void _Time(int);
private:
int hour_0;
int minute_0;
int second_0;
};
The above code compiles without any error.
Please like my answer if you are satisfied with it.thanks!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.