C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 12th, 2004, 11:10 AM
COS214 COS214 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: In the south of Africa
Posts: 5 COS214 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Maze problem: how do you place a 2D object array within an class

Wont anyone take a look at these few classes and fix and explain why cant a person place a class(mazeItem) within another class(maze). We are trying to place a 2d array of type mazeItem within the class maze, as maze is the manager, as it were, of the whole system but it keeps on giving trouble. Now we put an array of type character and this caused no problems, so what is the problem. oh, and we are using linux
Enclosed with this email are the classes in question.
Thanks....i think.
Oh and please email the classes back if you sort out the problem.
re: clark@telkomsa.net




//maze.h
using namespace std;
#include <string>
//#include "mazeItem.h"

class Maze
{
public:
Maze(int = 20, int= 20);
void addItem(string);
bool decode(string);
bool validate(string);
bool update();
void changeCord(int, int);
void fill(char);
void draw();

private:
int x_; //x keyboard position
int y_; //y keyboard position
int width_; //maze width
int length_; //maze length
char mazeArr[][]; //example array, to show that making an array of primitive type works
MazeItem mazeItem_[][]; //array of objects, doesn't f*(&ing work
};



//maze.cpp
#include "maze.h"
#include <iostream>
#include <string>
#include "mazeItem.h"
using namespace std;
Maze::Maze(int width, int length):width_(width-1), length_(length-1)
{
x_ = 0;
y_ = 0;
mazeArr[width_][length_]; //easy to initialize primitive type array

mazeItem[width_][length_]; //cannot initialize array of objects
}

void Maze::addItem(string code)
{
Maze::decode(code);
}

bool Maze::decode(string code)
{

if (!Maze::validate(code))
{
return false;
}
string col;
string item;
string row;
string temp;

row = code[0];
temp = code[2];

cout<<"code: "<<code<<endl;

if ((temp == "0")||(temp =="1")||(temp =="2")||(temp =="3")||(temp =="4")||(temp =="5")||(temp =="6")
||(temp =="7")||(temp =="8")||(temp =="9"))
{
cout<<"then"<<endl;
col=code.substr(1,2);
item=code.substr(3, code.length());
cout<<endl<<endl;
}
else
{
col=code.substr(1,1);
item=code.substr(2,code.length());
cout<<"else"<<endl;
}

//convert row value to int
x_ = 0 ;
int i = 0 ;

while ( row[i] != '\0' )
{
x_ = x_ * 10 ;
x_ = x_ + ( row[i] - '0' ) ;
i++ ;
}

x_ = x_ - 49;
cout<<"row value converted: "<<x_<<endl;

//convert column value to int
y_ = 0 ;
i = 0 ;

while ( col[i] != '\0' )
{
y_ = y_ * 10 ;
y_ = y_ + ( col[i] - '0' ) ;
i++ ;
}

cout<<"col value converted: "<<y_<<endl;


cout<<"row: "<<row<<endl;
cout<<"col: "<<col<<endl;
cout<<"item: "<<item<<endl;
return true;
}

bool Maze::validate(string code)
{
if (code.length()<=2)
{
cout<<"Too few characters, require at least 3"<<endl;
return false;
}

string temp;
temp = code[0];

if ((temp == "0")||(temp =="1")||(temp =="2")||(temp =="3")||(temp =="4")||(temp =="5")
||(temp =="6")||(temp =="7")||(temp =="8")||(temp =="9"))
{
cout<<"Start with letter coordinate first"<<endl;
return false;
}

temp = code[1];
if (!((temp == "0")||(temp =="1")||(temp =="2")||(temp =="3")||(temp =="4")||(temp =="5")
||(temp =="6")||(temp =="7")||(temp =="8")||(temp =="9")))
{
cout<<"The letter coordinate must be followed by a number"<<endl;
return false;
}

return true;
}
bool Maze::update()
{

return true;
}

void Maze::changeCord(int x, int y)
{
x_ += x;
y_ += y;
}

void Maze::fill(char charFill)
{
int a;
int b;

for(a = 0; a<= width_; a++)
{
for(b = 0; b<= length_; b++)
mazeArr[a][b] = charFill;
}
}

void Maze::draw()
{
int a;
int c;
char b;
cout<<" ";
for(b='A'; b<= 'A' + width_; b++)
{
cout<<b;
}
cout<<endl;

for(a=0; a<=length_; a++)
{
if (a<10)
cout<<" ";

cout<<a;

for(c = 0; c<=width_; c++)
{
cout<<mazeArr[a][c];
}
cout<<endl;
}
}
//end of maze2.cpp


//mazeItem.h
class MazeItem
{
public:
MazeItem();//char = 'w');
// MazeItem(const MazeItem&);
// MazeItem& operator=(&MazeItem);
void setSymbol(char);
char getSymbol();

protected:

private:
char symbol_;
};



//mazeItem.cpp
#include "mazeItem.h"
using namespace std;

MazeItem::MazeItem()//char symbol): symbol_(symbol)
{
}

/* MazeItem::MazeItem(const MazeItem& item)
{
symbol_ = item.symbol_;
}

MazeItem& MazeItem:perator=(MazeItem& item)
{
if(this == &item)
return *this;

return *this;
}

*/

void MazeItem::setSymbol(char symbol)
{
symbol_ = symbol;
}
char MazeItem::getSymbol()
{
return symbol_;
}
Attached Files
File Type: zip cos214.zip (2.0 KB, 836 views)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Maze problem: how do you place a 2D object array within an class


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek