BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

design class for object

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Ferry Ledi Tjandra
Guest





PostPosted: Fri Aug 06, 2004 5:51 am    Post subject: design class for object Reply with quote




Dear Folk,

considering I'm new user of C,
so I don't have good background for desingning class.

My problem is creating object and collection of objects
For example I have Point Object.
class Point
{
public:
int X,Y,Z;
Point(int x, int y, int z) X=x;Y=y;Z=z;
}

then i have collection of points, and I designed Points Class

class Points
{
public:
void AddPoint(Point pt);
Point PointItem(int iIndex);
}

So how I can add the point object into Points class and how I can maintain every point object, so I can do manipulation for this object property.

Regards,

********************************************************************************
Ferry Ledi Tjandra * フェリ・レディ・チャンドラ
Asia Air Survey Co., Ltd. * アジア航測株式会社
Research and Development Departement * .総合研究所・研究部
TEL: +81-44-969-7309 (International ----- 国際)
044-969-7309 (within Japan ------- 国内)
Website: http://www.ajiko.co.jp
E-Mai: [email]ltj.ferry (AT) ajico (DOT) co.jp[/email]
********************************************************************************

Back to top
Damon Chandler (TeamB)
Guest





PostPosted: Thu Aug 12, 2004 6:47 am    Post subject: Re: design class for object Reply with quote



Hi Ferry,
Quote:
My problem is creating object and collection of objects
For example I have Point Object.
class Point
{
public:
int X,Y,Z;
Point(int x, int y, int z) X=x;Y=y;Z=z;
}

Typically, the X, Y, and Z members would be declared in the private
section so that they're not directly accessible from outside of the
class; you'd then provide "getter" and "setter" functions...

class Point
{
public:
Point(int x=0, int y=0, int z=0) : X(x), Y(y), Z(z) {}
// add copy constructor(s) as needed

public:
int getX() { return X; }
int getY() { return Y; }
int getZ() { return Z; }
void setX(int x) { X = x; }
void setY(int y) { Y = y; }
void setZ(int z) { Z = z; }

private:
int X, Y, Z;
};

Quote:
then i have collection of points, and I designed Points Class

class Points
{
public:
void AddPoint(Point pt);
Point PointItem(int iIndex);
}

The easiest way to maintain a collection of objects is to use a pre-made
container class. For example, using the STL vector class, you'd do...

#include <vector>
class Points
{
public:
// add constructor(s) as needed

public:
void AddPoint(Point const& P)
{
list_of_points_.push_back(P);
}
Point PointItem(int iIndex)
{
return list_of_points_.at(iIndex);
}

private:
std::vector<Point> list_of_points_;
};

You might also be interested in the following chapter...

http://www.arirom.com/eng/OOP/ThinkingCpp/Vol_2/textC2/Chap07.htm

Good luck,
--
Damon (TeamB)
C++Builder Developer's Journal <http://bcbjournal.org>
BCBCAQ <http://caq.bcbjournal.org>

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.