您的位置:首页 > 其它

sdust 实验

2017-04-05 09:08 99 查看
#define LOCAL
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

class Point
{
private:
double x_, y_;
static int num1;
public:
Point():x_(0), y_(0){
num1++;
cout << "The Point ("<< x_ << ", " << y_ << ") is created! Now, we have "<< num1 << " points." << endl;
}
Point(double x, double y):x_(x), y_(y){
num1++;
cout << "The Point ("<< x_ << ", " << y_ << ") is created! Now, we have "<< num1 << " points." << endl;
}
Point(const Point & p):x_(p.x_), y_(p.y_){
num1++;
cout << "A Point ("<< x_ << ", " << y_ << ") is copied! Now, we have "<< num1 << " points." << endl;
}
~Point(){
num1--;
cout << "A Point ("<< x_<< ", "<< y_<< ") is erased! Now, we have "<< num1 << " points."<< endl;
}
int getX(){
return x_;
}
int getY(){
return y_;
}
static int getNumOfPoints();
};
int Point::num1 = 0;
int Point::getNumOfPoints(){
return num1;
}
class Circle
{
public:
Circle(double x, double y, double r):c_(x, y), r_(r){
num2++;
cout << "A circle at ("<< x << ", "<< y << ") and radius "<< r_ << " is created! Now, we have "<< num2 << " circles." << endl;
}
Circle(Point p, double r):c_(p), r_(r){
num2++;
cout << "A circle at ("<< c_.getX() << ", "<< c_.getY() << ") and radius "<< r_ << " is created! Now, we have "<< num2 << " circles." << endl;
}
~Circle(){
num2--;
cout << "A circle at ("<< c_.getX() << ", "<< c_.getY() << ") and radius "<< r_ << " is erased! Now, we have "<< num2 << " circles." << endl;
}
static int getNumOfCircles();
Point &getCenter()
{
return c_;
}
bool pointInCircle(Point & p);
private:
Point c_;
double r_;
static int num2;
};

int Circle::num2 = 0;
int Circle::getNumOfCircles(){
return num2;
}
bool Circle::pointInCircle(Point &p){
int x = p.getX()*1.0;
int y = p.getY()*1.0;
int x0 = c_.getX()*1.0;
int y0 = c_.getY()*1.0;
int m = (x0 - x)*(x0 - x) + (y0 - y)*(y0 - y);
int l = sqrt(m);
if(l < r_) return true;
else return false;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int cases,num;
int x, y, r, px, py;
Point aPoint(0,0), *bPoint;
Circle aCircle(1,1,1);
cin>>cases;
cout<<"We have "<<Point::getNumOfPoints()<<" points and "<<Circle::getNumOfCircles()<<" circles now."<<endl;
for (int i = 0; i < cases; i++)
{
cin>>x>>y>>r;
bPoint = new Point(x,y);
Circle circle(*bPoint, r);
cin>>num;
for (int j = 0; j < num; j++)
{
cin>>px>>py;
if (circle.pointInCircle(*(new Point(px, py)))) // new 运符返回一个地址,所以要用*运算,这也就说明了加*时传的就是一个类的引用×,,不是引用就是类似于普通的值
{
cout<<"("<<px<<", "<<py<<") is in the circle at (";
cout<<circle.getCenter().getX()<<", "<<circle.getCenter().getY()<<")."<<endl;
}
else
{
cout<<"("<<px<<", "<<py<<") is not in the circle at (";
cout<<circle.getCenter().getX()<<", "<<circle.getCenter().getY()<<")."<<endl;
}
}
delete bPoint;
}
cout<<"We have "<<Point::getNumOfPoints()<<" points, and "<<Circle::getNumOfCircles()<<" circles."<<endl;
return 0;
}


#include<iostream>
using namespace std;

class newInt
{
public:
newInt():x_(0){}
newInt(int x): x_(x){}
friend newInt operator+(newInt& m, newInt &n);
friend ostream &operator<<(ostream &os, newInt &c){
os << c.x_;
return os;
}
friend istream &operator>>(istream &is, newInt&c){
is >> c.x_;
return is;
}
int x_;
};
newInt operator+(newInt& a, newInt &b)
{
newInt t;
int x = a.x_;
int y = b.x_;
int aa[100] = {0}, bb[100] = {0};
int  i, j, h;
for(i = 0; x >= 10; i++){
aa[i] = x % 10;
x = x / 10;
}
aa[i] = x;
for(j = 0; y >= 10; j++){
bb[j] = y % 10;
y = y / 10;
}
bb[j] = y;
int m = (i > j) ? i : j;
int sum = 0;
for(h = m; h >= 0; h--)
{
int num = (aa[h]+bb[h])%10;
sum = num + sum * 10;
}
t.x_ = sum;
return t;
}

//      newInt operator + (const newInt &m,const newInt &n)
//        {
//            newInt t;
//            int arr[100];
//            int arr2[100];
//            int arr3[100];
//            for(int i=0;i<100;i++)
//                arr[i]=0;
//            for(int i=0;i<100;i++)
//                arr2[i]=0;
//                for(int i=0;i<100;i++)
//                arr3[i]=0;
//
//            int flag=0;
//            int a=0;
//            int b =0;
//            int xx = m.x_;
//            int yy = n.x_;
//            while(xx>0)
//            {
//                arr[a++] = xx%10;
//                xx =xx/10;
//                flag++;
//            }
//            int flag2=0;
//            while(yy>0)
//            {
//                arr2[b++] = yy%10;
//                yy /= 10;
//                flag2++;
//            }
//            flag = max(flag,flag2);
//            for(int i=0;i<flag;i++)
//            {
//                if(arr[i]+arr2[i]<10)
//                    arr3[i] = arr[i]+arr2[i];
//                    else arr3[i] = arr[i]+arr2[i]-10;
//            }
//            int sum=0;
//            for(int i=flag;i>=0;i--)
//            {
//                sum=10*sum;
//                sum += arr3[i];
//            }
//            t.x_= sum;
//            return t.x_;
//        }

int main()
{
int cases;
newInt a, b, c;
cin>>cases;
for (int i = 0; i < cases; i++)
{
cin>>a>>b;
c = a + b;
cout<<a<<" + "<<b<<" = "<<c<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  SDUST