看看这个程序有什么错误?
//定义三角形类。。。 #include <iostream>
using namespace std;
class Triangle:public Shape
{
long iT;
public:
Triangle(long t)
{
setTriangle(t);
}
void setTriangle(long t)
{
iT=t;
}
int getiT( ) const { return iT; }
virtual void printShapeName( ) const { cout << "Triangle: "<<endl; }
//打印数据成员
virtual void draw( ) const
{
for(int i=0;i<iT;i++)
{
for(int j=0;j<iT-i;j++)
{
cout<<" ";
}
for(int k=0;k<(i+i+1);k++)
{
cout<<"*";
}
cout<<endl;
}
}
};
//定义正方形类。。。
#include <iostream>
using namespace std;
class Square:public Shape
{
long iA;
public:
Square(long a)
{
setSquare(a);
}
void setSquare(long a)
{
iA=a;
}
int getiA( ) const { return iA; }
virtual void printShapeName( ) const { cout << "Square: "<<endl; }
//打印数据成员
virtual void draw( ) const
{
for(int j=0;j<iA;j++)
{
for(int k=0;k<iA;k++)
cout<<"*";
cout<<endl;
}
}
};
//定义抽象基类Shape
#include <iostream>
using namespace std;
class Shape {
public:
//纯虚函数,供派生类重定义
virtual void printShapeName( ) const = 0;
virtual void draw( ) const = 0;
};
//定义长方形类。。。
#include <iostream>
using namespace std;
class Rectangle:public Shape
{
long iL,iW;
public:
Rectangle(long l,long w)
{
setRectangle(l,w);
}
void setRectangle(long l,long w)
{
iL=l;
iW=w;
}
int getiL( ) const { return iL; }
int getiW( ) const { return iW; }
virtual void printShapeName( ) const { cout << "Rectangle: "<<endl; }
//打印数据成员
virtual void draw( ) const
{
for(int j=0;j<iW;j++)
{
for(int k=0;k<iL;k++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
};
#include<iostream>
#include"shape.h"
#include"square.h"
#include"triangle.h"
#include"rectangle.h"
using namespace std;
int main()
{
int l,w,t,a;
int num;
Square s1(0);
Rectangle c1(0,0);
Triangle tr1(0);
cout<<"请选择你要输出的类型:"<<endl;
cout<<"选择正方形请按(1),选择长方形请按(2),选择三角形请按(3),跳过请按(0):";
cin>>num;
switch(num)
{
case 0:cout<<"OK,next............"<<endl;
case 1:
cout<<"请输入正方形的边长:";
cin>>a;
s1.setSquare(a);
s1.printShapeName( );
s1.draw();break;
case 2:
cout<<"请输入长方形的长和宽:";
cin>>l>>w;
c1.setRectangle(l,w);
c1.printShapeName( );
c1.draw();break;
case 3:
cout<<"请输入正三角形的边长:";
cin>>t;
tr1.setTriangle(t);
tr1.printShapeName();
tr1.draw();break;
default:
cout<<"你输入了一个错误的东西!请继续下去!"<<endl;
}
cout<<endl;
return 0;
}