-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
158 lines (128 loc) · 4.38 KB
/
functions.cpp
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
#include "head.h"
#include <iostream>
#include <ctime>
#include <algorithm>
#include <string>
#include <vector>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
void menu(int *pointer) { int num = 0;
cout << "\n\nWelcome to MadeUp Banking. Select options below:" << endl; cout << "\t1. Make new account." << "\n\t2. Display all accounts."
<< "\n\t3. Deposit to an account." << "\n\t4. Withdraw from an account." << "\n\t5. Print account." << "\n\t6. Delete an account."
<< "\n\t7. Quit." << endl;
cout << "Selection:\t";
cin >> num;
*pointer = num; }
void makeAccount(vector <Account>& banks) { //creates bank account for users
int number=0;
Account temp;
number = rand() % 9000 + 1000; //random 4-digit number is generated
for (int i = 0; i < banks.size(); i++) {
if (banks[i].acNo == number) //stores in array
number = rand() % 9000 + 1000;
}
temp.acNo = number;
cout << "\nCreating bank account number " << temp.acNo << endl;
cout << "\nEnter first name: ";
cin >> temp.FirstName;
cout << "Enter last name: ";
cin >> temp.LastName;
cout << "Enter starting balance: ";
cin >> temp.acBal;
validAmt(temp.acBal);
banks.push_back(temp);
return;
}
void printAccount(vector <Account>& banks) {//displays a specific account
int acctNum = 0;
cout << "\nEnter account number to print: ";
cin >> acctNum;
for (int i = 0; i < banks.size(); i++) {
if (banks[i].acNo == acctNum) {
cout << "\nAccount Number: " << banks[i].acNo;
cout << "\t\tBalance: " << banks[i].acBal << endl;
cout << " Last name: " << banks[i].LastName;
cout << "\t\tFirst name: " << banks[i].FirstName << endl;
goto valid;
}
}
cout << "Account number does not exist!";
valid:
cout << endl;
}
void printAllAccount() { //prints all stored account
for (int i = 0; i < banks.size(); i++) {
cout << "\nAccount Number: " << banks[i].acNo;
cout << "\t\tBalance: " << banks[i].acBal << endl;
cout << " Last name: " << banks[i].LastName;
cout << "\t\tFirst name: " << banks[i].FirstName << endl;
}
return;
}
void depositAccount(vector <Account>& banks) { // allows user to deposit into a specific account.
int acctNum=0;
double money=0;
cout << "\nEnter account number for deposit: ";
cin >> acctNum;
cout << "Enter amount to be deposit: ";
cin >> money;
validAmt(money);
for (int j = 0; j < banks.size(); j++) {
if (banks[j].acNo == acctNum) {
banks[j].acBal = banks[j].acBal + money;
goto valid;
}
else {
continue;
}
}
cout << "Account number does not exist!";
valid:
cout << endl;}
void withdrawAccount(vector <Account>& banks) { //withdraw from a specific account.
int acctNum = 0;
double money = 0;
cout << "\nEnter account number for withdraw: ";
cin >> acctNum;
cout << "Enter amount to be withdraw: ";
cin >> money;
validAmt(money);
for (int j = 0; j < banks.size(); j++) {
if (banks[j].acNo == acctNum) {
banks[j].acBal = banks[j].acBal - money;
goto valid;
} else {
continue;
}
}
cout << "Account number does not exist";
valid:
cout << endl;
}
void sortAccounts(vector <Account>& banks) {//sorts the accounts to be displayed
for(int i=0; i<banks.size();i++){
for(int j=0; j<(banks.size()-1);j++) {
if(banks[j].acNo > banks[j+1].acNo){
iter_swap(banks.begin()+j, banks.begin()+j+1);
}}}}
void deleteAccount(vector <Account>& banks) { //delete a specific account.
int acctNum=0;
cout << "\nEnter account number to be deleted: ";
cin >> acctNum;
for (unsigned i = 0; i < banks.size(); i++) {
if (banks[i].acNo == acctNum) {
banks.erase(banks.begin() + i);
goto valid;
}
}
cout << "Account number does not exist!";
valid:
cout << endl;
}
void validAmt(double &money) {//Only allows positive deposits.
if (money < 0) {
cout << "\nInvalid input.";
cout << "\nEnter positive number: ";
cin >> money;
}}