OOP
#include <iostream.h>
#include <string.h>
class Name
{
//Daten
char VName[64];
char NName[64];
//sichtbar
public:
//Methoden, Eigenschaften
void SetVName (char *);
char *GetVName (void);
void SetNName (char *);
char *GetNName (void);
Name (); // Konstruktor
};
void Name::SetVName (char *text)
{
if (strlen (text) < sizeof (VName))
strcpy (VName, text);
else
cout << "Vorname ist zu lang.\n";
}
char *Name::GetVName (void)
{
return VName;
}
void Name::SetNName (char *text)
{
if (strlen (text) < sizeof (NName))
strcpy (NName, text);
else
cout << "Nachname ist zu lang.\n";
}
char *Name::GetNName (void)
{
return NName;
}
Name::Name ()
{
VName[0] = '\0';
NName[0] = '\0';
}
/*****************************************************************************************
Schueler ist von Name abgeleitet ("VERERBUNG")
******************************************************************************************/
class Schueler : public Name
{
int KatalogNr;
public:
void SetKatNr (int);
int GetKatNr ();
};
void Schueler::SetKatNr (int num)
{
KatalogNr = num;
}
int Schueler::GetKatNr ()
{
return KatalogNr;
}
void main ()
{
Name name1;
Schueler sch1;name1.SetVName ("Max");
name1.SetNName ("Mustermann");
cout << "Der Nachname lautet: " << name1.GetNName() << endl;sch1.SetKatNr (11);
sch1.SetVName ("Moritz");
sch1.SetNName ("Schlau");
cout << "Der Schueler " << sch1.GetNName() << " hat die Katalognummer " << sch1.GetKatNr() << endl;
}