Hallo ich möchte
#include <iostream>
#include <list>
using namespace std;
#define SIZE 16
class Shape // rein abstrakte Basisklasse = Interface
{
public:
virtual double area() const = 0;
virtual void draw() const = 0;
};
class Circle : public Shape
{
public:
Circle(double r,double rr = 0, char *name = "") { radius = r;
radius1 = rr; if ( name)
{
int t = strlen(name);
this->name = new char[t+1];
strncpy(this->name, name, t+1);
}
}
virtual double area() const {
this->getstring(); return 3.14159265 radius radius1; }
void getstring()const {cout << *name;}
virtual void draw() const
{ cout << "Drawing circle, area = " << area() << '\n'; }
private:
char *name;
double radius, radius1;
};
class Square : public Shape
{
public:
Square(double w) { width = w; }
virtual double area() const { return width * width; }
virtual void draw() const
{ cout << "Drawing square, area = " << area() << '\n'; }
private:
double width;
};
class ShapeManager
{
public:
ShapeManager() { count = 0; }
void add(Shape *psh)
{
////hier meine Daten in einen List Con reinschreiben Weiss jemand wi das
geht
list<int> x;
Shape *m;
m = psh;
x.push_front(m);
}
void remove(Shape *psh)
{
}
void drawShapes()
{
for (int i = 0; i < count; i++)
pshapes[i]->draw();
}
private:
Shape *pshapes[SIZE];
int count;
};
int main(void)
{
ShapeManager sman;
Circle ci1(10,11,"holl");
Square sq(20);
Circle ci2(30);
sman.add(&ci1); //Zeiger
sman.add(&sq);
sman.add(&ci2);
sman.drawShapes();
sman.remove(&sq);
cout << "\nAfter removal of sq:\n";
sman.drawShapes();
return 0;
}
Danke
Lernst Du grad fuer Software-Architektur? Dieses Shape-Beispiel kommt mir doch sehr bekannt vor :P (aus dem Open-Closed-Artikel).
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.