Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BankAccount.cpp
- #include "BankAccount.h"
- BankAccount::BankAccount(const string & actN, const string & fname, const string & lname, double bal) {
- ActNum = actN;
- // Validate balance
- if (bal < 0) {
- cout << "Balance is invalid. Value cannot be negative." << endl;
- balance = 0.0;
- }
- else {
- balance = bal;
- }
- FirstName = fname;
- LastName = lname;
- }
- const string BankAccount::toString() const {
- ostringstream os;
- os << fixed << showpoint << setprecision(2);
- os << "Full Name: " << FirstName << " " << LastName << endl;
- os << "Account Number: " << ActNum << endl;
- os << "Balance: $" << setprecision(2) << fixed << balance << endl;
- return os.str();
- }
- void BankAccount::setAccountNumber(const string & actN) {
- ActNum = actN;
- }
- void BankAccount::deposit(double money) {
- if (money < 0) {
- cout << "Deposit amount was negative. It cannot be negative." << endl;
- }
- else {
- balance += money;
- }
- }
- void BankAccount::withdraw(double money) {
- if (balance >= money) {
- balance -= money;
- }
- else {
- cout << "Withdrawl amount exceeded available funds." << endl;
- }
- }
- void BankAccount::setLastName(const string & lname) {
- LastName = lname;
- }
- string BankAccount::getAccountNumber() const {
- return ActNum;
- }
- double BankAccount::getBalance() const {
- return balance;
- }
- const string BankAccount::getFirstName() const {
- return FirstName;
- }
- const string BankAccount::getLastName() const {
- return LastName;
- }
- const string BankAccount::getFullName() const {
- return FirstName + " " + LastName;
- }
- void BankAccount::print() const {
- cout << "Full Name: " << FirstName << " " << LastName << endl;
- cout << "Account Number: " << ActNum << endl;
- cout << "Balance: $" << setprecision(2) << fixed << balance << endl;
- }
- void BankAccount::print(ostream & out) const {
- out << "Full Name: " << FirstName << " " << LastName << endl;
- out << "Account Number: " << ActNum << endl;
- out << "Balance: $" << setprecision(2) << fixed << balance << endl;
- }
- void BankAccount::getInstance(BankAccount & BA)
- {
- string actNum, fName, lName;
- double bal;
- cout << "Account Number: ";
- cin >> actNum;
- cout << "First Name: ";
- cin >> fName;
- cout << "Last Name: ";
- cin >> lName;
- cout << "Balance: $";
- cin >> bal;
- BA = BankAccount(actNum, fName, lName, bal);
- }
- void BankAccount::getInstance(BankAccount & BA, ifstream & in)
- {
- string actNum, fName, lName;
- double bal;
- in >> actNum >> lName >> fName >> bal;
- BA = BankAccount(actNum, fName, lName, bal);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement