Printing Dots in specific Locations in the Console ?


 
Thread Tools Search this Thread
Top Forums Programming Printing Dots in specific Locations in the Console ?
# 1  
Old 01-13-2008
Error Printing Dots in specific Locations in the Console ?

Point.h

Code:
#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

Code:
#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

Code:
#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

Code:
#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

Code:
#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

Code:
#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

Code:
#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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to delete empty files from specific locations

Hi, I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through... (4 Replies)
Discussion started by: Khan28
4 Replies

2. Shell Programming and Scripting

Printing a specific number of spaces

when given a file name, im looking for the most efficient way to turn each letter of the file name into spaces. for instance, the way im thinking of going about this is this: MYFILE=check_disks.sh CHANUM=$(echo ${MYFILE} | awk '{ print length }') printf '%s\n' $CHANUM as you can see... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies

4. UNIX for Dummies Questions & Answers

Printing files in a specific format

Hi, I have following files in a directory with '.meta' extension, which have data in follwoing patterns. i need to print data from these files in below metioned format. please provide a script for this solution. file names: TEST_HISTORY_MTH.meta AB_TEST_1.meta cat... (2 Replies)
Discussion started by: AAHinka
2 Replies

5. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

6. Shell Programming and Scripting

perform actions at specific locations in data frame

Hi everyone, I got a data frame like the one below and and would like to do the following: Ignore the first 3 rows and check in all following rows the second position. If the value is >500, subtract 100. Example DF: ABC 22 DE 12 BCD 223 GH 12 EFG 2104 DH ... (4 Replies)
Discussion started by: TuAd
4 Replies

7. UNIX for Advanced & Expert Users

printing specific line from a file.

The below line gives the perfect output when I mention the record number and file name as hardcoded. awk 'NR==3{print}' samp2.txt But when I pass the record num and file name as variable, it doesn't give any output. row_num=3;file2=samp2.txt;awk 'NR==$row_num {print}' $file2 Can you... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

8. Solaris

User specific printing options

Hi, how do I query available printer options and set defaults for my print requests? I have found lpoptions (man lpoptions(1)) on the web but it doesn't seem to be available under Solaris and I can't work out how else to do it. Thanks, Bob (2 Replies)
Discussion started by: BobD
2 Replies

9. Shell Programming and Scripting

Printing a specific line using AWK

Hi, I have a script that fetches only specific information from fcinfo command. Below is a portion of the script. #!/usr/bin/ksh set -x HBA_COUNT=`sudo fcinfo hba-port | grep -i state | awk 'END{print NR}'` echo "$HBA_COUNT HBAs exist" echo '........' INDEX=1 while $INDEX -le... (2 Replies)
Discussion started by: jake_won
2 Replies

10. Shell Programming and Scripting

Printing lines with specific awk NF

I have this files: ./frm/lf_mt1_cd.Ic_cell_template.attr ./die/addgen_tb_pumd.Ic_cell_template.attr ./min_m1_n.Ic_cell_template.attr When I use: awk -F\/ '{print NF}' Would result to: 3 3 2 I would like to list the files with 3 fields on it. Any Suggestions? (1 Reply)
Discussion started by: jehrome_rando
1 Replies
Login or Register to Ask a Question