Roin
By: a guest | Mar 20th, 2010 | Syntax:
C++ | Size: 1.55 KB | Hits: 63 | Expires: Never
//Basisklasse
class TKFZ {
private:
String Typ, Hersteller;
float Preis;
public:
TKFZ();
~TKFZ();
virtual void Create(String, String, float);
virtual void Show(String &, String &, float &);
};
//Unterklasse
class TAuto : public TKFZ {
private:
String Marke;
float Leistung;
public:
virtual void Create(String, String, float, String, float);
virtual void Show (String &, String &, float &, String &, float &);
TAuto();
~TAuto();
};
//implementierung
TKFZ::TKFZ() {
Typ="Personenwagen";
Hersteller= "VW";
Preis= 20000;
}
TKFZ::~TKFZ() {
}
void TKFZ::Create(String t, String h, float p) {
Typ=t;
Hersteller=h;
Preis=p;
}
void TKFZ::Show(String &t, String &h, float &p) {
t=Typ;
h=Hersteller;
p=Preis;
}
void TAuto::Create(String T, String H, float P, String M, float L) {
TKFZ::Create(T,H,P);
Marke=M;
Leistung=L;
}
void TAuto::Show (String &T, String &H, float &P, String &M, float &L) {
TKFZ::Show(T,H,P);
M=Marke;
L=Leistung;
}
TAuto::TAuto() {
Marke="Golf VI";
Leistung= 108;
}
TAuto::~TAuto() {
}
//instanz:
TAuto *A;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
A= new TAuto();
}
//Aufruf
A->Create(Edit1->Text,Edit2->Text,Edit3->Text.ToDouble(), Edit4->Text, Edit5->Text.ToDouble());
String T,H,M;
float P,L;
A->Show(T,H,P,M,L);