60 371
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #4068 in C++ for Mark Joven M Vergara

Question #4068
4. A bank in your town updates its customers’ accounts at the end of each month. The bank offers two types of accounts: Savings and Checking. Every customer must maintain a minimum balance. If a customer’s balance falls below the minimum balance, there is a service charge of P100.00 for savings accounts and P250.00 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:

a.) Savings account receives 4% interest.
b.) Checking accounts with balances of up to P5000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.

Write a program that will input a customer’s account number (int type), account type (char type; s for savings, c for checking), minimum balance that the account should maintain, and current balance. The program should then output the account number, account type, current balance, and an appropriate message.
(USING IF AND ELSE AND SWITCH ONLY)
Expert's answer
#include "stdafx.h"
#include <fstream>
#include
<conio.h>
#include <iostream>
#include
<stdlib.h>
#include <string>


using namespace
std;
//Class Account
class Account{
private:
string name;//name of
user
double checkingAccount;//checking Account data
double
savingAccount;//saving Account data
int numberofTransaction; //Number of
transaction
int input;
int acountNumber;//account number
public:

//Input data about account
void getData(){
cout << "\nEnter
name: ";
cin >> name;
cout<<"Enter 9-digit acount number:
";
cin>>acountNumber;
}
//Return data about account
void
showData(){
cout <<"\n\nAcount Number: "<<acountNumber;//input
account number
cout << "\nName: " << name; //input account
name
cout << "\nCheckingAccount: "<< checkingAccount;// input
checking Account
cout << "\nSavingAccount: "<< savingAccount;
//input saving Account

}
//Deposit to account number
void
Deposit(){
cout << "Which account would you like to deposit
to?\n";
cout << "1. Checking Account\n";
cout << "2. Saving
Account\n";
cin>> input;
if (input == 1)
{
double
checkingAcc;
checkingAccount=0;//Initialize
checkingAccount
savingAccount=0; //Initialize savingAccount
cout <<
"How much do you want to deposit to the Checking Account?\n";
cin >>
checkingAcc;//Deposit to
checkingAccount
checkingAccount+=(checkingAcc-checkingAcc*0.01);
cout
<< "The sum "<<checkingAcc<<" was deposited to the Checking
Account\n";
}
if (input ==2)
{
double
savingAcco;
checkingAccount=0;//Initialize
checkingAccount
savingAccount=0;//Initialize savingAccoun
cout <<
"How much do you want to deposit to the Saving Account?\n";
cin
>>savingAcco;
savingAccount+=savingAcco-savingAcco*0.015; //Deposit to
savingAccount
cout << "The sum "<<savingAcco<<" was
deposited to the Saving Account\n";
}
}
//withdrawal to account
number
void withdrawal(){
int input;
cout << "From which account
would you like to withdraw?\n";
cout << "1. Checking\n";
cout
<< "2. Saving\n";
cin >> input;
if (input == 1)
{
double
checkingAcc=0;
cout << "How much would you like to withdraw from the
Checking account?\n";
cin >>
checkingAcc;
checkingAccount-=checkingAcc;//withdraw from checking
Account

}
if (input == 2)
{
double savingAcco;
cout <<
"How much would you like to withdraw from the Saving account?\n";
cin
>>savingAcco;
savingAccount-=savingAcco; //withdraw from saving
Account
}
}
//Get Saving Account balance
double
getSavingAccountbalance(){
return savingAccount;
}
//Get Checking
Account balance
double getCheckingAccount(){
return
checkingAccount;
}
//Count for transactions
double
countForTransaction(){
numberofTransaction+=1;
}
//Get name of
account
string getName(){
return name;
}

int
getacountNumber(){
return acountNumber;
}

};
//class Savings
account
class Savings: public Account
{

public:
Savings(){}
Savings(double newBalance, double
newInterestRate);

double withdrawal(double amount);
double
deposit(double amount);


protected:

double getRate()
const;
double setRate();

private:

double
interestRate;

};
//class Checking account
class Checking: public
Account {

public:
Checking(){}
Checking(double
newBalance);

double withdrawal(double);
double
deposit(double);
};

Account account;//Creat account

//Main
function
int _tmain(int argc, _TCHAR* argv[])
{
char ch;
fstream
file,file1;
Savings savaccout;
Checking checkingacount;
int
choice;
int count=0;
cout << "WELCOME TO PROGRAMMING
BANK!\n\n";
cout << "WHAT WOULD YOU LIKE TO DO?\n";
int
accountID=0;
char chforDeposit;
file.open("Account.DAT", ios::app |
ios::out | ios::in | ios::binary );
do {
//Menu
cout << "\t1.
Registration new account.\n";
cout << "\t2. View Your Account
Information.\n";
cout << "\t3. View All Accounts
Information.\n";
cout << "\t4. Deposit.\n";
cout << "\t5.
Withdraw.\n";
cout << "\t6. Exit.\n\n";
cout <<"Please enter
your choice: \n";
cin >> choice;
//Select one of item
menu
switch(choice){
case 1:
cout << "Enter account's data:";

account.getData();
accountID=account.getacountNumber();
cout <<
"\nDo you want to deposit for this account? (y/n)";

cin>>chforDeposit;
if(chforDeposit=='y'){
account.Deposit();//
}
file.write(
reinterpret_cast<char*>(&account), sizeof(account) );

file.close();//Close file Account.DAT
file.open("Account.DAT", ios::app |
ios::out | ios::in | ios::binary ); //Read from file Account.DAT-it's binary
file
file.read(reinterpret_cast<char*>(&account), sizeof(account)
);
cout << "\nAccount:";
while(!file.eof() ){

if(account.getacountNumber()==accountID){
account.showData();
}
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );
}
cout
<<"\n";
break;
case 2:
cout << "\nEnter account number
:";
cin>>accountID;
file.close();//Close file
Account.DAT
file.open("Account.DAT", ios::app | ios::out | ios::in |
ios::binary ); //Read from file Account.DAT-it's binary
file
file.read(reinterpret_cast<char*>(&account), sizeof(account));

while(!file.eof() ){

if(account.getacountNumber()==accountID){
account.showData();
count+=1;
}
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );

}
if(count==0){
count=0;
cout<<"\nNo such
account\n";
}
cout<<"\n";
break;
case 3:
cout <<
"\nAccount:";
file.close();
file.open("Account.DAT", ios::app | ios::out |
ios::in | ios::binary );

file.read(reinterpret_cast<char*>(&account), sizeof(account));

while(!file.eof() ){
account.showData();
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );

}
cout<<"\n";
break;

case 4:
cout << "\nEnter
account number
:";
cin>>accountID;
file.close();
file.open("Account.DAT",
ios::app | ios::out | ios::in | ios::binary );

file.read(reinterpret_cast<char*>(&account), sizeof(account));

while(!file.eof() ){

if(account.getacountNumber()==accountID){
account.showData();
cout<<"\n";
account.Deposit();
count+=1;
}
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );

}
if(count==0){
count=0;
cout<<"\nNo such
account\n";
}
cout<<"\n";

break;
case 5:
cout <<
"\nEnter account number
:";
cin>>accountID;
file.close();
file.open("Account.DAT",
ios::app | ios::out | ios::in | ios::binary );

file.read(reinterpret_cast<char*>(&account), sizeof(account));

while(!file.eof() ){

if(account.getacountNumber()==accountID){
account.showData();
cout<<"\n";
if(account.getCheckingAccount()>0
|| account.getSavingAccountbalance()>0
){
account.withdrawal();
}else{
cout<<"\nCheckingAccount < 0
or SavingAccount < 0";
}
count+=1;
}
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );

}
if(count==0){
count=0;
cout<<"\nNo such
account\n";
}
file.close();
file.open("Account.DAT", ios::app |
ios::out | ios::in | ios::binary );

file.read(reinterpret_cast<char*>(&account), sizeof(account));

while(!file.eof() ){

if(account.getacountNumber()==accountID){
account.showData();
cout<<"\n";
if(account.getCheckingAccount()>0
|| account.getSavingAccountbalance()>0
){
account.withdrawal();
}else{
cout<<"\nCheckingAccount < 0
or SavingAccount < 0";
}
count+=1;
}
file.read(
reinterpret_cast<char*>(&account), sizeof(account) );

}
cout<<"\n";
break;

default:
cout<<"\nIncorrect
entering\n";
}
}while(choice!=6); //Exit if choice of menu item is 6

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions