#include <iostream> #include <time.h> using namespace std; class BankAccount { p
ID: 3546478 • Letter: #
Question
#include <iostream>
#include <time.h>
using namespace std;
class BankAccount
{
public:
// constructors
BankAccount(){};
BankAccount(int);
// getters and setters
void setAccountNumber(int);
int getAccountNumber();
double getBalance();
void setBalance(double);
// account operations
void deposit(double);
bool withdraw(double);
protected:
int accountNumber; //account number
double balance; //balance
};
// member function definitions of BankAccount class
BankAccount::BankAccount(int num)
{
setAccountNumber(num);
balance = 0;
}
void BankAccount::setAccountNumber(int num)
{
accountNumber = num;
}
int BankAccount::getAccountNumber(){
return accountNumber;
}
double BankAccount::getBalance(){
return balance;
}
void BankAccount::setBalance(double bal){
balance = bal;
}
//deposits specified amount
void BankAccount::deposit(double amount)
{
balance = balance + amount;
}
//return true if withdrawl is successful
//otherwise returns false
bool BankAccount::withdraw(double amount)
{
if(balance < amount)
return false;
else
{
balance = balance - amount;
return true;
}
}
/* =======================================
* Checking Account inherits from BankAccount
* ======================================= */
class CheckingAccount :public BankAccount
{
public:
CheckingAccount();
CheckingAccount(int);
bool withdraw(double);
private:
int numOfWithdrawls; // number of withdrawl count
};
// member function definitions of CheckingAccount class
CheckingAccount::CheckingAccount():BankAccount()
{
numOfWithdrawls = 0;
}
CheckingAccount::CheckingAccount(int num):BankAccount(num)
{
numOfWithdrawls = 0;
}
// overridden withdrawl method
bool CheckingAccount::withdraw(double amount)
{
if(numOfWithdrawls > 3)
amount = amount + 50;
numOfWithdrawls++;
if( balance < amount)
return false;
else
balance = balance - amount;
return true;
}
/* =======================================
* Savings Account inherits from BankAccount
* ======================================= */
class SavingsAccount :public BankAccount
{
public:
SavingsAccount();
SavingsAccount(int);
void setAnnualInterest(double);
double getBalance();
double intEarnedSinceLastTrans();
int numOfDaysSinceLastTrans();
private:
// daily interest rate
double dailyInterestRate;
//interets earned since last transaction
double intEarnSinceLastTrans;
// number of days since last transaction occured
int numOfDays;
};
// member function definitions of SavingsAccount class
SavingsAccount::SavingsAccount():BankAccount()
{
numOfDays = rand()%8;
}
SavingsAccount::SavingsAccount(int num):BankAccount(num)
{
numOfDays = rand()%8;
}
void SavingsAccount::setAnnualInterest(double rate)
{
dailyInterestRate = rate/365;
}
int SavingsAccount::numOfDaysSinceLastTrans()
{
return numOfDays;
}
double SavingsAccount::intEarnedSinceLastTrans()
{
return numOfDays * dailyInterestRate;
}
double SavingsAccount::getBalance()
{
balance = balance + (numOfDays * dailyInterestRate);
numOfDays = rand()%8;
return balance;
}
//main function
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(NULL));
//saving and checking acc objetcs
SavingsAccount sa(12345);
CheckingAccount ca(54321);
//sets initila balance
sa.setBalance(100);
ca.setBalance(100);
//sets annual interets rate
sa.setAnnualInterest(0.03);
//displaying account details
cout<<"Account Number: "<<sa.getAccountNumber()<<endl;
cout<<"Account Type: Savings"<<endl;
cout<<"Balance: $"<<sa.getBalance()<<endl;
cout<<"Number of days since last transcation: "<<sa.numOfDaysSinceLastTrans()<<endl;
cout<<"Interest earned since last transaction: $"<<sa.intEarnedSinceLastTrans()<<endl;
cout<<" Account Number: "<<ca.getAccountNumber()<<endl;
cout<<"Account Type: Checking"<<endl;
cout<<"Balance: $"<<ca.getBalance()<<endl;
return 0;
}
Here are the two erroer msgs I am getting.
1>c:usersjenniferdocumentsisual studio 2012projectsconsoleapplication17consoleapplication17source.cpp(279): error C2061: syntax error : identifier '_TCHAR'
1>c:usersjenniferdocumentsisual studio 2012projectsconsoleapplication17consoleapplication17source.cpp(283): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Explanation / Answer
#include <iostream>
#include <time.h>
#include <tchar.h>
using namespace std;
class BankAccount
{
public:
// constructors
BankAccount(){};
BankAccount(int);
// getters and setters
void setAccountNumber(int);
int getAccountNumber();
double getBalance();
void setBalance(double);
// account operations
void deposit(double);
bool withdraw(double);
protected:
int accountNumber; //account number
double balance; //balance
};
// member function definitions of BankAccount class
BankAccount::BankAccount(int num)
{
setAccountNumber(num);
balance = 0;
}
void BankAccount::setAccountNumber(int num)
{
accountNumber = num;
}
int BankAccount::getAccountNumber(){
return accountNumber;
}
double BankAccount::getBalance(){
return balance;
}
void BankAccount::setBalance(double bal){
balance = bal;
}
//deposits specified amount
void BankAccount::deposit(double amount)
{
balance = balance + amount;
}
//return true if withdrawl is successful
//otherwise returns false
bool BankAccount::withdraw(double amount)
{
if(balance < amount)
return false;
else
{
balance = balance - amount;
return true;
}
}
/* =======================================
* Checking Account inherits from BankAccount
* ======================================= */
class CheckingAccount :public BankAccount
{
public:
CheckingAccount();
CheckingAccount(int);
bool withdraw(double);
private:
int numOfWithdrawls; // number of withdrawl count
};
// member function definitions of CheckingAccount class
CheckingAccount::CheckingAccount():BankAccount()
{
numOfWithdrawls = 0;
}
CheckingAccount::CheckingAccount(int num):BankAccount(num)
{
numOfWithdrawls = 0;
}
// overridden withdrawl method
bool CheckingAccount::withdraw(double amount)
{
if(numOfWithdrawls > 3)
amount = amount + 50;
numOfWithdrawls++;
if( balance < amount)
return false;
else
balance = balance - amount;
return true;
}
/* =======================================
* Savings Account inherits from BankAccount
* ======================================= */
class SavingsAccount :public BankAccount
{
public:
SavingsAccount();
SavingsAccount(int);
void setAnnualInterest(double);
double getBalance();
double intEarnedSinceLastTrans();
int numOfDaysSinceLastTrans();
private:
// daily interest rate
double dailyInterestRate;
//interets earned since last transaction
double intEarnSinceLastTrans;
// number of days since last transaction occured
int numOfDays;
};
// member function definitions of SavingsAccount class
SavingsAccount::SavingsAccount():BankAccount()
{
numOfDays = rand()%8;
}
SavingsAccount::SavingsAccount(int num):BankAccount(num)
{
numOfDays = rand()%8;
}
void SavingsAccount::setAnnualInterest(double rate)
{
dailyInterestRate = rate/365;
}
int SavingsAccount::numOfDaysSinceLastTrans()
{
return numOfDays;
}
double SavingsAccount::intEarnedSinceLastTrans()
{
return numOfDays * dailyInterestRate;
}
double SavingsAccount::getBalance()
{
balance = balance + (numOfDays * dailyInterestRate);
numOfDays = rand()%8;
return balance;
}
//main function
int _tmain(int argc, _TCHAR* argv[])
{
//srand(time(NULL));
srand((unsigned int)time(NULL));
//saving and checking acc objetcs
SavingsAccount sa(12345);
CheckingAccount ca(54321);
//sets initila balance
sa.setBalance(100);
ca.setBalance(100);
//sets annual interets rate
sa.setAnnualInterest(0.03);
//displaying account details
cout<<"Account Number: "<<sa.getAccountNumber()<<endl;
cout<<"Account Type: Savings"<<endl;
cout<<"Balance: $"<<sa.getBalance()<<endl;
cout<<"Number of days since last transcation: "<<sa.numOfDaysSinceLastTrans()<<endl;
cout<<"Interest earned since last transaction: $"<<sa.intEarnedSinceLastTrans()<<endl;
cout<<" Account Number: "<<ca.getAccountNumber()<<endl;
cout<<"Account Type: Checking"<<endl;
cout<<"Balance: $"<<ca.getBalance()<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.