Question: EXERCISES FOR C++ 1) Declare a pointer to an integer. Declare an integer say month. Use the pointer to change month to 1 then output

EXERCISES FOR C++

1) Declare a pointer to an integer. Declare an integer say month. Use the pointer to change month to 1 then output the result. You must use the pointer for all of your code. Also properly initialize the pointer.

2) Use the Point class to declare 2 Point objects (could be of any x,y) and 2 pointers to those objects. Declare a double variable to represent the distance between the two points. Compute the distance using the pointers. Hint: distance = sqrt ( (x2-x1)2 + (y2-y1)2 ). Must use the pointers in your calculation.

3) Assuming the following fragment of code:

int day = 21;

int month = 9;

int * p1 = NULL;

int * p2 = NULL;

int * p3 = NULL;

p1 = &day;

p2 = &month;

p3 = p1;

p1 = p2;

p3 = p2;

p1 = NULL;

Draw diagram of day, month, p1, p2, and p3 similar to the diagram shown in section "Pointers to double" in sub-module "Pointer to primitive data types".

The purpose is to show the changes of the pointers after each statement is executed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!