c++第四次作业

{

派生类成员声明;

}

#include <iostream>
#include <math.h>
using namespace std;

class point
{
public:
void set1(int x, int y);
void show();
int getx()
{
return x;
};
int gety()
{
return y;
};
private:
int x;
int y;
};
void point::set1(int x, int y)
{
this->x = x;
this->y = y;
}

void point::show()
{
cout << "x=" << x << endl << "y=" << y << endl;
}

class line :public point
{
public:
void set(int x,int y);
float todis();
private:
float dis;
};

void line::set(int x, int y)
{
set1(x,y);
}

float line::todis()
{
dis = sqrt((getx() * getx()) + (gety() * gety()));
return dis;
}

int main()
{
line a;
a.set(3, 4);
a.show();
cout << a.todis() << endl;
}

#include <iostream>
#include <math.h>
using namespace std;

class point
{
public:
void set1(int x, int y);
void show();
int getx()
{
return x;
};
int gety()
{
return y;
};
private:
int x;
int y;
};
void point::set1(int x, int y)
{
this->x = x;
this->y = y;
}

void point::show()
{
cout << "x=" << x << endl << "y=" << y << endl;
}

class line :private point
{
public:
void set(int x,int y);
float todis();
void show1();
private:
float dis;
};

void line::set(int x, int y)
{
set1(x,y);
}

float line::todis()
{
dis = sqrt((getx() * getx()) + (gety() * gety()));
return dis;
}

void line::show1()
{
cout << dis<<endl;
show();
}

int main()
{
line a;
a.set(3, 4);
cout << a.todis() << endl;
a.show1();
}

#include <iostream>
#include <math.h>
using namespace std;

class point
{
public:
void set1(int x, int y);
void show();
int getx()
{
return x;
};
int gety()
{
return y;
};
private:
int x;
int y;
};
void point::set1(int x, int y)
{
this->x = x;
this->y = y;
}

void point::show()
{
cout << "x=" << x << endl << "y=" << y << endl;
}

class line :protected point
{
public:
void set(int x,int y);
float todis();
void show1();
private:
float dis;
};

void line::set(int x, int y)
{
set1(x,y);
}

float line::todis()
{
dis = sqrt((getx() * getx()) + (gety() * gety()));
return dis;
}

void line::show1()
{
cout << dis<<endl;
show();
}

int main()
{
line a;
a.set(3, 4);
cout << a.todis() << endl;
a.show1();
}

posted on 2019-10-13 13:09  zero-one  阅读(108)  评论(0编辑  收藏  举报