c++ language structures and pointers

User Generated

Gnanf

Programming

Description

1. You have a struct defined as

struct Coordinate
{
int x;
int y;
};

And you have variables defined from it:

Coordinate point1;
Coordinate point2;

Show just the code needed to access the y value of point2.

2.

The formula to find the distance between two points is:

distance.PNG

Using the struct definition in the previous questions, show the code needed to find the distance between point1 and point2, using cmath functions as needed.

Show just the line of code to produce the distance - do not show any include statements or an entire program.

3.

A pointer is a variable that contains a value that is

4.

How would you use the parameter f in the body of this function to access the numerator field?

void reduce(Fraction &f)

{

}

5.

The function argument in the previous question is defined as a

6.

You have this definition:

struct FractionArray
{
Fraction *fractions;
int nFractions;
};

And these statements:

FractionArray fractions;

fractions.nFractions = 100;

fractions.fractions = new Fraction[fractions.nFractions];

Using the new operator as in the code above means that you are

7.

Once you dynamically allocate memory, and you no longer need it to use it, what do you do?

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Here are the answers. Please let me know if you have any questions.

1. po...


Anonymous
Excellent resource! Really helped me get the gist of things.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags