0% found this document useful (0 votes)
97 views

Assignment 03: Marks: 5

The document is an assignment for a data structures and algorithms course. It provides instructions for a programming assignment involving implementing a banking system using linked lists. Students are asked to write code to model a scenario where visitors come to a bank each day, their information is saved in a linked list, and various operations are performed like calculating totals deposited and withdrawn, identifying a random winner, and displaying information. The assignment asks students to insert at least 10 sample visitors and include output screenshots.

Uploaded by

Khizar Siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Assignment 03: Marks: 5

The document is an assignment for a data structures and algorithms course. It provides instructions for a programming assignment involving implementing a banking system using linked lists. Students are asked to write code to model a scenario where visitors come to a bank each day, their information is saved in a linked list, and various operations are performed like calculating totals deposited and withdrawn, identifying a random winner, and displaying information. The assignment asks students to insert at least 10 sample visitors and include output screenshots.

Uploaded by

Khizar Siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Computer Science CSC-221:Data structures & Algorithm

Bahria University Karachi Campus Semester 03 (SPRING 2021)

ASSIGNMENT 03
Marks: 5

NAME: KHIZAR HUSSAIN SIDDIQUI


EN.NO: 02-235201-036
CLASS: BS-IT(3A)
REG. NO. 67653
COURSE: DATA STRUCTURE AND ALGORITHM

Read Carefully:

WARNING: This is an individual assignment; you must solve it by yourself. Any form of
plagiarism will result in receiving zero in the assignment.

WARNING: Late submission will not be accepted. Any assignment submitted after the cutoff
time will receive zero.

• Submit SOFTCOPY on LMS in pdf format.

Q1. Consider there are n visitors visits LL bank every day. LL bank want to keep record of each
visitor who came for transaction (withdraw/deposit). Customers waits in a queue for their turn.
Specific information of each visitor is saved in a system such as Visitor_CNIC, Contact no. ,
Type of Transaction, Deposit_amount and Withdraw_amount. Whenever visitor get their turn to
get their information is saved in a system. As it the silver jubilee month of LL bank going on that
is why they are sending gifts to a lucky winner. For choosing a lucky winner they identify middle
visitor from a list of all visitors and send gift to them. At the end of a day, LL bank management
monitor about various details from the system which are as follows.
1. Total count of visitors visits bank.
2. Display all the details of visitors who visits LL bank that day.
3. Calculate and display total amount deposit today in a bank.
4. Calculate and display total amount withdraw from the bank.
5. Display total count of each type of transactions (withdraw/deposit) done.
6. Identify and display name of a lucky winner.
Implement the given scenario using linked list data structure. Insert data for at least 10 visitors
of your choice. Write down the code for given scenario and also attach the output screenshots in
sequence given above. Make sure to attach clear screenshots of output.
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

CODE:
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
using namespace std;
#define MIN_BALANCE 400
class InsufficientFunds{};
class Account
{
private:
long accountNumber;
string firstName;
string lastName;
float balance;
static long NextAccountNumber;
public:
Account(){}
Account(string fname, string lname, float balance);
long getAccNo()
{
return accountNumber;
}
string getFirstName()
{
return firstName;
}
string getLastName()
{
return lastName;
}
float getBalance()
{
return balance;
}
void Deposit(float amount);
void Withdraw(float amount);
static void setLastAccountNumber(long accountNumber);
static long getLastAccountNumber();
friend ofstream & operator<<(ofstream &ofs, Account &acc);
friend ifstream & operator>>(ifstream &ifs, Account &acc);
friend ostream & operator<<(ostream &os, Account &acc);
};
long Account::NextAccountNumber = 0;
class Bank
{
private:
map<long, Account> accounts;
public:
Bank();
Account openAccount(string fname, string lname, float balance);
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

Account balEnquiry(long accountNumber);


Account dep(long accountNumber, float amount);
Account withdraw(long accountNumber, float amount);
void closeAccount(long accountNumber);
void ShowAllAccounts();
~Bank();
};
int main()
{
Bank b;
Account acc;
int choice;
string fname, lname;
long accountNumber;
float balance;
float amount;
cout << "-----LL BANK-----" << endl;
do
{
cout << "\n\tPlease Select any of the option: ";
cout << "\n\t1 Open an new Account.";
cout << "\n\t2 Balance Enquiry.";
cout << "\n\t3 Cash Deposit.";
cout << "\n\t4 Cash Withdrawal.";
cout << "\n\t5 Close an Account.";
cout << "\n\t6 Show All Accounts Record.";
cout << "\n\t7 Quit.";
cout << "\nPlease Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
//account number is randomly generated.
cout << "Enter First Name: ";
cin >> fname;
cout << "Enter Last Name: ";
cin >> lname;
cout << "Enter Balance: ";
cin >> balance;
acc = b.openAccount(fname, lname, balance);
cout << endl << "Your Account is Successfully created :)." << endl;
cout << acc;
break;
case 2:
cout << "Enter Account Number:";
cin >> accountNumber;
acc = b.balEnquiry(accountNumber);
cout << endl << "Your Account Details are: " << endl;
cout << acc;
break;
case 3:
cout << "Enter Account Number:";
cin >> accountNumber;
cout << "Enter Balance:";
cin >> amount;
acc = b.dep(accountNumber, amount);
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

cout << endl << "Your Amount is Deposited." << endl;


cout << acc;
break;
case 4:
cout << "Enter Account Number:";
cin >> accountNumber;
cout << "Enter Balance:";
cin >> amount;
acc = b.withdraw(accountNumber, amount);
cout << endl << "Amount Successfully Withdrawn." << endl;
cout << acc;
break;
case 5:
cout << "Enter Account Number:";
cin >> accountNumber;
b.closeAccount(accountNumber);
cout << endl << "Account is Closed." << endl;
cout << acc;
case 6:
b.ShowAllAccounts();
break;
case 7: break;
default:
cout << "\nPlease choose correct option.";
exit(0);
}
} while (choice != 7);
return 0;
}
Account::Account(string fname, string lname, float balance)
{
NextAccountNumber++;
accountNumber = NextAccountNumber;
firstName = fname;
lastName = lname;
this->balance = balance;
}
void Account::Deposit(float amount)
{
balance += amount;
}
void Account::Withdraw(float amount)
{
if (balance - amount<MIN_BALANCE)
throw InsufficientFunds();
balance -= amount;
}
void Account::setLastAccountNumber(long accountNumber)
{
NextAccountNumber = accountNumber;
}
long Account::getLastAccountNumber()
{
return NextAccountNumber;
}
ofstream & operator<<(ofstream &ofs, Account &acc)
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

{
ofs << acc.accountNumber << endl;
ofs << acc.firstName << endl;
ofs << acc.lastName << endl;
ofs << acc.balance << endl;
return ofs;
}
ifstream & operator>>(ifstream &ifs, Account &acc)
{
ifs >> acc.accountNumber;
ifs >> acc.firstName;
ifs >> acc.lastName;
ifs >> acc.balance;
return ifs;
}
ostream & operator<<(ostream &os, Account &acc)
{
os << "First Name:" << acc.getFirstName() << endl;
os << "Last Name:" << acc.getLastName() << endl;
os << "Account Number:" << acc.getAccNo() << endl;
os << "Balance:" << acc.getBalance() << endl;
return os;
}
Bank::Bank()
{
Account account;
ifstream infile;
infile.open("Bank.data");
if (!infile)
{
return;
}
while (!infile.eof())
{
infile >> account;
accounts.insert(pair<long, Account>(account.getAccNo(), account));
}
Account::setLastAccountNumber(account.getAccNo());
infile.close();
}
Account Bank::openAccount(string fname, string lname, float balance)
{
ofstream outfile;
Account account(fname, lname, balance);
accounts.insert(pair<long, Account>(account.getAccNo(), account));
outfile.open("Bank.data", ios::trunc);
map<long, Account>::iterator itr;
for (itr = accounts.begin(); itr != accounts.end(); itr++)
{
outfile << itr->second;
}
outfile.close();
return account;
}
Account Bank::balEnquiry(long accountNumber)
{
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

map<long, Account>::iterator itr = accounts.find(accountNumber);


return itr->second;
}
Account Bank::dep(long accountNumber, float amount)
{
map<long, Account>::iterator itr = accounts.find(accountNumber);
itr->second.Deposit(amount);
return itr->second;
}
Account Bank::withdraw(long accountNumber, float amount)
{
map<long, Account>::iterator itr = accounts.find(accountNumber);
itr->second.Withdraw(amount);
return itr->second;
}
void Bank::closeAccount(long accountNumber)
{
map<long, Account>::iterator itr = accounts.find(accountNumber);
cout << "Account Deleted." << itr->second;
accounts.erase(accountNumber);
}
void Bank::ShowAllAccounts()
{
map<long, Account>::iterator itr;
for (itr = accounts.begin(); itr != accounts.end(); itr++)
{
cout << "Account " << itr->first << endl << itr->second << endl;
}
}
Bank::~Bank()
{
ofstream outfile;
outfile.open("Bank.data", ios::trunc);
map<long, Account>::iterator itr;
for (itr = accounts.begin(); itr != accounts.end(); itr++)
{
outfile << itr->second;
}
outfile.close();
}
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

OUTPUT:
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)

You might also like