Re: Pointer work around

new topic     » goto parent     » topic index » view thread      » older message » newer message

--part0_915900581_boundary
Content-ID: <0_915900581 at inet_out.mail.aol.com.1>
Content-type: text/plain; charset=US-ASCII

Here is a simple C++ prog that uses pointers, i put in comments but if there
are any questions feel free to ask.

--part0_915900581_boundary
Content-ID: <0_915900581 at inet_out.mail.aol.com.2>
Content-type: text/plain;
        name="POINTER.CPP"
Content-transfer-encoding: quoted-printable
Content-disposition: inline

// Pointer example.
#include <iostream.h>
#include <math.h>
#include <complex.h>

typedef struct
=09{
=09=09int X, Y;
=09} Point;

double Slope(Point First, Point Second);

void main()
{
=09Point P[2] //Declares an array of two sets of points.
=09Point *PP; //Declares a pointer to a point.

=09PP =3D new Point; //Initiallizes pointer.
=09PP =3D &P[0]; //Sets pointer to equal the first point in P.
=09cout << "X1: ";
=09cin >> PP->X; //Gets the value of X1 with the pointer.
=09cout << "Y1 :";
=09cin >> PP->Y; //Gets the value of Y1 with the pointer.
=09PP++;  //Sets the pointer to equal the second point in P.
=09cout << "X2 :";
=09cin >> PP->X; //Gets the value of X2 with the pointer.
=09cout << "Y2 :";
=09cin >> PP->Y; //Gets the value of Y2 with the pointer.
=09cout << "The slope of the line between (X1, Y1) and (X2, Y2) is "
=09cout << Slope(P[0], P[1]) << ".";  //Finds the slope with the actual a=
rray.

}

double Slope(Point One, Point Two)
{
=09return ((Two.Y - One.Y)/(Two.X - One.X));
}


--part0_915900581_boundary--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu