Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //"I pledge my honor that I have abided by the Stevens Honor System" - ajmauceri
- //declaring libraries
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <math.h>
- #include <map>
- #include <algorithm>
- #include <chrono>
- #include <ctime>
- #include <time.h>
- #include <stdio.h>
- #include <iomanip>
- #include <string.h>
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <list>
- //declaring namespace
- using namespace std;
- enum DepositType { cash, check };
- //returns lowercase values of typed functions
- string stringToLower(string input)
- {
- transform(input.begin(), input.end(), input.begin(), tolower);
- return input;
- }
- //Using "an" or "a" in a sentence
- string aOrAn(string nextWord) {
- nextWord = stringToLower(nextWord);
- char firstChar = nextWord.at(0);
- if (firstChar == 'a' ||
- firstChar == 'e' ||
- firstChar == 'i' ||
- firstChar == 'o' ||
- firstChar == 'u')
- {
- return "an";
- }
- else {
- return "a";
- }
- }
- bool SaveData(string FilePath, string contents) {
- ofstream writer;
- //1. open a real file on your hard drive
- writer.open(FilePath); //Creates a file titled 'FilePath' and ios::app makes it so it only adds info without deleting previous data
- if (writer.is_open()) {
- //2. getting data and saving data
- writer << contents;
- //3. Save and close that file.
- writer.close();
- return true; //returning that the file was saved sucessfully
- }
- else {
- writer.close();
- return false; //returning tht the file failed
- }
- }
- string LoadData(string FilePath) {
- ifstream reader;
- stringstream strStream;
- //1. Open a file so you can read from it
- reader.open(FilePath);
- //2. go ahead and read everything in it
- strStream << reader.rdbuf();
- //3. close the file
- reader.close();
- return strStream.str();
- }
- //Capitalizing the first letter in a sentence
- string CapitalizeFirstLetter(string input) {
- input[0] = toupper(input[0]);
- return input;
- }
- //setting the color of a sentence
- void PrintMessageInColor(string message, int color = 36) {
- cout << "\033[1;" << color << "m" << message << "\033[0m" << endl;
- }
- //standard color for Error Messages
- void PrintError(string message)
- {
- PrintMessageInColor(message , 31);
- }
- //setting a class for a transaction
- class Transaction
- {
- public:
- string name = "Transaction";
- float value = 0;
- time_t transactionTime;
- string toUser;
- string fromUser;
- Transaction(string transactionName, float initialValue) {
- name = transactionName;
- value = initialValue;
- }
- string ToString() {
- return name + " " + std::to_string(value) + "\r\n";
- }
- };
- //teaching the compiler what a bank account is
- class BankAccount
- {
- public:
- string username;
- private:
- string password;
- float currentBalance;
- list<Transaction> trasactions;
- public:
- BankAccount(string username, string password) {
- this->username = username;
- this->password = password;
- currentBalance = 1000;
- }
- bool CheckPassword(string password) {
- return (this->password == password);
- }
- void CheckBal() {
- PrintMessageInColor("Your balance: $" + to_string(currentBalance), 32);
- }
- bool Withdraw(float amount) {
- if (amount > 0 && amount <= 200) { //check if it's a valid amount
- if (fmod(amount, 20) == 0) { //check if it's divisable to 20
- currentBalance -= amount; //removing from balance
- PrintMessageInColor("You have successfully withdrawn: $" + to_string(amount) + "\nHere is your cash.", 32); //printing message
- return true; //returning success
- }
- else {
- PrintError("You can only withdraw amounts divisable by $20!");
- return false;
- }
- }
- else {
- PrintError("Sorry you can only withdraw a positive number up to $200.");
- return false;
- }
- }
- bool Deposit(float amount, DepositType depositType) {
- if (depositType == cash) { //depositing cash
- if (amount < 100 && amount > 0) { //checking valid amount for cash
- currentBalance += amount; //adding to balance
- PrintMessageInColor("You have successfully deposited: $" + to_string(amount), 32); //printing message
- return true; //returning success
- }
- else { //invalid amount printing error, returning false
- PrintError("Invalid amount deposited!");
- return false;
- }
- }
- else if (depositType == check) { //depositing check
- if (amount > 0) { //checking valid amount
- currentBalance += amount; //adding amount to balance
- PrintMessageInColor("You have successfully deposited: $" + to_string(amount), 32); //printing sucess message
- return true; //returning success
- }
- else { //invalid amount printing error returning false
- PrintError("Invalid amount deposited!");
- return false;
- }
- }
- return false; //if all else failed, return false
- }
- };
- //teach the compiler about banks
- class OneClickBank {
- list<BankAccount> accounts;
- private:
- BankAccount CurrentActiveAccount;
- public:
- OneClickBank(string BranchName) {
- CurrentActiveAccount = nullptr;
- };
- void AttemptToCreateBankAccount() {
- string username, password;
- bool SuccessfullyCreatedAccount = false;
- while (!SuccessfullyCreatedAccount)
- {
- cout << "Please enter a username" << endl;
- cin >> username;
- cout << "Please enter a password" << endl;
- cin >> password;
- SuccessfullyCreatedAccount = this->CreateBankAccount(username, password);
- }
- }
- void Welcome() {
- PrintMessageInColor("Welcome to 'One Click Bank' the one and only C++ bank where idiots store their cash!", 36);
- }
- bool CreateBankAccount(string username, string password) {
- for (list<BankAccount>::iterator it; it != accounts.end(); it++) { //this code scans over each BankAccount in the list checking if it's the last one, if not it adds one to check the next account
- if (it->username == username) { //checks the username from the current iterator (it) and sees if the username already exits
- PrintError("Sorry, the username you entered already exits.");
- return false;
- }
- }
- //We have successfully checked and our username doesn't already exist!
- BankAccount NewAccount(username, password);
- accounts.push_back(NewAccount);
- PrintMessageInColor("You have successfully created an account! As a thankyou we have deposited $1000 to " + username + ".", 36);
- return true;
- }
- bool Login(string username, string password) {
- for (list<BankAccount>::iterator it; it != accounts.end(); it++) { //this code scans over each BankAccount in the list checking if it's the last one, if not it adds one to check the next account
- if (it->username == username && it->CheckPassword(password)) { //checks the username from the current iterator (it) and sees if the username already exits
- PrintMessageInColor("Welcome back" + username + "!");
- CurrentActiveAccount = *it;
- cout << CurrentActiveAccount.username;
- return true;
- }
- }
- PrintError("Invalid login, please try again.");
- return false;
- }
- };
- int main()
- {
- OneClickBank oneClickBank;
- oneClickBank.Welcome();
- oneClickBank.AttemptToCreateBankAccount();
- oneClickBank.AttemptToCreateBankAccount();
- //pretend user wants to create an account
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement