#include<iostream>
using namespace std;
class Triangle{
public:
Triangle(int a,int b)
{
height=a;
base=b;
}
friend ostream& operator<<(ostream& output,Triangle& T);
private:
int height,base;
};
ostream& operator<<(ostream& output,Triangle& T)
{
int i,j,h,k;
i=j=T.base-1;
for(h=T.height-1;h;h--)
{
for(k=i;k;k--)
output<<' ';
output<<'*';
if(j!=i)
{
for(k=j-i-1;k;k--)
output<<' ';
output<<'*';
}
i--;
output<<endl;
}
for(k=0;k<T.base;k++)
output<<'*';
output<<endl;
return output;
}
int main()
{
Triangle t1(5,5),t2(10,10),t3(12,12);
cout<<t1<<endl;
cout<<t2<<endl;
cout<<t3<<endl;
system("pause");
return 0;
}
重载的应用
最新推荐文章于 2023-06-11 20:37:15 发布