C Programming 1 Consider the following class declaration 1 c
C++ Programming:
1) Consider the following class declaration:
1 class Point
2 { public:
3 void showPoint( ) const;
4 Point( );
5 Point(int, int);
6 int xlocation;
7 int ylocation;
8 } ;
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
2) Now consider the following code segment, assuming the Point class definition from above, and answer the questions below.
1 int main( )
2 {
3 Point.xlocation = 3;
4 Point.ylocation = 10;
5 Point p1;
6 p1 = 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:
Solution
Answer:
 a. Here const means that this function is not allowed modify the object on which they are called.
 b. line 4
 c. Yes. The data members are allowed for direct access in main, since they are public and also accessible by member functions. So they will work.
 d.
 e. Point::Point (int x, int y)
 {
 xlocation=x;
 ylocation=y;
 }
 2.
 a) Yes. The problem is , the members of the class is not accessible using the class
 name. we have to create an object for the class. Using the object, we can access the public members.
 So modify the program as follows:
 1 int main( )
 2 {
 3 Point point;
 4 point.xlocation = 3;
 5 point.ylocation = 10;
 6 Point p1;
 7 p1 = Point(5,6);
 8 p1.showPoint();
 9 Point p2( );
 10 return 0;
 11 }
 b. line 7 is p1 = Point(5,6); It assigns p1\'s xlocation as 5 and y location as 6
 c.
 d. Line 9 currently declares
 e. Point p2;


