C++ 实验五

//设计一个名为Fan的类, 表示一个风扇;
#include <iostream>
#include <string>
using namespace std;

#define ON  1
#define OFF 0

class Fan
{
public:
	Fan(int speed, double radius, string color, bool on);
	~Fan();
	void display(void);
	void accessSpeed(int speed);
	void accessRadius(double radius);
	void accessColor(string color);
	void accessOn(bool on);
private:
	int speed;
	double radius;
	string color;
	bool on;
};

int main(void)
{
	Fan ssta(3, 10, "yellow", ON);
	Fan isa(2, 5, "blue", OFF);
	ssta.display();
	isa.display();

	return 0;
}
Fan::Fan(int speed, double radius, string color, bool on)
{
	this -> speed = speed;
	this -> radius = radius;
	this -> color = color;
	this -> on = on;
}
Fan::~Fan()
{
	cout << "Well Done" << endl;
}
void Fan::display(void)
{
	cout << "the speed of this fan is: " << speed << endl;
	cout << "the radius of this fan is: " << radius << endl;
	cout << "the color of this fan is: " << color << endl;
	cout << "the switch status of this fan is: ";
	if(on)
		cout << "on" << endl;
	else
		cout << "off" << endl;
}
void Fan::accessSpeed(int speed)
{
	this -> speed = speed;
}
void Fan::accessRadius(double radius)
{
	this -> radius = radius;
}
void Fan::accessColor(string color)
{
	this -> color = color;
}
void Fan::accessOn(bool on)
{
	this -> on = on;
}

//设计一个名为Account的类;
#include <iostream>
using namespace std;

class Account
{
public:
	Account(int id, double balance, double annualInterestRate);
	~Account();
	double getMonthlyInterestRate(void);
	void   withDraw(double money);
	void   deposit(double money);
	void   display(void);
private:
	int id;
	double balance;
	double annualInterestRate;
};

int main(void)
{
	Account MoneyMonkey(1122, 20000, 0.045);
	MoneyMonkey.withDraw(2500);
	MoneyMonkey.display();
	MoneyMonkey.deposit(3000);
	MoneyMonkey.display();
	
	return 0;
}
Account::Account(int id, double balance, double annualInterestRate)
{
	this -> id = id;
	this -> balance = balance;
	this -> annualInterestRate = annualInterestRate;
}
Account::~Account()
{
	cout << "Well Done~" << endl;
}
double Account::getMonthlyInterestRate(void)
{
	return annualInterestRate / 12;
}
void Account::withDraw(double money)
{
	balance -= money;
}
void Account::deposit(double money)
{
	balance += money;
}
void Account::display(void)
{
	cout << "the balance is: " << balance;
	cout << "the monthly interest rate is: ";
	cout << getMonthlyInterestRate() * 100 << '%' << endl;
}

嘛, 这回的比较简单, 于是就是这样啦喵~


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值