📄 l7_1.cpp
字号:
#include <iostream.h>
#include <string.h>
class CLocation
{
private:
int x;
int y;
public:
int Getx();
int Gety();
void MoveTo(int x, int y);
CLocation(int x=0, int y=0);
};
void CLocation::MoveTo(int x, int y)
{
CLocation::x = x; // 可以写成 this->x = x;
CLocation::y = y; // 可以写成 this->y = y;
}
int CLocation::Getx()
{
return x;
}
int CLocation::Gety()
{
return y;
}
CLocation::CLocation(int x, int y)
{
CLocation::x = x; // 可以写成 this->x = x;
CLocation::y = y; // 可以写成 this->y = y;
}
class CPoint:public CLocation
{
private:
char Color[10];
public:
CPoint(char *c);
void SetColor(char *c);
void Show();
};
CPoint::CPoint(char *c)
{
strcpy(Color,c);
}
void CPoint::SetColor(char *c)
{
strcpy(Color,c);
}
void CPoint::Show()
{
cout << Getx() << "," << Gety() << " " << Color << endl ;
}
void main(void)
{
CPoint p("Red");
p.Show();
p.MoveTo(7,8);
p.Show();
p.SetColor("Green");
p.Show();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -