Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BankSystemDriver.cpp: BankSystem is a project that allows users to dynamically look at and change particular values of their bank and credit accounts. Upon execution,
- the user is given a number of choices for actions to take. They are allowed to validate their card (and identify it), check their balance, enter
- a new account into the system, or remove an account from the system.
- Author: Jake Davis [41441080]
- Date Modified: 14 April 2010
- UserID / Lab: z7c7 / L2A
- */
- #include "stdafx.h"
- #include "CreditAccount.h"
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <stdlib.h>
- #define NUM_ACCOUNTS 100
- BankAccount* newBankAccount(){
- string newName;
- string newNum;
- double newBalance;
- cout << "\nEnter account name: ";
- cin >> newName;
- cout << "Enter bank account number (10 digits: 0-9): ";
- cin >> newNum;
- cout << "Enter initial balance: $";
- cin >> newBalance;
- // Create the account
- BankAccount* theAccount = new BankAccount(newName, newNum, newBalance);
- // Confirmation of completion
- cout << "\nAccount successfully created. Returning value.\n\n";
- theAccount->print();
- }
- void newCreditAccount(CreditAccount* account){
- string newName;
- string newNum;
- double newBalance;
- int cardType;
- string newCredNum;
- double newInterest;
- int credChoice;
- string digits;
- while(true){
- cout << "\nEnter account name: ";
- cin >> newName;;
- while(newNum.length() != 10){
- cout << "Enter bank account number (10 digits: 0-9): ";
- cin >> newNum;
- // Validate that this number has not already been taken!
- if(newNum.length() != 10){
- cout << "Invalid number of digits (must be 10 digits: 0-9)\n\n";
- continue;
- }
- }
- cout << "Enter initial balance: $";
- cin >> newBalance;
- cout << "\nSelect a credit card type from the options below:\n";
- cout << "1. MasterCard\n";
- cout << "2. Visa\n";
- cout << "3. American Express\n";
- cout << "4. Discover\n";
- cout << "0. Cancel\n";
- cout << "Please select one: ";
- cin >> cardType;
- if(cardType == 0) break;
- if(cardType < 0 && cardType > 4) cout << "Sorry, you've entered an invalid option\n\n";
- /* Credit card standards include:
- MasterCard: first two digits 51, 52, 53, 54, or 55; 16 digits in length
- Visa: first digit 4; 13 or 16 digits in length
- American Express: first digits 34 or 37; 15 digits in length
- Discover: first digits 6011; 16 digits in length
- */
- // Begin switch statement to determine the type of credit card the user wants
- switch(cardType){
- case 1:
- while(digits.length() != 14){
- cout << "Per MasterCard standards, the first two digits must be 51, 52, 53, 54, or 55.\nFor simplicity, we will choose 54 for you!\nEnter the remaining 14 digits (0-9): ";
- newCredNum = "54";
- cin >> digits;
- if(digits.length() != 14) cout << "Ruht-roh! Invalid number of digits (must be 14 digits: 0-9)\n\n";
- else newCredNum.append(digits);
- }
- break;
- case 2:
- while(digits.length() != 12 && digits.length() != 15){
- cout << "Per Visa standards, the first digit of your card must be 4.\nEnter 12 or 15 additional digits (0-9): ";
- newCredNum = "4";
- cin >> digits;
- if(digits.length() != 12 && digits.length() != 15) cout << "Ruht-roh! Invalid number of digits (must be 12 or 15 digits: 0-9)\n\n";
- else newCredNum.append(digits);
- }
- break;
- case 3:
- while(digits.length() != 13){
- cout << "Per American Express standards, the first digit of your card must be 34 or 37.\nFor simplicity, we will choose 34 for you!\nEnter the remaining 13 digits (0-9): ";
- newCredNum = "34";
- cin >> digits;
- if(digits.length() != 13) cout << "Ruht-roh! Invalid number of digits (must be 13 digits: 0-9)\n\n";
- else newCredNum.append(digits);
- }
- break;
- case 4:
- while(digits.length() != 12){
- newCredNum = "6011";
- cout << "Per Discover standards, the first four digits of your card must be 6011.\nEnter the remaining 12 digits (0-9): ";
- cin >> digits;
- if(digits.length() != 12) cout << "Ruht-roh! Invalid number of digits (must be 12 digits: 0-9)\n\n";
- else newCredNum.append(digits);
- }
- break;
- default:
- break;
- }
- cout << "\nSelect an interest plan from the below options:\n";
- cout << "1. 5.0%, $10/yearly" << endl;
- cout << "2. 19.0%, $2/yearly" << endl;
- cout << "3. 24.0%, $0/yearly" << endl;
- cout << "0. Cancel new credit card account" << endl;
- cout << "Please select one: ";
- cin >> credChoice;
- if(credChoice == 0) break;
- if(credChoice != 1 && credChoice != 2 && credChoice != 3) cout << "Sorry, you've entered an invalid option\n";
- switch(credChoice){
- case 1:
- newInterest = 5;
- break;
- case 2:
- newInterest = 19;
- break;
- case 3:
- newInterest = 24;
- break;
- default:
- break;
- }
- // Create the account based on the values received
- account->setName(newName);
- account->setNum(newNum);
- account->setBal(newBalance);
- account->setCredBal(0.0 );
- account->setCredNum(newCredNum);
- account->setInterest(newInterest);
- // Confirmation of completion
- cout << "\nAccount successfully created. Returning value.\n\n";
- account->print();
- }
- }
- int main(void){
- int choice;
- int entry;
- string tempAcc;
- BankAccount* bankArray[NUM_ACCOUNTS];
- bankArray[0] = new BankAccount("Jake Davis", "1234567890", 100.00);
- while(true){
- cout << "\nPlease choose from the following options:\n" << endl;
- cout << "1. Enter a new account into the system\n";
- cout << "2. Remove an account from the system\n";
- cout << "3. Check your account\n";
- cout << "0. Exit\n";
- cout << "Please select one: ";
- cin >> choice;
- // account1.print();
- if(choice == 0) break;
- if(choice < 1 || choice > 3){
- cout << "Sorry, you've entered an invalid option\n";
- continue;
- }
- switch(choice){
- case 1:
- cout << "\nPlease select the type of account you want to create:\n";
- cout << "1. Bank (debit card) account\n";
- cout << "2. Credit card account\n";
- cout << "0. Cancel new account\n";
- cout << "Please select one: ";
- cin >> entry;
- if(entry == 0) break;
- else if(entry != 1 && entry != 2){
- cout << "Sorry, you've entered an invalid option\n";
- continue;
- }
- else{
- if(entry == 1) bankArray[1] = newBankAccount(bankArray[0]); // add to the given array the return of newBankAccount()
- if(entry == 2) bankArray[1] = newCreditAccount(); // add to the given array the return of newCreditAccount()
- }
- break;
- case 2:
- cout << "Enter bank account number: ";
- cin >> tempAcc;
- /*
- if(bankArray.findNum(tempAcc)){
- }
- else{
- cout << "\nThis bank account number was not found!";
- }
- */
- break;
- case 3:
- cout << "Enter bank account number: ";
- cin >> tempAcc;
- /*
- findNum(tempAcc);
- */
- break;
- default:
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement