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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started