实验19

任务1

#include<iostream>
using namespace std;
class Mammal
{
public:
	Mammal() { cout << "Mammal" << endl; }
	~Mammal() { cout << "~Mammal" << endl; }
};
class Dog:public Mammal
{
public:
	Dog() { cout << "Dog" << endl; }
	~Dog() { cout << "~Dog" << endl; }
};
class Document
{
private:
	char name[100];
};
class Book :public Document
{
private:
	int pageCount;
};
class Base
{
public:
	void fn1() { cout << "Base fn1" << endl; }
	void fn2() { cout << "Base fn2" << endl; }
};
class Derived :public Base
{
public:
	void fn1() { Base::fn1(); }
};
int main()
{
	Derived der;
	der.Base::fn1();
	return 0;
}

任务2

#include<iostream>
using namespace std;
class Shape
{
public:
	Shape() { line_col = fill_col = line_rid = pen_style = 0; }
	~Shape() {}
	void Set_line_col() {}
	void Set_fill_col() {}
	void Set_line_rid() {}
	void Set_pen_style() {}
private:
	int line_col;
	int fill_col;
	int line_rid;
	int pen_style;
};
class Point
{
public:
	Point() { x = 0, y = 0; }
	void initPoint(float x = 0, float y = 0)
	{
		this->x = x; this->y = y;
	}
	void movePoint(float offX, float offY)
	{
		x += offX;
		y += offY;
	}
	float getX() { return x; }
	float getY() { return y; }
private:
	float x, y;
};
class Rectangle :public Point, public Shape
{
public:
	Rectangle(int w, int h) :width(w), height(h) {}
	~Rectangle() { cout << "~Rectangle" << endl; }
	int getArea()
	{
		return width * height;
	}
	void Set(int w, int h)
	{
		width = w;
		height = h;
	}
private:
	int height, width;
};
class Square :public Rectangle
{
public:
	Square(int l) :Rectangle(l, l) {}
	void Set(int l) { Rectangle::Set(l, l); }
};
class Circle :public Point, public Shape
{
public:
	Circle(int r) :radius(r) {}
	~Circle() { cout << "~Circle" << endl; }
	double GetArea() { return 3.1415926 * radius * radius; }
private:
	int radius;
};
int main()
{
	Rectangle rect(5, 10);
	cout << rect.getArea() << endl;

	cout << rect.getX() << ' ' << rect.getY() << endl;
	rect.movePoint(20, 50);
	cout << rect.getX() << ' ' << rect.getY() << endl;

	Circle cir(3);
	cout << cir.GetArea() << endl;
	Square squ(5);
	cout << squ.getArea() << endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值