Hello, I'm having a hard time figuring out what to do for my bank account program. I haven't gotten far into it, but I have several problems/issues with my code.
1. I have to load and save all the data to and from a binary file, but I was testing out how it would output without being a binary file and it appears unreadable. How could I fix this and successfully turn it into a binary file?
2. I have to load the binary file into an STL vector, but I'm still confused on how to do that. I plan to use a vector for multiple customers that would use an ID or name that would be associated with multiple accounts (such as saving and checking accounts), but I'm completely stuck on doing it.
3. Is there any advice you would give me on how to make this polymorphic? I'm using the print function as a pure virtual function, but are their other ways to implement polymorphism? Also, what other ways could I make this program connect, in terms of composition and inheritance?
I'm sorry for this HUGE amount of questions, but I really do appreciate it if anyone could give me even a small amount of help. Thanks in advance!
My code so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <ctime>
using namespace std;
const int NAMESIZE = 30;
class BankManage
{
protected:
char fName[NAMESIZE], lName[NAMESIZE];
int accountID;
double balance;
public:
// Default Constructor for BankAccount
BankManage()
{
accountID = 0;
balance = 0.00;
}
// Copy Constructor for BankAccount
BankManage(char first, char last, int id, double bal)
{
fName[NAMESIZE] = first;
lName[NAMESIZE] = last;
accountID = id;
balance = bal;
}
int getID()
{
return accountID;
}
double getBalance()
{
return balance;
}
void createNewAccount()
{
// Add an new customer
int id;
cout << "\n\nThank you for choosing Samediff Bank!\n";
cout << "Please enter your first name: ";
cin.ignore();
cin.getline(fName, NAMESIZE);
cout << "Please enter your last name: ";
cin.ignore();
cin.getline(lName, NAMESIZE);
cout << "Type in a four-character passcode: ";
cin >> accountID;
while (accountID < 1 || accountID > 9999)
{
cout << "Error! ID out of range.\n";
cin >> id;
}
//accountID = id;
//cin >> accountID;
cin.ignore();
cin.get();
cout << "Congrats! Your new ID number is " << accountID
<< ".\nKeep this number safe and don't share it with others.\n";
}
};
class BankAccount : public BankManage
{
protected:
int bankID;
public:
BankAccount();
//virtual double deposit();
//virtual double withdraw();
//virtual void print() = 0;
};
// Constructor for BankAccount
BankAccount::BankAccount()
{
bankID = this->accountID;
}
//// Savings Account
//class savingAccount : public BankAccount
//{
//private:
// double apyRate;
// double balance;
//public:
// savingAccount();
// void interest();
// double withdraw();
// double deposit();
// void print();
//};
//
//// Constructor for savingAccount
//savingAccount::savingAccount()
//{
// apyRate = 0.0105;
//}
//
//// Interest for savingsAccount
//void savingAccount::interest()
//{
//
//}
//
//// Withdraw from savings account
//double savingAccount::withdraw()
//{
//
//}
//
//// Deposit in savings account
//double savingAccount::deposit()
//{
//
//}
//
//// Print the balance in the savings account
//void savingAccount::print()
//{
// cout << balance << endl;
//}
//class checkingAccount
//{
//private:
// double apyRate = 0.0105;
//public:
// checkingAccount();
// void interest();
// double withdraw();
// double deposit();
// void print();
//};
// Function Prototypes
void writeAccount(vector<BankManage> &);
void manageAccounts(vector<BankManage> &);
int main()
{
// Variables
vector<BankManage> customers;
// Let's start the program!!!
cout << "-----------Samediff Bank-----------\n";
// Menu System
int choice;
cout << " Please select the following:\n\n";
cout << "1. Create a new account.\n";
cout << "2. Add or remove an account.\n";
cout << "3. Deposit an amount into one of your accounts.\n";
cout << "4. Withdraw an amount from one of your accounts.\n";
cout << "5. View your balance from one of your accounts.\n";
cout << "6. Check how much interest you will earn in one of your accounts.\n";
cout << "7. Exit the program.\n";
cout << "Enter your choice here: \n";
cin >> choice;
switch (choice)
{
case 1:
writeAccount(customers);
break;
case 2:
manageAccounts(customers);
break;
case 3:
case 4:
case 5:
case 6:
case 7:
default:
cout << "Error! Entered invalid input. Now closing program.\n";
break;
}
cout << "\nThank you for using Samediff Bank!\nYour account will update once exiting.\n";
cin.ignore();
cin.get();
return 0;
}
void writeAccount(vector<BankManage>& customers)
{
// Variables
BankManage customer;
fstream outFile;
char first[NAMESIZE], last[NAMESIZE];
outFile.open("bankData.txt", ios::out );
if (!outFile)
{
cout << "Error opening file!";
cin.ignore();
cin.get();
exit(1);
}
else
{
customer.createNewAccount();
outFile.write(reinterpret_cast<char *>(&customer), sizeof(outFile));
}
BankManage newCustomer(first[30], last[30], customer.getID(), customer.getBalance());
customers.push_back(newCustomer);
outFile.close();
}
void manageAccounts(vector<BankManage> &)
{
}
| |