How do I add initialization, copy and non-argument constructors to this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I add initialization, copy and non-argument constructors to this code?

I'll attach the code now...

23rd May 2020, 11:42 AM
PUFFIN Channel
PUFFIN Channel - avatar
2 Answers
0
#include <iostream> #include <iomanip> #include <math.h> using namespace std; class ATM { public: ATM():Id(0), curentMoney(0) {} void setId(int i) { Id = i; } int getId(){ return Id; } void InsertMoney(int i){ if((i < min) || (i > max)){ cout<<"Sorry, but max = 1000, min = 10"; return; } if((curentMoney + i) > max ){ cout<<"Please, input max = "<<max-curentMoney<<endl; return; } curentMoney = i; } void getMoney(int i){ if((i < min) || (i > max)){ cout<<"Sorry, but max = 1000, min = 10"; return; } if( (curentMoney - i) < 0 ) { cout<<"Problem"<<endl <<"get max: "<<curentMoney<<endl; } curentMoney -= i; } void toString() const{ cout<<"current money: "<<curentMoney<<endl; } private: int Id;
23rd May 2020, 11:43 AM
PUFFIN Channel
PUFFIN Channel - avatar
0
private: int Id; int curentMoney; enum { max = 1000, min = 10 }; }; int main() { ATM bank; bank.setId(111); bank.InsertMoney(500); bank.getMoney(100); bank.toString(); cout<<bank.getId()<<endl; return 0; }
23rd May 2020, 11:44 AM
PUFFIN Channel
PUFFIN Channel - avatar