January 02, 2005 Make headers??? | ||||
---|---|---|---|---|
| ||||
Hello to Everybody, I have the class declaration 'BOX.h', the class implementation 'BOX.cpp' and the main routine 'BOXEN2.cpp'. How can I create a working header file and such link the files to make them running???? Thanks a lot! Lisa ----------------------------------------------------------------------------- The header file, class declaration ----------------------------------------------------------------------------- // Kapitel 5 - Programm 7 - BOX.H class Box { int Laenge; int Breite; public: Box(void); //Konstruktor void Setze(int NeueLaenge, int NeueBreite); int HoleFlaeche(void) {return (Laenge * Breite);} ~Box(void); //Destruktor }; ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- The class implementation ----------------------------------------------------------------------------- // Kapitel 5 - Programm 8 - BOX.CPP #include "box.h" Box::Box(void) //Implementation des Konstruktors { Laenge = 8; Breite = 8; } // Diese Methode setzt die Größe der Box auf die beiden Parameter void Box::Setze(int NeueLaenge, int NeueBreite) { Laenge = NeueLaenge; Breite = NeueBreite; } Box::~Box(void) //Implementation des Destruktors { Laenge = 0; Breite = 0; } ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- The main routine ----------------------------------------------------------------------------- // Kapitel 5 - Programm 9 - BOXEN2.CPP #include <iostream.h> #include "box.h" int main() { Box Klein, Mittel, Grosz; //Drei Boxen Klein.Setze(5, 7); // Die mittlere Box verwendet die Werte, // die der Konstruktor vorgibt Grosz.Setze(15, 20); cout << "Der Flaecheninhalt der keinen Box ist " << Klein.HoleFlaeche() << "\n"; cout << "Der Flaecheninhalt der mittleren Box ist " << Mittel.HoleFlaeche() << "\n"; cout << "Der Flaecheninhalt der grossen Box ist " << Grosz.HoleFlaeche() << "\n"; return 0; } ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- |
Copyright © 1999-2021 by the D Language Foundation