Assignment 03: Marks: 5
Assignment 03: Marks: 5
ASSIGNMENT 03
Marks: 5
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.
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)
{
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)
OUTPUT:
Department of Computer Science CSC-221:Data structures & Algorithm
Bahria University Karachi Campus Semester 03 (SPRING 2021)