Point Test #1


Program Listings

PointTest1.cpp

/************************************************************************
*                                                                       *
*   Program:    PointTest1.cpp                                          *
*                                                                       *
************************************************************************/

//  Header files

#include <iostream>
#include <string>
#include "point1.h"

using namespace std;

/************************************************************************
*                                                                       *
*   Function:   main                                                    *
*                                                                       *
************************************************************************/

int main() {

//  Test the constructors and the output operator

    cout << "Test the constructors and the output operator" << endl;
    point P;            // Test the default constructor
    point Q(2, 3);      // Test the other constructor
    point R = Q;        // Test the copy constructor

//  Test the assignment operator

    cout << endl << "Test the assignment operator" << endl;
    cout << "Assign Q to P:  ";
    P = Q;                          // Test the assignment operator
    
    cout << endl << "Good-bye" << endl;
    
    return 0;
}

point1.h

/************************************************************************
*                                                                       *
*   File:       point1.h                                                *
*                                                                       *
*   Author:     Robb T. Koether                                         *
*                                                                       *
*   Date:       Oct 19, 1999                                            *
*                                                                       *
*   Abstract:   This file contains the definition of the point class    *
*               and related operators                                   *
*                                                                       *
*   Note:       This definition includes only the constructors          *
*                                                                       *
************************************************************************/

#ifndef POINT_H
#define POINT_H

//  Header files

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

/************************************************************************
*                                                                       *
*   Definition of the point class                                       *
*                                                                       *
************************************************************************/

class point {

    public:

    //  Constructors

        point();                        // Default constructor
        point(double x, double y);      // Construct point from 2 doubles

    private:

        double xval;        // x-coordinate of the point
        double yval;        // y-coordinate of the point
};

#endif

Point1.cpp

/************************************************************************
*                                                                       *
*   File:       Point1.cpp                                              *
*                                                                       *
*   Author:     Robb T. Koether                                         *
*                                                                       *
*   Date:       Oct 19, 1999                                            *
*                                                                       *
*   Abstract:   This file implements the member functions and           *
*               operators of the point class                            *
*                                                                       *
*   Note:       This definition includes only the constructors          *
*                                                                       *
************************************************************************/

//  Header files

#include "point1.h"

/************************************************************************
*                                                                       *
*   CONSTRUCTORS                                                        *
*                                                                       *
************************************************************************/

/************************************************************************
*                                                                       *
*   Function:   point()                                                 *
*                                                                       *
*   Purpose:    To construct the default point (0, 0)                   *
*                                                                       *
************************************************************************/

point::point() {
    xval = 0;
    yval = 0;
    return;
}

/************************************************************************
*                                                                       *
*   Function:   point(double, double)                                   *
*                                                                       *
*   Purpose:    To construct a point with the specified x- and          *
*               y-coordinates                                           *
*                                                                       *
************************************************************************/

point::point(double x, double y) {
    xval = x;
    yval = y;
    return;
}

Sample Run

Test the constructors and the output operator

Test the assignment operator
Assign Q to P:  
Good-bye



Return to Lectures page


e-mail me at robbk@hsc.edu

This page was last modified on Tue Dec 7 16:04:44 1999 .

URL: http://people.hsc.edu/faculty-staff/robbk/Coms261/Examples/PointTest1.html

Return to Coms 261 home page