currency.cpp
来自「一本语言类编程书籍」· C++ 代码 · 共 22 行
CPP
22 行
// Exercise 11.2 Currency converter. File: currency.cpp
#include <iostream>
#include <iomanip>
#include "currency.h"
// Display a currency amount with two decimal places
void Currency::show() {
std::cout << std::fixed << std::setprecision(2) << amount << " " << code;
}
// Sets the amount for the current currency
void Currency::set_amount(double value){
if(value == 0.0) // Can't have a zero amount
amount = 1.0;
else
amount = value;
}
// Convert the amount of the current currency the currency of the argument
double Currency::convert(Currency currency) {
return amount*rate/currency.rate;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?