In C++ OUTPUT EXAMPLE: Account Management System In this project, you will write
ID: 3826527 • Letter: I
Question
In C++
OUTPUT EXAMPLE:
Account Management System In this project, you will write a program to manage a bank account and a stock portfolio. The program will be written using inheritance structure for the classes. Starting with the abstract base class Account write two derived classes stockAccount and bankAccount. All of the accounts should be linked together through the common cashBalance variable. The starting balance for the account will be $10000. The balance will change as you perform the transactions. In the main menu, you can select to work with either stock account, bank account, or exit the program. The sub menu for each will be as following Stock account Display current price for a stock symbol Buy stock Sell stock Display current portfolio Display transactions history Return to main menu Bank account Display current cash balance Deposit to account Withdraw from account Display transactions history Return to main menu 1. Stock Account This program manage your stock portfolio. You can purchase or sell stocks. Use the stock nformation in stock1 txt stock 2.txt stock 3.txt stock4.txt files for all of the transactions. When you initiate a transaction, you can randomly select one of the files for stock prices.Explanation / Answer
Bank account management system project in c++:-
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
using namespace std;
class acc
{
int ano;
char name[100];
int dep;
char type;
public:
void create_acc();
void show_acc() const;
void adep(int);
void draw(int);
void report() const;
int retano() const;
int retbal() const;
char qtype() const;
};
void acc::create_acc()
{
cout<<" Enter The Account Number :";
cin>>ano;
cout<<" Enter, Name of The Account Holder : ";
cin.ignore();
cin.getline(name,100);
cout<<" Enter Type of Account(Current/Savings) : ";
cin>>type;
cout<<" Enter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>dep;
cout<<" Congrats Account Has Been Created..";
}
void acc::show_acc() const
{
cout<<" Account Number : "<<ano;
cout<<" Account Holder Name : ";
cout<<name;
cout<<" Type of Account : "<<type;
cout<<" Balance amount : "<<dep;
}
void acc::adep(int x)
{
dep+=x;
}
void acc::draw(int x)
{
dep-=x;
}
void acc::report() const
{
cout<<ano<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<dep<<endl;
}
int acc::retano() const
{
return ano;
}
int acc::retbal() const
{
return dep;
}
char acc::qtype() const
{
return type;
}
void write_acc();
void display_sp(int);
void modify_acc(int);
void delete_acc(int);
void display_all();
void dep_withdraw(int, int);
void intro();
int main()
{
char ch;
int num;
intro();
do
{
system("cls"); //Clear The Screen
cout<<" ACTION MENU";
cout<<" 01. NEW ACCOUNT";
cout<<" 02. DEPOSIT";
cout<<" 03. WITHDRAW";
cout<<" 04. BALANCE ENQUIRY";
cout<<" 05. COMPLETE ACCOUNT HOLDERS LIST";
cout<<" 06. CLOSE AN ACCOUNT";
cout<<" 07. MODIFY AN ACCOUNT";
cout<<" 08. EXIT";
cout<<" Select Your Option (1-8) ";
cin>>ch;
system("cls"); //Clear The Screen
switch(ch)
{
case '1':
write_acc();
break;
case '2':
cout<<" Enter The Account Number : "; cin>>num;
dep_withdraw(num, 1);
break;
case '3':
cout<<" Enter The Account Number : "; cin>>num;
dep_withdraw(num, 2);
break;
case '4':
cout<<" Enter The Account Number : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<" Enter The Account Number : "; cin>>num;
delete_acc(num);
break;
case '7':
cout<<" Enter The Account Number : "; cin>>num;
modify_acc(num);
break;
case '8':
cout<<" Thanks For Visiting Our Bank!";
break;
default :cout<<"";
}
cin.ignore();
cin.get();
}while(ch!='8');
return 0;
}
void write_acc()
{
acc ac;
ofstream x;
x.open("info.dat",ios::binary|ios::app);
ac.create_acc();
x.write(reinterpret_cast<char *> (&ac), sizeof(acc));
x.close();
}
void display_sp(int n)
{
acc ac;
bool flag=false;
ifstream x;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be opened!! Press any Key to exit...";
return;
}
cout<<" BALANCE DETAILS ";
while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
if(ac.retano()==n)
{
ac.show_acc();
flag=true;
}
}
x.close();
if(flag==false)
cout<<" Account number does not exist";
}
}
void delete_acc(int n)
{
acc ac;
ifstream x;
ofstream y;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
y.open("Temp.dat",ios::binary);
x.seekg(0,ios::beg);
while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
if(ac.retano()!=n)
{
y.write(reinterpret_cast<char *> (&ac), sizeof(acc));
}
}
x.close();
y.close();
remove("info.dat");
rename("Temp.dat","info.dat");
cout<<" Record Deleted ..";
}
void display_all()
{
acc ac;
ifstream x;
x.open("info.dat",ios::binary);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<" ACCOUNT HOLDER LIST ";
cout<<"==================================================== ";
cout<<"A/c no. NAME Type Balance ";
cout<<"==================================================== ";
while(x.read(reinterpret_cast<char *> (&ac), sizeof(acc)))
{
ac.report();
}
x.close();
}
void dep_withdraw(int n, int option)
{
int amt;
bool found=false;
acc ac;
fstream x;
x.open("info.dat", ios::binary|ios::in|ios::out);
if(!x)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!x.eof() && found==false)
{
x.read(reinterpret_cast<char *> (&ac), sizeof(acc));
if(ac.retano()==n)
{
ac.show_acc();
if(option==1)
{
cout<<" TO DEPOSITE AMOUNT ";
cout<<" Enter The amount to be deposited";
cin>>amt;
ac.adep(amt);
}
if(option==2)
{
cout<<" TO WITHDRAW AMOUNT ";
cout<<" Enter The amount to be withdraw";
cin>>amt;
int bal=ac.retbal()-amt;
if((bal<500 && ac.qtype()=='S') || (bal<1000 && ac.qtype()=='C'))
cout<<"Insufficience balance";
else
ac.draw(amt);
}
int pos=(-1)*static_cast<int>(sizeof(ac));
x.seekp(pos,ios::cur);
x.write(reinterpret_cast<char *> (&ac), sizeof(acc));
cout<<" Record Updated";
found=true;
}
}
x.close();
if(found==false)
cout<<" Record Not Found ";
}
void intro()
{
cout<<" Welcome To XYZ BANK MANAGEMENT SYSTEM";
cout<<" A C++ Code Project by Student, Student At Army School Ranikhet";
cout<<" Press Enter To Continue........";
cin.get();
}