------------------------------------------------------------------------------
MC logo
Point User File
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Point Hdr File] [Point Impl File] [Point User File] [Point Class Hdr File] [Point Class Impl File] [Point Class User File] [C++ Integer Stack ADT] [C++ Integer Stack Implementation] [C++ Integer Stack Driver]
cpointu.cpp
/*
 * Driver program for the struct point ADT.
 */

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

using namespace std;

// Print a line of the form x op y = z, where x, y, and z are points. 
void prline(Point x, string op, Point y, Point z)
{
        print(x);
        cout << " " << op << " ";
        print(y);
        cout << " = ";
        print(z);
        cout << endl;
}

main() 
{
        // Some points.
        Point a = mkpt(5.2, -4.8);
        Point b = mkpt(3.0, 9.0);
        Point c = mkpt(-3.38, 0.0);
        Point d = mkpt(0.0, 0.0);

        // Some arith. on the points.
        d = sub(b, c);
        prline(b, "-", c, d);
        prline(a, "+", b, add(a, b));
        print(a); 
        cout << " is " << dist(a,d) << " from "; 
        print(d); 
        cout << endl;

        // Point variables are not references.
        Point fred[5];
        int m;
        for(m = 0; m < 5; m++) fred[m] = a;
        double w = 4.5;
        double x = -2.31;
        for(m = 0; m < 5; m++) {
                move(&fred[m], w, x);
                w += 3.4;
                x -= 1.3;
        }
        for(m = 0; m < 5; m++) {
                print(fred[m]);
                cout << endl;
        }
}