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 16186114cfd98ba86ef7b78ee3c95e3d913af57f
parent 5ed35cec7eddbad4e737d2f2724d83c03b33a541
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Sat,  2 Sep 2017 15:22:16 +0530

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

diff --git a/s3/oops b/s3/oops @@ -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; +}