Point.h
#pragma once
#include <iostream>
using namespace std;
class Point
{
private:
int x;
int y;
public:
Point(void);
Point( int x, int y );
Point( const Point &xPoint );
~Point(void);
void setX( int x ) { x = x; }
int getX() const { return x; }
void setY( int y ) { y = y; }
int getY() const { return y; }
Point & operator = ( const Point &xPoint );
bool operator == ( const Point &xPoint ) const;
bool includes( int cord_X, int cord_Y ) const;
bool includes( const Point &xPoint ) const;
void draw() const;
};
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
Point.cpp
#include "Point.h"
Point::Point( void )
{
this->x = 0;
this->y = 0;
}
Point::Point( int x, int y )
{
this->x = x;
this->y = y;
}
Point::Point( const Point &xPoint )
{
this->x = xPoint.x;
this->y = xPoint.y;
}
Point::~Point( void ) {} // Destructor
Point &Point::operator = ( const Point &xPoint )
{
if( this != &xPoint )
{
this->x = xPoint.x;
this->y = xPoint.y;
}
return ( *this );
}
bool Point::includes( int cord_X, int cord_Y ) const
{
return ( this->x == cord_X && this->y == cord_Y );
}
void Point::draw() const
{
cout << '.';
}
bool Point::operator == ( const Point &xPoint ) const
{
bool isEquality = false;
if( this->x == xPoint.x && this->y == xPoint.y )
{
isEquality = true;
}
return isEquality;
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
PointCollection.h
#pragma once
#include "Point.h"
const int MAXPoint = 100;
class PointCollection
{
private:
Point pts[ MAXPoint ];
int quantity;
public:
PointCollection( void );
PointCollection( const PointCollection &xPointCollection );
~PointCollection( void );
// To know how many Points are
// ..in the collection
int size() const;
PointCollection operator = ( const PointCollection &xPointCollection );
PointCollection &operator + ( const Point &xPoint );
Point &operator[]( int index );
const Point &operator[]( int index ) const;
bool isFull() const;
bool isEmpty() const;
bool includes( const Point &xPoint ) const;
int indexOf( const Point &xPoint ) const;
};
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
PointCollection.cpp
#include "PointCollection.h"
PointCollection::PointCollection( void )
{
this->quantity = 0;
}
PointCollection::PointCollection( const PointCollection &xPointCollection )
{
this->quantity = xPointCollection.quantity;
for ( int i = 0 ; i < this->quantity ; i++ )
( this->pts )[ i ] = ( xPointCollection.pts )[ i ];
}
PointCollection::~PointCollection( void ) {}
int PointCollection::size() const
{
return ( this->quantity );
}
Point &PointCollection::operator []( int index )
{
return ( ( this->pts )[ index ] );
}
const Point &PointCollection::operator []( int index ) const
{
return ( ( this->pts )[ index ] );
}
PointCollection PointCollection::operator =( const PointCollection &xPointCollection )
{
this->quantity = xPointCollection.quantity;
for ( int i = 0 ; i < this->quantity ; i++ )
( this->pts )[ i ] = ( xPointCollection.pts )[ i ];
return ( *this );
}
PointCollection &PointCollection::operator +( const Point &xPoint )
{
(*this)[ this->quantity ] = xPoint;
(this->quantity)++;
return ( *this );
}
bool PointCollection::isFull() const
{
return ( this->quantity == MAXPoint );
}
bool PointCollection::isEmpty() const
{
return ( this->quantity == 0 );
}
bool PointCollection::includes( const Point &xPoint ) const
{
bool thisOne = false;
for ( int i = 0 ; i < this->quantity && ! thisOne ; i++ )
{
if( pts[ i ] == xPoint )
thisOne = true;
}
return ( thisOne );
}
int PointCollection::indexOf( const Point &xPoint ) const
{
int index = -1;
for ( int i = 0 ; i < this->quantity && index == -1 ; i++ )
{
if( pts[ i ] == xPoint )
index = i;
}
return ( index );
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
Page.h
#pragma once
#include "PointCollection.h"
const int MAXPAGE = 100;
class Page
{
private:
int heigh;
int width;
public:
Page( void );
Page( int width, int heigh );
Page( const Page &xPage );
~Page( void );
void setWidth( int width ) { width = width; }
int getWidth() const { return width; }
void setHeigh( int heigh ) { heigh = heigh; }
int getHeigh() const { return heigh; }
bool operator == ( const Page &xPage ) const;
void draw() const;
};
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
Page.cpp
#include "Page.h"
Page::Page( void )
{
this->width = 0;
this->heigh = 0;
}
Page::Page( int width, int heigh )
{
this->width = width;
this->heigh = heigh;
}
Page::Page( const Page &xPage )
{
this->width = xPage.width;
this->heigh = xPage.heigh;
}
Page::~Page( void ) {}
void Page::draw() const
{
bool included;
PointCollection pc;
for( int y = 0 ; y < this->heigh ; y++ )
{
included = false;
for ( int x = 0; x < this->width ; x++ )
{
for ( int p = 0 ; p < pc.size() && !included ; p++ )
{
if ( pc[ p ].includes( x, y ) )
{
pc[ p ].draw();
included = true;
}
if ( included )
cout << ' ';
}
}
cout << endl;
}
}
bool Page::operator ==( const Page &xPage ) const
{
bool isEquality = false;
if( this->heigh == xPage.heigh && this->width == xPage.width )
{
isEquality = true;
}
return isEquality;
}
Main.cpp
#include "Page.h"
int main ()
{
Point p1( 5, 5 ), p2( 1, 1 );
Page pg( 15, 15 );
p1.draw();
pg.draw();
system("PAUSE");
return 0;
}
The Program Compiles but The problem is when i try to print the dot in the console using.p1.draw() it only prints a single dot in the console and not in the location that i want it to be printed...