current position:Home>How should this program be completed
How should this program be completed
2022-02-02 19:26:18 【CSDN Q & A】
Create an abstract base class Account( Account ) class , Indicates the customer account of the bank . Customers can deposit money from their bank accounts ( That is to credit )、 Withdraw money ( That is, debit ).Account Class includes :
(1) A data member representing the account balance Balance( type :double), And provide... For the data member getBalance and setBalance Two member functions , among ,setBalance The function guarantees that the balance is nonnegative , If it's negative , Set the balance to 0, And display the error message “Balance is invalid”;getBalance Function returns the value of the data member representing the current balance ;
(2) An advantage of setBalance Function to initialize the constructor and a virtual Destructor ;
(3) A with deposit amount as the parameter virtual function credit, Realize the function of saving money in bank account ;
(4) A with withdrawal amount as the parameter virtual function debit, To realize the withdrawal function of bank account , And guarantee that the account will not overdraw . If overdraft , Then the current balance remains unchanged , And print the information “Insufficient balance.”.
Refer to the answer 1:
#include<iostream>#include<string>using namespace std;class Account{public: Account(double Balance){ setBalance(Balance); } virtual ~Account(){} void setBalance(double Balance){ if(Balance >= 0) this->Balance = Balance; else{ this->Balance = 0; cout<<"Balance is invalid"<<endl; } } double getBalance(){ return Balance; } virtual void credit(double money) = 0; virtual void debit(double money) = 0;private: double Balance;};class Bank:public Account{public: Bank(double ba):Account(ba){} void credit(double money){ setBalance(money + getBalance()); } void debit(double money){ if(money > getBalance()) cout<<"Insufficient balance."<<endl; else setBalance(getBalance()-money); }};int main(){ Bank b(-900); b.credit(1200); b.debit(4000); b.debit(3000); cout<<" The remaining amount is :"<<b.getBalance()<<endl; return 0;}
Refer to the answer 2:
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021926167572.html
The sidebar is recommended
- C language file encryption applet problem
- Three types of MPEG images
- How to write this program code
- Questions about data structure: data structure sequence table (language-c language)
- A problem of energy economics
- Vscode why does Python have two problems when the external window is running? Press any key to continue?
- Using 7474n to build JK Trigger and D trigger.
- C language two-dimensional array, for interpretation
- When simulating with botu and factory IO, factory IO I2 The contacts behind 0 are not working
- How to solve termux qqbot error?
guess what you like
-
C + + getline cannot correctly read the console input Chinese
-
Android development bookkeeping
-
About the problem of C language: input 12 + 3 with DEVC + + to get 12.000000. I don't know what's wrong, include & lt; stdio. h&gt;
-
Prompt the user to enter an integer n and N real numbers, calculate and output the sum of the negative numbers in the input n real numbers.
-
Using C52 and LCD1602 to simulate an electronic clock, how to program four modes and one LED flashing for four keys
-
Do any friends know how to do this? Please
-
For problems occurred during GCN reproduction, it is suggested that the openposedemo file cannot be found
-
TypeError: string indices must be integers
-
I really can't find answers to the exercises after freshman class.
-
How is the MSE value compared with the vector?
Random recommended
- How to set a draw when making tic tac toe chess in Python
- Solving Python language C language
- How does Maple set a variable to be any integer from a certain interval
- How to realize that the opening of a website computer is one interface and the opening of a mobile phone is another interface, similar to self adaptation?
- After entering two indefinite length arrays and sorting them, merge and sort the two arrays again
- The computer has a web, but it can't access other web pages except the navigation page display
- C + + how to do this program
- Want to know how to find the parameters of this function? How should the matlab code knock
- Multi module project cannot inject mapper java
- MapReduce average score how to find the average of each line
- Wechat applet rendering layer error
- What does this mean? Why can't I open my QQ
- CMD run Py file encountered a problem
- Help me see what's wrong
- Why not 13bingo
- Decipher the password and there is no result after running?
- Ask you why this code can't run (◞‸◟)
- Hello, can you extract the of our applet
- Why not show folders when attaching a database
- How can the last line end with 0 without spaces
- Generate images from HTML pages and download them into PDF files
- Two Python experiment questions
- Hidden display problems in HTML
- Is there any good analysis process for push box problem
- What's going on here?.,!
- Cyclic input and output. If the input is a number, it will print. If the input is not a number, it will print No
- C language freshman PTA input an English sentence, change the first letter of each word into capital letters.
- Question e: snake walking, please help me
- Why is the attenuation of wave height in numerical simulation serious?
- Difference between digital image processing and image signal processing (ISP)
- Oracle a column of multi value update problem.
- Write a program in Python.
- How can Python write here to become a variable
- Which rstudio is installed in win7 64 bit? Dear friends, the previous connection can install w10,8,7, but now it can only install W10. Cry.
- Which is better, CCD camera tracking or gray sensor tracking
- Virtual reality combined with AR space
- How to click two label controls in QT to subtract the customized numbers in the control
- Ask you why there is a period of garbled code in front of the output?
- QR code generation of shopping scanning payment and third-party payment
- The Internet is a large network composed of many small networks. Can a local area network also be such a small network? What's more, how large is the coverage of a small network in a large network?