From e283c3f67f634fc7c1a97f229060084ca731e80e Mon Sep 17 00:00:00 2001 From: Kuamr_Shubham Date: Wed, 15 May 2024 23:52:23 +0530 Subject: [PATCH] Assignment --- OOPS/Readme.md | 57 ++--------- OOPS/shubhamoops.cpp | 235 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+), 46 deletions(-) create mode 100644 OOPS/shubhamoops.cpp diff --git a/OOPS/Readme.md b/OOPS/Readme.md index 3190c2c..68b200f 100644 --- a/OOPS/Readme.md +++ b/OOPS/Readme.md @@ -1,50 +1,15 @@ -# Banking Client +The programme doesnt cantain the savings and current differentiation i.e the interest rates and all. Hence the branch manager cannot access the interest rates at any particular time too. -You got your dream job in World Bank. To give other employees a run for their money, you have to come up with an OOPS based banking client. +The programme starts by welcoming the client and asks for option such as signup, login as user, login as branch manager. ---- -## High Level Overview +SIGNUP +It will ask for username and password and ensure uniqueness of username. +itll allott a unique 9 digit number as account number. -### Login In and Account creation +LOGIN +Asks for credentials and then deposit/withraw or transaction history. -1. The system should be accessed via a CLI (Command Line Interface) -2. It should have option from **Account Holder** Login/Sign-Up. Also have an option from **Branch Manager** Login -3. Username is chosen by account holder. Make system to ensure uniqueness of usernames. -4. Sign Up process is decoupled from account creation. Account creation option should be made visible after Login only. -5. Single Account holder can have multiple accounts (both of savings and checking type.) - -### Accounts -1. Accounts should have statements linked with them. -2. Opening balance is required when opening an account -3. Generate a random 9 digit number for account number (or you can also serially assign account numbers from 1 onwards) -4. Savings accounts have an upper transaction limit while checking accounts don't, decide the limit yourself and keep it constant for all savings accounts -5. Have an option to view statements -6. Have an option to close an account -7. Maintain a **global date variable** and all transactions are to be signed with the global date in the statements. - -### Branch Manager - -1. Nothing special, class diagram is self explanatory. -2. **Fast Forward method** is an explicit method that can be called from the command line interface when the manager is logged in. It skips whatever amount of days input. Depending on opening date of accounts, savings account maybe deposited by interest return from bank. Beware that banks only deposit interests monthly or trimonthly (up to you). - - ---- - -## Low Level Overview - -1. Choose appropriate access specifiers **(public, private and protected)** for the various attributes -2. Given below are the class diagrams for the classes that you have to implement -3. Do not restrict yourself to these, they are just to get you started and help you get an idea. - -

  

- -![alt text](./class.png) - ---- - -## Submission - -- Here is the Github link -- Make a fork of this repo and create a branch in the fork with the following name: [firstname]_[lastname_initial] eg. atulya_s -- Then create a pull request by 23:59:59, 11th May 2024 -- In case of any doubts, create an issue on the main repo +BRANCH MANAGER +user id: manager +pass: manager +Shows list of all accounts created. diff --git a/OOPS/shubhamoops.cpp b/OOPS/shubhamoops.cpp new file mode 100644 index 0000000..90f6b13 --- /dev/null +++ b/OOPS/shubhamoops.cpp @@ -0,0 +1,235 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Account { +public: + Account(const string& accountType, int openingAmount) + : accountType(accountType), balance(openingAmount) {} + + string getAccountType() const { return accountType; } + int getBalance() const { return balance; } + void deposit(int amount) { balance += amount; } + +private: + string accountType; + int balance; +}; + +class User { +public: + User(const string& name, const string& username, const string& password, const string& accountNumber, const Account& account) + : name(name), username(username), password(password), accountNumber(accountNumber), account(account) {} + + string getName() const { return name; } + string getUsername() const { return username; } + string getPassword() const { return password; } + string getAccountNumber() const { return accountNumber; } + const Account& getAccount() const { return account; } + +private: + string name; + string username; + string password; + string accountNumber; + Account account; +}; + +class UserDatabase { +public: + UserDatabase(vector& users, vector& accountNumbers) : users(users), accountNumbers(accountNumbers) {} + + bool findUser(const string& username, const string& password, User*& foundUser) { + for (auto& user : users) { + if (user.getUsername() == username && user.getPassword() == password) { + foundUser = &user; + return true; + } + } + return false; + } + + void addUser(const User& user, const string& accountNumber) { + users.push_back(user); + accountNumbers.push_back(accountNumber); + } + const vector& getUsers() const { + return users; + } + +private: + vector& users; + vector& accountNumbers; +}; + +class SignUp { +public: + SignUp(UserDatabase& UserDatabase, vector& accountNumbers) + : UserDatabase(UserDatabase), accountNumbers(accountNumbers) {} + + void signUp() { + string name, username, password, accountType; + int openingAmount; + + cout << "Enter name: "; + cin.ignore(); + getline(cin, name); + + do { + cout << "Enter username: "; + getline(cin, username); + } while (!CheckUnique(username)); + + cout << "Enter password: "; + getline(cin, password); + + cout << "Enter account type (Savings/Current): "; + getline(cin, accountType); + + cout << "Enter opening amount: "; + cin >> openingAmount; + + string accountNumber = generateAccountNumber(); + Account account(accountType, openingAmount); + User newUser(name, username, password, accountNumber, account); + UserDatabase.addUser(newUser, accountNumber); + cout << "Sign up successful! Your account number is: " << accountNumber << endl; + } + +private: + UserDatabase& UserDatabase; + vector& accountNumbers; + + bool CheckUnique(const string& username) { + for (const auto& user : UserDatabase.getUsers()) { + if (user.getUsername() == username) { + cout << "Username already exists. Please choose a different one." << endl; + return false; + } + } + return true; + } + + string generateAccountNumber() { + string accountNumber; + static const char digits[] = "0123456789"; + const int numDigits = 9; + uniform_int_distribution distribution(0, 9); + mt19937 engine(static_cast(time(0))); + bool unique = false; + + do { + accountNumber.clear(); + for (int i = 0; i < numDigits; ++i) { + accountNumber += digits[distribution(engine)]; + } + if (find(accountNumbers.begin(), accountNumbers.end(), accountNumber) == accountNumbers.end()) { + unique = true; + } + } while (!unique); + + return accountNumber; + } +}; + +class LogIn { +public: + LogIn(UserDatabase& UserDatabase) : UserDatabase(UserDatabase) {} + + void logIn() { + string username, password; + cout << "Enter username: "; + cin >> username; + cout << "Enter password: "; + cin >> password; + + User* foundUser = nullptr; + + if (UserDatabase.findUser(username, password, foundUser)) { + cout << "Login Successful! Welcome, " << foundUser->getName() << "." << endl; + cout << "Your account number is: " << foundUser->getAccountNumber() << endl; + cout << "Account Type: " << foundUser->getAccount().getAccountType() << endl; + cout << "Balance: " << foundUser->getAccount().getBalance() << endl; + } else { + cout << "Incorrect username or password. Please try again." << endl; + } + } + +private: + UserDatabase& UserDatabase; +}; + +int main() { + int option; + vector users; + vector accountNumbers; + + UserDatabase UserDatabase(users, accountNumbers); + + SignUp SignUp(UserDatabase, accountNumbers); + LogIn LogIn(UserDatabase); + + //BRANCH MANAGER LOGIN DETAILS + const string BMUsername = "manager"; + const string BMPassword = "manager"; + + while (true) { + cout << "-----------WELCOME------------" << endl; + cout << "1. Sign Up" << endl; + cout << "2. Login as User" << endl; + cout << "3. Login as Branch Manager" << endl; + cout << "4. Exit" << endl; + cout << "Enter your option: "; + cin >> option; + + if (option == 1) { + SignUp.signUp(); + } else if (option == 2) { + LogIn.logIn(); + } else if (option == 3) { + string username, password; + cout << "Enter branch manager username: "; + cin >> username; + cout << "Enter branch manager password: "; + cin >> password; + if (username == BMUsername && password == BMPassword) { + cout << "Login Successful! Welcome, Branch Manager." << endl; + while (true) { + cout << "-----------BRANCH MANAGER MENU------------" << endl; + cout << "1. Show all accounts" << endl; + cout << "2. Exit" << endl; + cout << "Enter your option: "; + cin >> option; + if (option == 1) { + cout << "List of all accounts:" << endl; + for (const auto& user : users) { + cout << "Name: " << user.getName() << ", Account Number: " << user.getAccountNumber() << endl; + } + } else if (option == 2) { + cout << "...Exiting Branch Manager mode..." << endl; + break; + } else { + cout << "Invalid. Please try again." << endl; + } + } + } else { + cout << "Incorrect username or password. Please try again." << endl; + } + } else if (option == 4) { + cout << "Thank you for visiting!" << endl; + return 0; + } else { + cout << "Invalid. Please try again." << endl; + } + } + + return 0; +} + + +