nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

commit e2ed088dab9aa1df1e0132d0202371df70187bad
parent ba640695055ed7c20971e9f32832b9a2cbd4a0db
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Sat,  2 Sep 2017 15:23:40 +0530

Create bank.cpp
Diffstat:
As3/oops/bank.cpp | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+), 0 deletions(-)

diff --git a/s3/oops/bank.cpp b/s3/oops/bank.cpp @@ -0,0 +1,121 @@ +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +using namespace std; + +class BBVA { + char name[20]; + int accountNumber; + char accountType; + float balance; + public: + void assign(int); + void deposit(float); + void withdraw(float); + void display(int); +}; + +void BBVA::assign(int x) { + cout << "Enter the name, account type and balance for account number " << x << " :\t"; + cin >> name >> accountType >> balance; + accountNumber = x; +} + +void BBVA::deposit(float x) { + if(x < 0) { + cout << "Invalid deposit sum.\n"; + return; + } + balance+=x; + cout << "Successfully deposited " << x << ". New balance is: " << balance << endl; +} + +void BBVA::withdraw(float x) { + if(x < 0 || x > balance) { + cout << "\nInsufficient balance.\n"; + return; + } + balance-=x; + cout << "Successfully withdrawn " << x << " from the account. Current balance is: " << balance << endl; +} + +void BBVA::display(int x) { + cout << "\nAccount number: " << accountNumber << endl << "Name: " << name << endl << "Account: " << accountType << endl << "Balance: " << balance << endl; +} + +int main() { + int max, maxNew, input = 7, index; + float sum; + do { + cout << "\nEnter the number of accounts\nYour input> "; + cin >> max; + // cout << endl; + if(max < 1) + cout << "\nInvalid input, try again.\n\n"; + } while(max < 1); + // BBVA *a = new BBVA[max]; + BBVA *a = (BBVA *) malloc(max * sizeof(BBVA)); + if(a == NULL) { + cout << "\nInsufficient memory.\n"; + return 0; + } + do{ + sum = 0; + cout << "\nEnter number corrosponding to their label\n1. Enter the details\t2. Deposit money\n3. Withdraw money\t4. Display details\n5. Add more accounts\t6. Exit\n\nYour input> "; + cin >> input; + fflush(stdin); + switch (input) { + case 1: + cout << "\nEnter the account number. (Between 0 and " << max - 1 << ")\nYour input> "; + cin >> index; + if(index < 0 || index >= max) { + cout << "\nAccount not found. Can not store the information.\n"; + break; + } + a[index].assign(index); + break; + case 2: + cout << "\nEnter the account number. (Between 0 and " << max - 1 << ")\nYour input> "; + cin >> index; + if(index < 0 || index >= max) + cout << "\nAccount not found. Can not deposit money.\n"; + cout << "Enter amount to be deposited.\nYour input> "; + cin >> sum; + a[index].deposit(sum); + break; + case 3: + cout << "\nEnter the account number. (Between 0 and " << max - 1 << ")\nYour input> "; + cin >> index; + if(index < 0 || index >= max) + cout << "\nAccount not found. Can not withdraw money.\n"; + cout << "Enter amount to be withdrawn.\nYour input> "; + cin >> sum; + a[index].withdraw(sum); + break; + case 4: + cout << "\nEnter the account number. (Between 0 and " << max - 1 << ")\nYour input> "; + cin >> index; + if(index < 0 || index >= max) + cout << "\nAccount not found. Can not display details.\n"; + a[index].display(index); + break; + case 5: + cout << "Enter new number of bank accounts\nYour input> "; + cin >> maxNew; + if(maxNew > max) { + a = (BBVA *) realloc(a, maxNew * sizeof(BBVA)); + max = maxNew; + cout << "\nNumber of accounts has been updated to " << max << ".\n"; + } + else cout << "\nInvalid input. New size should be greater than " << max << ".\n"; + break; + case 6: + cout << "\nProgramme has ended.\n"; + break; + default: + cout << "\nInvalid choice. Try again.\n\n"; + break; + } + } while(input != 6); + return 0; +}