// GA.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class shape
{
public:
virtual float area() const =0;
};
class point:public shape
{
public:
point(float=0,float=0);
setpoint(float,float);
float area();
getx();
gety();
operator + (point &p);
operator + (int p);
private:
float x,y;
};
point::getx()
{return x;}
point::gety()
{return y;}
point::setpoint(float a,float b)
{x=a;x=b;}
point::operator + (point &p)
{
return setpoint(x+p.getx(),y+p.gety());}
point::operator + (int p)
{
return setpoint(x+p,y+p);}
float point::area()
{
cout<<x<<","<<y<<endl;
return 0;
}
class circle:public point
{
public:
circle(float=0,float=0,float=0);
setcircle(float a,float b,float r);
float area();
operator + (point &p);
private:
float x,y;
float ra;
};
circle::setcircle(float a,float b,float r)
{
x=a;y=b;ra=r;
}
circle::operator + (point &p)
{return setcircle(x+p.getx(),y+p.gety(),ra+0);
}
float circle::area()
{
cout<<3.14*ra*ra<<endl;
return 0;
}
int main(int argc, char* argv[])
{
point p(1.5,1.7);
p.area();
//circle c(1.5,1.3,1.5),cp;
//cp=c+P;
printf("Hello World!\n");
return 0;
}
额 源程序是这样的