|
请问下面这个程序哪里出错了啊??急啊,谢谢啊
#include <iostream>
#include <cstring>
using namespace std;
class TwoDShape {
double width;
double height;
char name[20];
public:
TwoDShape(double w, double h, char *n) {
width = w;
height = h;
strcpy(name, n);
}
double getWidth() { return width; }
double getHeight() { return height; }
void setWidth(double w) { width = w; }
void setHeight(double h) { height = h; }
char *getname {return name;}
};
class Triangle : public TwoDShape {
char style[20]; // now private
public:
Triangle(char *str, double w,
double h) : TwoDShape(w, h, "triangle") {
strcpy(style, str);
}
double area() {
return getWidth() * getHeight() / 2;
}
void style() {
cout<<"style is "<<style<<"\n";
}
};
int main()
{
Triangle t("right", 8.0, 12.0);
cout<<t.style()<<t.area();
return 0;
} |
|