Files
BasicsOfComputerSoftwareEng…/OOP/2015Exam/2.3.cpp
2023-05-30 19:29:48 +08:00

87 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
using namespace std;
class Point {
public:
Point(int x, int y);
Point(Point &p);
~Point();
void Set(double x, double y);
void Print();
private:
double X, Y;
};
Point::Point(int x, int y) {
X = x;
Y = y;
}
Point::Point(Point &p) {
X = p.X;
Y = p.Y;
}
void Point::Set(double x, double y) {
X = x;
Y = y;
}
void Point::Print() {
cout << '(' << X << "," << Y << ")" << endl;
}
Point::~Point() {
cout << "Point的析构函数被调用" << endl;
}
class Line : public Point {
public:
Line(int x, int y, int s);
Line(Line &p);
~Line();
void Set(double x, double y, double s);
void Print();
private:
double S;
};
// Line::Line(int x, int y, int s) ____________ { // Blank 7
Line::Line(int x, int y, int s) : Point(x, y) {
S = s;
}
// Line::Line(Line &p) __________ { // Blanck 8
Line::Line(Line &p) : Point(p) {
S = p.S;
}
void Line::Set(double x, double y, double s) {
// _________________; // Blank 9
Point::Set(x, y);
S = s;
}
void Line::Print() {
cout << "直线经过的点:";
//_______________________; //Blank 10
Point::Print();
cout << "斜率为S=" << S << endl;
}
Line::~Line() {
cout << "Line析构函数被调用" << endl;
}
int main() {
Line C1(1, 1, 5);
C1.Print();
Line C2(C1);
C2.Set(3, -3, 10);
C2.Print();
return 0;
}