第一次用C++写程序还是记录一下吧:
#include <iostream>
using namespace std;
class CTriangle
{
private:
int x;
int y;
public:
CTriangle(int xx,int yy)
{
x=xx;
y=yy;
}
CTriangle operator+(const CTriangle&c)
{
CTriangle t(0,0);
t.x=x+c.x;
t.y=y+c.y;
return t;
}
void print();
};
void CTriangle::print()
{
cout<<"A(0,"<<y<<"),B(0,0),C("<<x<<",0)";
}
int main()
{
int x,y;
cin>>y>>x;
CTriangle a(x,y);
while(cin>>y)
{
if(y==0)
{
a.print();
}
else
{
cin>>x;
CTriangle b(y,x);
a=a+b;
}
}
}