Account's Balance(for lab)
来源:互联网 发布:开网店用什么软件 编辑:程序博客网 时间:2024/05/18 03:34
Account’s Balance(for lab)
标签(空格分隔): 程序设计实验 c++
本人学院
- Accounts Balancefor lab
- 标签空格分隔 程序设计实验 c
- 本人学院
- Description
- 读题
- my answer
- the standard answer
Description:
Suppose there is a class PersonalAccount, which has a private member variable balance (type: integer and value is 0 at first);
Besides, this class has three member functions:
1. add, add money into user’s account.
2. subtract, subtract money from user’s account, if the balance is insufficient, do not subtract money and print message “insufficient balance..”
3. getBalance, print the user’s balance like “The Balance is: xx”.
The main.cpp and .h are given, please finish the class’s definition..
main.cpp
/* from younglee.. * guys! enjoy your journey of c plus plus, against all odds! */#include<iostream>#include "PersonalAccount.h"using namespace std;int main() { // test input here.. int a, b; cin >> a >> b; // declare a object and it's balance is 0. PersonalAccount pa; // add a dollar into user's account.. pa.add(a); // deduct b dollar from user's account.. pa.subtract(b); // show balance.. pa.getBalance();}
PersonalAccount.h
#ifndef PERSONALACCOUNT_H#define PERSONALACCOUNT_Hclass PersonalAccount { private: int balance; public: PersonalAccount(); void add(int value); void subtract(int value); void getBalance();};#endif
读题
my answer
#include<iostream>#include"PersonalAccount.h"using namespace std;void PersonalAccount::add(int value) { balance += value;}void PersonalAccount::subtract(int value) { if (balance < value) { cout << "insufficient balance.." << endl; } else { balance -= value; }}void PersonalAccount::getBalance() { cout << "The Balance is: " << balance << endl;}PersonalAccount::PersonalAccount() { balance = 0;}
the standard answer
#include<iostream>#include"PersonalAccount.h"using namespace std;// the constructor..PersonalAccount::PersonalAccount() { balance = 0;}// add money into user's account..void PersonalAccount::add(int value) { balance += value;}// deduct money from user's account..void PersonalAccount::subtract(int value) { if (balance - value >= 0) { balance -= value; } else { cout << "insufficient balance.." << endl; }}// get the account's balance..void PersonalAccount::getBalance() { cout << "The Balance is: " << balance << endl;}// the end..
0 0
- Account's Balance(for lab)
- SQL Server 2008 User Account Create (For Frank's website)
- Lab - Pandora's Box
- Eva's Balance
- Eva's Balance POJ1702
- POJ1702Eva's Balance
- hdoj5616Jam's balance【dp】
- hdu5616 Jam's balance
- HDU5616Jam's balance
- Jam's balance
- HDU5616 Jam's balance
- Eva's Balance
- Eva's Balance
- Eva's Balance-OJ
- Eva's Balance
- test for account
- StringProblem(for lab)
- SimpleCalculator(for lab)
- java学习日记_19:面向对象之private关键词。07.06—07
- 目标检测--PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection
- C# 正则表达式去除<p>标签
- PHP+正则
- Java使用Log日志系统(common-logging和log4j)
- Account's Balance(for lab)
- Spark Streaming createDirectStream保存kafka offset(JAVA实现)
- Oracle数据库有哪些应用结构?
- 最短路+定积分 csu1806 Toll
- 数组中出现次数超过一半的数字-基于Partitoin和数据规律
- Android —— GitHub和SourceTree使用
- __declspec(dllimport)的作用
- SimpleCalculator(for lab)
- [Linux] undefined reference to `itoa'