Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following class declaration: class Point public: void showPoint() c

ID: 3806994 • Letter: C

Question

Consider the following class declaration: class Point public: void showPoint() const: Point(); Point(int, int): int xlocation: int ylocation:}: 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. int main() {Point.xlocation = 3; Point.ylocation = 10; Point p1; p1 = Point(5, 6); Point p2(); return 0:} 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

a. Describe the problem (if any) with the statements in lines 3, and 4:
Yes there is a problem with these lines.
xlocation and ylocation variables are not static, and therefore, should
be associated with an instance of class Point. Here Point is a class,
and is not associated with an instance. Therefore, will not work.

b. Describe (in detail) what the statement in line 7 does.
A default constructor should not be called with parentheses. Assuming the parentheses
is removed Point p2; will create an object p2 of class type Point by calling the
default constructor Point().

c. What is the problem (if any) with the statement in line 9
(assuming you are trying declare an instance of the point class)?
Line 9 is the end of main(), and there is no problem with that line.
If you're talking about line 6, it is defining an object p1 with specified values,
by calling the parameterized constructor.
If you're talking about line 7, there is a problem here, a variable without
parentheses will declare the default constructor, whereas, if you give parentheses
to a p2, it will be considered as a function, which takes no parameters.

d. What does the statement in line 9 currently declare?
Line 9 is the end of main(), and it doesn't declare anything.
If you 're talking about line 6, it is defining an object p1 with specified values,
by calling the parameterized constructor.
If you're talking about line 7, it is currently declaring a function p2 with no parameters.

e. Rewrite the statement in line 9, to declare the default instance of the Point class.
If you're talking about line 6, we can simply do that by:
p1 = Point();
If you're talking about line 7, it can be done in 2 ways:
Point p2; will do the needful.
Point p2 = new Point(); will also do the same.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote