我不是发给你了吗,在百度消息里,已经发过了 ,算了,在给你发一次:
第一题:
#include
#include
#include
using namespace std;
class Point
{
int x,y;
static int count;
public:
Point(int xx = 0,int yy = 0):x(xx),y(yy) {
count++;
}
Point(Point & p) {
x = p.x;
y = p.y;
count++;
}
friend double dist(Point &p1,Point & p2);
static void show(Point &p) {
cout<<"("<
};
int Point::count = 0;
double dist(Point &p1,Point &p2)
{
double x=p1.x-p2.x;
double y=p1.y-p2.y;
return sqrt(x*x+y*y);
}
int main()
{
Point p1;
Point::show(p1);
Point p2(3,4);
Point::show(p2);
cout<<"distance:"<
return 0;
}
第二题:
#include
#include
#include
using namespace std;
class Matrix
{
int *p_data; //矩阵数据
int row, col; //矩阵的行数和列数
public:
Matrix(int r, int c);
Matrix(Matrix &m);
~Matrix();
int & element(int i,int j);//访问矩阵元素
void display();//显示矩阵元素
Matrix add(Matrix &m);
};
Matrix::Matrix(int r, int c)
{
row=r;
col=c;
p_data = new int[row*col];
for (int i=0;i
};
Matrix::Matrix(Matrix &m)
{
row=m.row;
col=m.col;
p_data= new int [row*col];
for (int i=0;i
};
Matrix::~Matrix()
{
delete []p_data;
};
int& Matrix::element(int i, int j)
{
return *(p_data+i*col+j);
};
Matrix Matrix::add(Matrix &m)
{
Matrix temp(row,col);
for (int i=0;i
return temp;
};
void Matrix::display()
{
for (int i=0;i
}
};
int main()
{
int row=2,col=3;
Matrix mym1(row,col);
Matrix mym2(row,col);
for (int i=0;i
for ( int i=0;i
getchar();
cout<<"matrix:\n";
cout<<"mym1:"<
cout<<"\nmym2:"<
//Matrix m(2,3);
//m = mym1.add(mym2);
cout<<"after mym1 add mym2 :\n";
mym1.add(mym2).display();
getchar();
return 0;
}
这个第二题,稍微有点改动,是我的编译器的问题,按着原题编译,我的编译器编译不过去,你看看就知道了。