1352 [BA1002] The Account class
来源:互联网 发布:淘宝用什么刷流量 编辑:程序博客网 时间:2024/06/07 12:14
Description
Deisgn a class named Account that contains:
An int data field named id for the account (default 0).
A double data field named balance for the account (default 0).
A double data field named annualInterestRate that stores the current interest rate (default 0).
A no-arg constructor that creates a default account.
The accessor and mutator functions for id, balance, and annualInterestRate.
A function named getMonthlyInterestRate() that returns the monthly interest rate. (Hint: monthlyInterestRate = annualInterestRate / 12)
A function name withDraw that withdraws a specified amount from the account.
A function name deposit that deposits a specified amount to the account.
Provided Codes
framework.cpp
#include <iostream>#include <iomanip>#include "source.h"using namespace std;void print(Account& account){ cout << "Account ID " << account.getId() << fixed << setprecision(2) << ", Balance " << account.getBalance() << ", Monthly Interest Rate " << account.getMonthlyInterestRate() << endl;}int main(){ Account a, b; print(a); b.setId(1122); b.setBalance(20000.0); b.setAnnualInterestRate(4.5); print(b); return 0;}
Submission
source.h
class Account{public: Account(); void setId(int ); void setBalance(double =0); void setAnnualInterestRate(double =0); int getId(); double getBalance(); double getMonthlyInterestRate(); void withDraw(double ); void doposit(double );private: int id; double balance; double annualInterestRate;};Account::Account(){ id=0;}void Account::setId(int Id){ id=Id;}void Account::setBalance(double Balance){ balance=Balance;}void Account::setAnnualInterestRate(double Annual){ annualInterestRate=Annual;}int Account::getId(){ return id;}double Account::getBalance(){ return balance;}double Account::getMonthlyInterestRate(){ return annualInterestRate/12;}void Account::withDraw(double payout){ balance-=payout;}void Account::doposit(double income){ balance+=income;}
Standard Answer
source.h
// Problem#: 17645// Submission#: 4642239// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<iostream>#include<string>using namespace std;class Account {private: int id; double balance, annualInterestRate;public: Account(int ID = 0, double BALANCE = 0, double AnnualInterestRate = 0) { id = ID; balance = BALANCE; annualInterestRate = AnnualInterestRate; } int getId() { return id; } double getBalance() { return balance; } double getAnnualInterestRate() { return annualInterestRate; } void setId(int ID) { id = ID; } void setBalance(double Balance) { balance = Balance; } void setAnnualInterestRate(double AnnualInterestRate) { annualInterestRate = AnnualInterestRate; } double getMonthlyInterestRate() { return annualInterestRate/12; } void withDraw(double amount) { balance -= amount; if ( balance < 0 ) balance = 0; } void deposit(double amount) { balance += amount; }};
阅读全文
1 0
- 1352 [BA1002] The Account class
- The source code of the Account class of the famous IM app
- the account is locked
- the account is locked
- the account is locked
- the account is locked
- The LocalSystem Account
- The account is locked
- scott the account is locked
- oracle -- the account is locked
- the account is locked 解决方案
- oracle the account is locked
- oracle- the account is locked
- 微擎二开笔记之一:framework\class\account.class.php
- account
- Account
- Account
- account
- sonarqube项目按权限分配
- 聊聊树莓派吧(1)
- 【HashMap】JAVA HASHMAP的死循环
- CG中的几何学(点,向量以及法线)【1】
- Java求1-100之和的三种方式
- 1352 [BA1002] The Account class
- Android开发中常用ADB命令总结
- Android HelloWorld 分析
- Html 标签作用合集
- Netty学习(十)-Netty文件上传
- java自动装箱、拆箱
- 随机森林 random forest
- bzoj3265 noi2008志愿者招募 【线性规划】
- 图的深度优先遍历(递归与非递归算法)和广度优先遍历