//设计一个名为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;
}
嘛, 这回的比较简单, 于是就是这样啦喵~