Point.h

``````#prag...
#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 );
int getX() const;

void setY( int y );
int getY() const;

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

``````#prag...
#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 ) {}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

void Point::setX( int x ) // set X
{
this->x = x;
}

void Point::setY( int y ) // set Y
{
this->y = y;
}

int Point::getX() const // get X
{
return ( this->x );
}

int Point::getY() const // get Y
{
return ( this->y );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

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

``````#prag...
#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

``````#prag...
#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 );
}``````

Line.h

``````#prag...
#pragma once

#include "Point.h"

class Linea
{
private:
Point begin;
Point end;

public:
Linea( void );
Linea( const Linea &xLinea );
Linea( Point XY1, Point XY2 );
~Linea( void );

Linea &operator = ( const Linea &xLinea );

bool includes( int cord_X, int cord_Y ) const;
bool operator == ( const Linea &xLinea ) const;

double m() const; // Pendiente
double b() const; // Intercept in Y

bool isVertical() const;
bool isHorizontal() const;
bool isDiagonal() const;

void draw() const;
};``````

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

Line.cpp

``````#prag...
#include "Linea.h"

Linea::Linea()
{
}

Linea::Linea( Point XY1, Point XY2 )
{
this->begin = begin;
this->end = end;
}

Linea::Linea( const Linea &xLinea )
{
this->begin = xLinea.begin;
this->end = xLinea.end;
}

Linea::~Linea( void )
{
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

Linea &Linea::operator =( const Linea &xLinea )
{
if( this != &xLinea )
{
this->begin = xLinea.begin;
this->end = xLinea.end;
}

return ( *this );
}

bool Linea::operator == ( const Linea &xLinea ) const
{
bool isEquality = false;
if( this->begin == xLinea.begin &&
this->end == xLinea.end )
{
isEquality = true;
}
return isEquality;
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

double Linea::m()const
{
return ( (this->end.getY()) - (this->begin.getY()) ) / ((this->end.getX()) - (this->begin.getX()) );
}

double Linea::b()const
{
return ( this->end.getY() - (this->m() * this->end.getX()) );
}

bool Linea::isVertical () const
{
return ( ( (this->end.getX()) - (this->begin.getX()) ) == 0 );
}

bool Linea::isHorizontal () const
{
return ( ( (this->end.getY()) - (this->begin.getY()) ) == 0 );
}

bool Linea::isDiagonal () const
{
return ( this->isVertical() && this->isHorizontal() );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

bool Linea::includes( int cord_X, int cord_Y ) const
{
bool included = false;

if ( this->isHorizontal() )
{
if ( ( (this->begin).getY() == cord_Y ) &&

( (this->begin).getX() <= cord_X ) &&

( (this->end).getX() >= cord_X ) ||

( (this->begin).getX() >= cord_X ) &&

( (this->end).getX() <= cord_X ) )

included = true;
}

else if ( this->isVertical() )
{
if ( ( (this->begin).getX() == cord_X ) &&

( (this->begin).getY() <= cord_Y ) &&

( (this->end).getY() >= cord_Y ) ||

( (this->begin).getY() >= cord_Y ) &&

( (this->end).getY() <= cord_Y ) )

included = true;
}

else
{
if ( ( cord_Y == this->m() * cord_X + this->b() ) &&

( (this->begin).getX() <= cord_X ) &&

( (this->end).getX() >= cord_X ) ||

( (this->begin).getX() >= cord_X ) &&

( (this->end).getY() >= cord_Y ) ||

( (this->begin).getY() >= cord_Y ) &&

( (this->end).getY() <= cord_Y ) )

included = true;
}

return ( included );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

void Linea::draw() const
{
cout << '.';
}``````

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

LineCollectoin.h

``````#prag...
#pragma once

#include "Linea.h"

const int MAX = 100;

class LineCollection
{
private:
Linea lc[ MAX ];
int quantity;

public:
LineCollection(void);
LineCollection( const LineCollection &xLineCollection );
~LineCollection(void);

// To know how many Lines are
// ..in the collection
int size() const;

LineCollection operator = ( const LineCollection &xLineCollection );

LineCollection &operator + ( const Linea &xLinea );

Linea &operator [] ( int index );
const Linea &operator[]( int index ) const;

bool isFull() const;
bool isEmpty() const;

bool includes( const Linea &xLinea ) const;
int indexOF( const Linea &xLinea ) const;

friend ostream &operator << ( ostream &output, const LineCollection &xLineCollection );
friend istream &operator >> ( istream &input, LineCollection &xLineCollection );
};``````

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

LineCollection.cpp

``````#prag...
#include "LineCollection.h"

LineCollection::LineCollection( void )
{
this->quantity = 0;
}

LineCollection::LineCollection( const LineCollection &xLineCollection )
{
this->quantity = xLineCollection.quantity;

for ( int i = 0 ; i < this->quantity ; i++ )
( this->lc )[ i ] = ( xLineCollection.lc )[ i ];
}

LineCollection::~LineCollection( void ) {}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

int LineCollection::size() const
{
return ( this->quantity );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

Linea &LineCollection::operator []( int index )
{
return ( ( this->lc )[ index ] );
}

const Linea &LineCollection::operator []( int index ) const
{
return ( ( this->lc )[ index ] );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

LineCollection LineCollection::operator =( const LineCollection &xLineCollection )
{
this->quantity = xLineCollection.quantity;

for ( int i = 0 ; i < this->quantity ; i++ )
( this->lc )[ i ] = ( xLineCollection.lc )[ i ];

return ( *this );
}

LineCollection &LineCollection::operator +( const Linea &xLinea )
{
(*this)[ this->quantity ] = xLinea;
(this->quantity)++;

return ( *this );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

bool LineCollection::isFull() const
{
return ( this->quantity == MAX );
}

bool LineCollection::isEmpty() const
{
return ( this->quantity == 0 );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

bool LineCollection::includes(const Linea &xLinea) const
{
bool thisOne = false;

for ( int i = 0 ; i < this->quantity && ! thisOne ; i++ )
{
if ( lc[i] == xLinea )
thisOne = true;
}
return ( thisOne );
}

int LineCollection::indexOF( const Linea &xLinea ) const
{
int index = -1;

for ( int i = 0 ; i < this->quantity && index == -1 ; i++ )
{
if ( lc[i] == xLinea )
index = i;
}

return ( index );
}``````

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

Page.h

``````#prag...
#pragma once

#include "PointCollection.h"
#include "LineCollection.h"
#include "RectangleCollection.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 );
int getWidth() const;

void setHeigh( int heigh );
int getHeigh() const;

bool operator == ( const Page &xPage ) const;

void draw() const;

Page &operator [] ( int index );
const Page &operator[]( int index ) const;
};``````

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

Page.cpp

``````#prag...
#include "Page.h"

Page::Page( void )
{
this->width = 0;
this->heigh = 0;
//int quantity = 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::setHeigh( int heigh )
{
this->heigh = heigh;
}

void Page::setWidth( int width )
{
this->width = width;
}

int Page::getHeigh() const
{
return ( this->heigh );
}

int Page::getWidth() const
{
return ( this->width );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

void Page::draw() const
{
bool included;
PointCollection pc;
LineCollection li;
RectangleCollection rec;

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 << ' ';
}

for ( int line = 0 ; line < li.size()  && !included ; line++ )
{

if ( li[ line ].includes( x, y ) )
{
li[ line ].draw();
included = true;
}

if ( included )
cout << ' ';
}

for ( int r = 0 ; r < rec.size() && !included ; r++ )
{
if ( rec[ r ].includes( x, y ) )
{
rec[ r ].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

``````#prag...
#include "Page.h"

int main ()
{

Point p1( 5, 5 ), p2( 1, 1 );
Linea L;
Page pg( 15, 15 );

p1.draw();

L.draw();

L + p1;

pg.draw();

/*
if ( p1.includes( 1, 1 ) == true )
cout << "Point 1 & 2 are Equal" << "\n\n";
else
cout << "Point 1 & 2 are NOT Equal" << "\n\n";
*/

system("PAUSE");
return 0;

}``````

------ Build started: Project: Project_Dibujo, Configuration: Debug Win32 ------
Compiling...
Main_.cpp
c:\documents and settings\mpayne007\desktop\december 19333 update\project_dibujo\project_dibujo\main_.cpp(15) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'Point'
c:\program files\microsoft visual studio 8\vc\include\xstring(438) : see declaration of 'std::operator +'
c:\documents and settings\mpayne007\desktop\december 19333 update\project_dibujo\project_dibujo\main_.cpp(15) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'Point'
c:\program files\microsoft visual studio 8\vc\include\xstring(298) : see declaration of 'std::operator +'
c:\documents and settings\mpayne007\desktop\december 19333 update\project_dibujo\project_dibujo\main_.cpp(15) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'Point'
c:\program files\microsoft visual studio 8\vc\include\xutility(1809) : see declaration of 'std::operator +'
c:\documents and settings\mpayne007\desktop\december 19333 update\project_dibujo\project_dibujo\main_.cpp(15) : error C2676: binary '+' : 'Linea' does not define this operator or a conversion to a type acceptable to the predefined operator
Generating Code...
Compiling...
RectangleCollection.cpp
Generating Code...
Skipping... (no relevant changes detected)
Linea.cpp
LineCollection.cpp
NoteBook.cpp
Page.cpp
Rectangle.cpp
Build log was saved at "file://c:\Documents and Settings\MPayne007\Desktop\December 19333 Update\Project_Dibujo\Project_Dibujo\Debug\BuildLog.htm"
Project_Dibujo - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

## Featured Replies in this Discussion

• You are not moving the cursor at right place before you do a "cout" Ycan move cursor by including one more function in your point class in point.h add a member funtion in the point class ... in point .cpp add following. ... use it in your draw member function ...
Post Contains: Code

No, you didn't overload it. `L` is type `Linea` . `p1` is type `Point` .
Neither of these classes overload the "+" operator.

By the way, `L + p1;` is read as "sum L and p1 and throw away the result."

It should be something like: `L = L + p1;` or: `L += p1;` Hope this helps.

I need help on how to do the overloading in Linea and Point ?

Here's for Point

``````Point Point::operator +(const Point &xPoint) const
{
Point P;

P.x = this->x + xPoint.x;
P.y = this->y + xPoint.y;

return ( P );
}``````

Is this right ? because it doesn't work ? I did the same for linea.

Overloading only works when there is a function taking arguments of the exact same type as the things you are trying to operate on.

Since `L + p1;` is saying "add a Point (the type of p1) to a Linea (the type of L)" you must have an overloaded function specifically for handling these two things. For example: `Linea &Linea::operator + ( Point &p )` That is, it is a function which overloads adding a Point to a Line.

I am wondering, do you mean to be adding a point to a Linea, or to a PointCollection? A Linea only has two points ("begin" and "end"), so adding a Point to it doesn't seem to make much sense. What exactly are you trying to do?

I have been stuck trying to do this simple program for a month now. I'm hopeless.

All i need to do is draw some dots and lines in a page. So far Every time i try to print 3 different dots in different coordinates in the page it just prints 3 consecutive dots.

What am I doing Wrong ? Can you help me out by writing what's missing ?

It appears that you are trying to do ASCII graphics. Is that right?

To me you appear to be trying to draw a collection of '.' to the console (or page or grid or even a file---the latter so you could print it on paper if you wanted). However, at the moment Point.draw() and Linea.draw() just output a single '.' at the current location on the console, not at specified locations on the console. If my assumption is correct, then you're going to need to develop a routine to place each of the dots in the desired location within a page/grid and then print the page/grid to the console/file. To accomplish this I would set up a 2 d array of spaces as the default. Then I'd put a '.' in the desired elements of the 2d array such that they represent a Point or a Line, etc. Then I'd just print out the entire page as a single unit and not try to print out each individual Point or Line.

``````Example:
A Line called line with the following begin/end values
line.begin.X = 2;
line.begin.Y = 1;
line.end.X = 5;
line.end.Y = 1;

line placed on a Page defined as char grid[10][10];

//put "Points" in line on the grid
for(int i = line.begin.X; i < line.end.X; i++)
for(int j = line.begin.Y; j < line.end.Y; ++j)
grid[i][j] = '.';

//display the grid, which will show line on the console
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
cout << grid[i][j];``````

The only problem then is, does a line with begin at (2,1) and end at (5,1) have 3 '.' (5-2 == 3) or 4 '.' (representing (2,1) (3,1) (4,1) (5,1)). The difference will deteremine whether you use < or <= in the placement to the grid routine. I arbitrarally chose the former, but the latter is valid as well.

Still cant figure it out.

What do i put in the main() function that will let me print points and lines anywhere in the page i want ?

to rephrase what lerner already said{and add a little sugar!} if you want to output to screen {a line, a dot or whatever} you must use directly the OS's api or some framework thats supports graphics like Qt , MFC or .NET..... On the other hand if you just want to print a line in the console {for educational purposes i guess} you should have a 2dimensional character array `char grid[10][10]` initialized with zeros do all the changes in this array and then output the whole array in the console {that wouldbe a primitive ascii art}

hope that helped
-nicolas

Here's as basic a program as I can write that creates Points and Lines, places them on a Page, and prints the Page, which may contain 0 or more Points or Lines, to the screen. This isn't how I would submit it to an instructor, but it get's the job done. You can embelish it to your hearts content.

``````#include <iostream>

using namespace std;

struct Point
{
int X;
int Y;
};

struct Line
{
Point begin;
Point end;
};

struct Page
{
char grid[10][10];
Page();
void placePointOnGrid(Point);
void placeLineOnGrid(Line);
void draw();
};

Page::Page()
{
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
grid[i][j] = ' ';
}

void Page::placePointOnGrid(Point p)
{
grid[p.X][p.Y] = '.';
}

void Page::placeLineOnGrid(Line line)
{
int i, j;
if(line.begin.X == line.end.X) //horizontal
{
i = line.begin.X;
for(j = line.begin.Y; j <= line.end.Y; ++j)
grid[i][j] = '.';
}
else if(line.begin.Y == line.end.Y) //vertical
{
j = line.begin.Y;
for(i = line.begin.X; i <= line.end.X; ++i)
grid[i][j] = '.';
}
}

void Page::draw()
{
for(int i = 0; i < 10; ++i)
{
for(int j = 0; j < 10; ++j)
{
cout << grid[i][j];
}
cout << endl;
}
}

int main()
{
Page page;

Point pt;
pt.X = 7;
pt.Y = 7;

page.placePointOnGrid(pt);

Line line;
line.begin.X = 2;
line.begin.Y = 2;
line.end.X = 2;
line.end.Y = 5;

page.placeLineOnGrid(line);

line.begin.X = 0;
line.begin.Y = 0;
line.end.X = 9;
line.end.Y = 0;

page.placeLineOnGrid(line);

page.draw();

char ch;
cin >> ch;

return 0;
}``````

Here's a shorter version of the code, without the Line.

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 );
int getX() const;

void setY( int y );
int getY() const;

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 ) {}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

void Point::setX( int x ) // set X
{
this->x = x;
}

void Point::setY( int y ) // set Y
{
this->y = y;
}

int Point::getX() const // get X
{
return ( this->x );
}

int Point::getY() const // get Y
{
return ( this->y );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

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 );
int getWidth() const;

void setHeigh( int heigh );
int getHeigh() const;

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::setHeigh( int heigh )
{
this->heigh = heigh;
}

void Page::setWidth( int width )
{
this->width = width;
}

int Page::getHeigh() const
{
return ( this->heigh );
}

int Page::getWidth() const
{
return ( this->width );
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

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;

}``````

This has nothing to do with Graphics.

I only want p1.draw() to be printed on the location ( 5, 5 ) ( x, y ) in the page.

You are not moving the cursor at right place before you do a "cout"
Ycan move cursor by including one more function in your point class
in point.h
add a member funtion in the point class

``void gotoxy(int , int ) const ;``

``````void Point::gotoxy(int x, int y) const
{
HANDLE hConsoleOutput;
COORD Cursor_Pos = {x, y};

hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, Cursor_Pos);
}``````

use it in your draw member function

``````void Point::draw() const
{
gotoxy(x,y);
cout<<".";
}``````
I have to admit this, it is hell alot of code to read, and you manage to solve it.
Solved a problem a lot of people couldn't solve.

Thank You Very much. I can't begin to express my gratitude for helping me out on this. Now i can add the rest of my classes without any problem.

Thank You. :icon_smile:

Cheers...

Question Answered as of 7 Years Ago by Duoas, Lerner, dubeyprateek and 1 other
You