Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Class declaration

81 views
Skip to first unread message

kolo...@hotmail.com

unread,
Apr 8, 2020, 4:57:28 AM4/8/20
to
Hi,
i need to solve the following problem:
(All Code is Pseudo-Code)

I want to define a list of Persons.
virtual class Person
{
Person(char* name, char* vorname, date birthday);
char* name;
char* vorname*
date birthday;
static int counter;
Person* Father;
Person* Mother;

}

Now i want to tell between Man an Women

class Man : Public Person
{
Man()
: Person(char*, char*, date);
bool prop1;
short prop2;
short prop3;
// List an event has to be added to(Man-Specific) //right place here?
}

class Woman : public Person
{
Woman(char*, char*, date)
: Person(char*, char*, date);
bool prop1;
short prop2;
short prop3;
// List an events has to be added to (Woman-Specific) //right place here?
}

So far, so good. Now there is an event that has to go in a List:

add_Event(Person* Person2, place, date);

The question is, where to put that Method?

- in a method in Person?

- in a method in another class (SLIST)?

- as a friend-function of both Man/Woman

That Event could be anything from "going out", "Have Diner", "Go Shopping", etc. But I have to tell between Man and Woman.

Example:
Person* Mary = new Person(Smith, Mary, 01.01.1980);
Person* Gordon = new Person(Brown, Gordon, 12.03.1975);
Mary->add_Event(Gordon, Cinema, today(20:00));

Now add_Event has to do the following(SIMPLE):

- if Mary->prop1 == 0 then prop1 = 1
- SLIST->add_event Mary(Gordon, Cinema, today(20:00))

- SLIST->add_event Godon(Mary, Cinema, today(20:00))


I hope this is clear...
Any help would be nice




***
win10, IntelQuadCore(), 8GB

Ned Latham

unread,
Apr 8, 2020, 5:27:07 AM4/8/20
to
kolo...@hotmail.com wrote:
> Hi,
> i need to solve the following problem:
> (All Code is Pseudo-Code)
>
> I want to define a list of Persons.
> virtual class Person
> {
> Person(char* name, char* vorname, date birthday);
> char* name;
> char* vorname*
> date birthday;
> static int counter;
> Person* Father;
> Person* Mother;
>
> }
>
> Now i want to tell between Man an Women
>
> class Man : Public Person
> {
> Man()
> : Person(char*, char*, date);
> bool prop1;
> short prop2;
> short prop3;
> // List an event has to be added to(Man-Specific) //right place here?
> }

Why not

class Person
{
Person(char* name, char* vorname, date birthday);
char* name;
char* vorname*
date birthday;
bool sex;
bool prop1;
short prop2;
short prop3;
static int counter;
Person* Father;
Person* Mother;
}

and put the method(s) in there?
Message has been deleted

Ned Latham

unread,
Apr 8, 2020, 6:00:17 AM4/8/20
to
koloss88 wrote:
> schrieb Ned Latham:
> Hi,
> the properties of Man and Woman are not the same. They are Gender_Specific.
> But a good Idea...

The bool "sex" could be used to differentiate a variant record.

Actually, I'd prefer a different approach, perhaps through a typedef:

typedef enum { man, woman } sex;

kolo...@hotmail.com

unread,
Apr 8, 2020, 6:07:01 AM4/8/20
to
Hi,
i do think about it. Thanks for your help.

Paavo Helde

unread,
Apr 8, 2020, 6:17:43 AM4/8/20
to
08.04.2020 11:57 kolo...@hotmail.com kirjutas:
> Hi,
> i need to solve the following problem:
> (All Code is Pseudo-Code)
>
> I want to define a list of Persons.
> virtual class Person
> {
> Person(char* name, char* vorname, date birthday);
> char* name;
> char* vorname*
> date birthday;
> static int counter;
> Person* Father;
> Person* Mother;
>
> }

There is no need to use char* for strings in C++, use std::string instead.


>
> Now i want to tell between Man an Women
>
> class Man : Public Person
> {
> Man()
> : Person(char*, char*, date);
> bool prop1;
> short prop2;
> short prop3;
> // List an event has to be added to(Man-Specific) //right place here?
> }
>
> class Woman : public Person
> {
> Woman(char*, char*, date)
> : Person(char*, char*, date);
> bool prop1;
> short prop2;
> short prop3;
> // List an events has to be added to (Woman-Specific) //right place here?
> }
>
> So far, so good. Now there is an event that has to go in a List:
>
> add_Event(Person* Person2, place, date);
>
> The question is, where to put that Method?

Much more important is where you hold the data about the event. If
directly inside Person, then you have to duplicate and synchronize it
everywhere (imagine a football match event with 10,000 persons attending).

I would make a separate Event class, containing description, date and
time, etc. Then I would add a Participate member function in Person:

class Event {
// ...
};

class Person {
// ...
std::deque<std::shared_ptr<Event>> events_;
public:
void Participate(std::shared_ptr<Event> event) {
events_.push_back(event);
}
};




Usage example:
Person Mary("Smith", "Mary", "01.01.1980");
Person Gordon("Brown", "Gordon", "12.03.1975");
auto event1 = std::make_shared<Event>("Cinema", "today(20:00)");

Mary.Participate(event1);
Gordon.Participate(event1);

Many other ways to build up such a program are possible, the choice
depends primarily on what tasks the program has to carry out.



>
> - in a method in Person?
>
> - in a method in another class (SLIST)?


>
> - as a friend-function of both Man/Woman

Avoid friend functions as much as possible.

kolo...@hotmail.com

unread,
Apr 8, 2020, 10:03:48 AM4/8/20
to
Hi,
no offense, but I prefer the Paavo-Solution. That is, what I was looking for. Thanks alot.

M.

Jorgen Grahn

unread,
Apr 8, 2020, 10:36:10 AM4/8/20
to
On Wed, 2020-04-08, Paavo Helde wrote:
> 08.04.2020 11:57 kolo...@hotmail.com kirjutas:
>> Hi,
>> i need to solve the following problem:
>> (All Code is Pseudo-Code)
>>
>> I want to define a list of Persons.
>> virtual class Person
>> {
>> Person(char* name, char* vorname, date birthday);
>> char* name;
>> char* vorname*
>> date birthday;
>> static int counter;
>> Person* Father;
>> Person* Mother;

When there are "soft" chains like that, I tend to invent a unique ID
and look up parents and grandparents by ID. Kind of like a database.
Watch out for loops!

...
>> Now i want to tell between Man an Women
>>
>> class Man : Public Person
...
>> class Woman : public Person

What an odd thing to split on! How about people who are dead, anonymous,
non-binary or babies?

...
> Many other ways to build up such a program are possible, the choice
> depends primarily on what tasks the program has to carry out.

Exactly. The original class design looked wrong to me, but there's no
way to tell what a good design is without knowing that task.

There's no single Person class that fits all purposes.

(And here I have to admit I didn't read the part about Events.
It reminded me about genealogical data, but my thinking stopped
there.)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Melzzzzz

unread,
Apr 8, 2020, 11:10:26 AM4/8/20
to
On 2020-04-08, Jorgen Grahn <grahn...@snipabacken.se> wrote:
> On Wed, 2020-04-08, Paavo Helde wrote:
>> 08.04.2020 11:57 kolo...@hotmail.com kirjutas:
>>> Hi,
>>> i need to solve the following problem:
>>> (All Code is Pseudo-Code)
>>>
>>> I want to define a list of Persons.
>>> virtual class Person
>>> {
>>> Person(char* name, char* vorname, date birthday);
>>> char* name;
>>> char* vorname*
>>> date birthday;
>>> static int counter;
>>> Person* Father;
>>> Person* Mother;
>
> When there are "soft" chains like that, I tend to invent a unique ID
> and look up parents and grandparents by ID. Kind of like a database.
> Watch out for loops!

Pointer is unique ID. I think Oracle supports pointers, so that
one does not have to invent ID's...


--
press any key to continue or any other to quit...
U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec
Svi smo svedoci - oko 3 godine intenzivne propagande je dovoljno da jedan narod poludi -- Zli Zec
Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi
bili naoruzani. -- Mladen Gogala

Jorgen Grahn

unread,
Apr 8, 2020, 3:36:38 PM4/8/20
to
On Wed, 2020-04-08, Melzzzzz wrote:
> On 2020-04-08, Jorgen Grahn <grahn...@snipabacken.se> wrote:
>> On Wed, 2020-04-08, Paavo Helde wrote:
>>> 08.04.2020 11:57 kolo...@hotmail.com kirjutas:
>>>> Hi,
>>>> i need to solve the following problem:
>>>> (All Code is Pseudo-Code)
>>>>
>>>> I want to define a list of Persons.
>>>> virtual class Person
>>>> {
>>>> Person(char* name, char* vorname, date birthday);
>>>> char* name;
>>>> char* vorname*
>>>> date birthday;
>>>> static int counter;
>>>> Person* Father;
>>>> Person* Mother;
>>
>> When there are "soft" chains like that, I tend to invent a unique ID
>> and look up parents and grandparents by ID. Kind of like a database.
>> Watch out for loops!
>
> Pointer is unique ID.

Are you're advocating code like the above, or are you (which would be
fair enough) nitpicking?

> I think Oracle supports pointers, so that one does not have to
> invent ID's...

I didn't suggest that the OP should use a database, from Oracle or
another vendor; I'm not very familiar with them.

Juha Nieminen

unread,
Apr 9, 2020, 9:28:06 AM4/9/20
to
kolo...@hotmail.com <kolo...@hotmail.com> wrote:
> Hi,
> i need to solve the following problem:
> (All Code is Pseudo-Code)

Why does this look like an archetypal school assignment?

Öö Tiib

unread,
Apr 9, 2020, 10:20:27 AM4/9/20
to
Because (for whatever reason) majority of scholars seem to assume
that assignments must be bland and uninspiring to extreme?
This felt like assignment from novice level scholar, advanced
use concepts of "foo" and "bar" to maximize on it.

Ian Collins

unread,
Apr 9, 2020, 7:26:50 PM4/9/20
to
Would any C++ class endorse using char* for a name class member?

--
Ian.


Jorgen Grahn

unread,
Apr 10, 2020, 1:10:22 AM4/10/20
to
The code had an early 1990s feel to it in general, so that part
didn't seem so unusual.

A teacher stuck in the past feels like a fairly likely explanation.

Öö Tiib

unread,
Apr 10, 2020, 1:23:46 AM4/10/20
to
Judging by some stack overflow questions C++ curriculum in (at least
some parts of) India still involves things like <conio.h>,
<iostream.h> and Borland C.

Juha Nieminen

unread,
Apr 10, 2020, 5:29:53 PM4/10/20
to
Öö Tiib <oot...@hot.ee> wrote:
> Judging by some stack overflow questions C++ curriculum in (at least
> some parts of) India still involves things like <conio.h>,
> <iostream.h> and Borland C.

There are surprisingly many servers out there that are, for some
reason, stuck with gcc 4.

Of course even that is miles more modern than Borland C for DOS.

Jorgen Grahn

unread,
Apr 10, 2020, 6:21:35 PM4/10/20
to
On Fri, 2020-04-10, Juha Nieminen wrote:
> Öö Tiib <oot...@hot.ee> wrote:
>> Judging by some stack overflow questions C++ curriculum in (at least
>> some parts of) India still involves things like <conio.h>,
>> <iostream.h> and Borland C.
>
> There are surprisingly many servers out there that are, for some
> reason, stuck with gcc 4.

gcc 4 is the default compiler in RedHat <mumble> 7, and 8 was only
fairly recently out. That may be part of the reason.

#7 came in 2014 I believe.

> Of course even that is miles more modern than Borland C for DOS.

Yes, gcc 4 has fairly/nearly complete C++11 support, and doesn't
really cripple your designs. (Except notably std::regex is broken.)

Keith Thompson

unread,
Apr 10, 2020, 9:05:07 PM4/10/20
to
Is that a compiler issue or a library issue?

If you're running an old version of RedHat, you're probably stuck with
old versions of both gcc and the library (GNU libstdc++) unless you
rebuild both from source, so it might not make much practical difference
which package is at fault.

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Jorgen Grahn

unread,
Apr 11, 2020, 1:32:19 AM4/11/20
to
On Sat, 2020-04-11, Keith Thompson wrote:
> Jorgen Grahn <grahn...@snipabacken.se> writes:
>> On Fri, 2020-04-10, Juha Nieminen wrote:
>>> Öö Tiib <oot...@hot.ee> wrote:
>>>> Judging by some stack overflow questions C++ curriculum in (at least
>>>> some parts of) India still involves things like <conio.h>,
>>>> <iostream.h> and Borland C.
>>>
>>> There are surprisingly many servers out there that are, for some
>>> reason, stuck with gcc 4.
>>
>> gcc 4 is the default compiler in RedHat <mumble> 7, and 8 was only
>> fairly recently out. That may be part of the reason.
>>
>> #7 came in 2014 I believe.
>>
>>> Of course even that is miles more modern than Borland C for DOS.
>>
>> Yes, gcc 4 has fairly/nearly complete C++11 support, and doesn't
>> really cripple your designs. (Except notably std::regex is broken.)
>
> Is that a compiler issue or a library issue?

Library:
https://gcc.gnu.org/onlinedocs/gcc-4.8.5/libstdc++/manual/manual/status.html#status.iso.2011

> If you're running an old version of RedHat, you're probably stuck with
> old versions of both gcc and the library (GNU libstdc++) unless you
> rebuild both from source so it might not make much practical difference
> which package is at fault.

True.
0 new messages