Consider the following class declaration: 1 class Point 2 (public: 3 void show P
ID: 3806933 • Letter: C
Question
Consider the following class declaration: 1 class Point 2 (public: 3 void show Point() const: 4 Point(); 5 Point(int, int) 6 int x location 7 int location; a. What does the const keyword signify in line 3? b. Which line contains the default constructor for the class? c. The data members are declared public. Will this work? d. Would this be a good idea or not for a large program? e. Write the function definition for the constructor declared in line 5 Now consider the following code segment, assuming the Point class definition from above, and answer the questions below. 1 int main() 2 { 3 Point x location = 3; 4 Pointy location = 10; 5 Point p1; 6 pl = Point(5,6): 7 Point p2(): 8 return 0: 9) a. Describe the problem (if any) with the statements in lines 3 and 4. b. Describe (in detail) what the statement in line 7 does (consult your textbook): c)What is the problem (if any) with the statement in line 9 (assuming you are trying to declare an instance of the point class? d. What does the statement in line 9 currently declare? e. Rewrite the statement in line 9 to declare a default instance of the Point class:Explanation / Answer
1)
a)it signifies that this function cannot modify the member variables of the object, unless they are declared as mutable.
example:
mutable int xlocation;
b)line 4
c)yes, it will work, this means all members will be accessed out side of the class
d)when you want to protect or private some members then it will not be good idea, because every will be modified outside of the class, if it doesn't matters then it is fine
e)
Point(int a,int b)
{
xlocation =a;
ylocation =b;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.