In: Computer Science
Problem Description: SavingsAccount Develop a C++ class declaration called SavingsAccount class that allows user to input initial values of dollars and cents and then asks for deposits and withdrawals. The class should include the following information: Operations (Member Functions) 1. Default constructor that sets both dollars and cents to 0. 2. The constructor has 2 parameters that set dollars and cents to the indicated values. 3. Open account (with an initial deposit). This is called to put initial values in dollars and cents. 4. Make a deposit. A function that will add value to dollars and cents 5. Make a withdrawal. A function that will subtract values form dollars and cents. 6. Show current balance. A function that will print dollars and cents. Give the implementation code for all the member functions. Data (Member Data) 1. Dollars 2. Cents Have the code generate two objects: bank1: has its values set during definition by the user bank2: uses the default constructor. Have the code input deposit and withdraws for both bank1 and bank 2. Note: you must perform normalization in cents. This means that if cents is 100 or more, it must increment dollars by the appropriate amount. Example: If cents is 234, then dollars must be increased by 2 and cents reduced to 34. Write code that will create an object called bank1. The code will ten initially place $200.50 in the account. The code will deposit $40.50 and then withdraw $100.98. It will print out the final value of dollars and cents. The following output should be produced: dollars = 140 cents = 2
Code
#include<iostream>
using namespace std;
class SavingsAccount
{
public:
SavingsAccount();
SavingsAccount(int ,int);
void deposit(int,int);
void withdrawal(int,int);
int getDollar();
int getCent();
private:
int dollar,cent;
};
SavingsAccount::SavingsAccount()
{
dollar=0;
cent=2;
}
SavingsAccount::SavingsAccount(int d,int c)
{
dollar=d;
if(c>100)
{
dollar+=(c/100);
cent=c%100;
}
else
cent=c;
}
void SavingsAccount::deposit(int d,int c)
{
dollar+=d;
cent+=c;
if(cent>100)
{
dollar++;
cent=cent%100;
}
}
void SavingsAccount::withdrawal(int d,int c)
{
dollar-=d;
if(cent<c)
{
dollar--;
cent=100+cent-c;
}
else
cent-=c;
}
int SavingsAccount::getCent()
{
return cent;
}
int SavingsAccount::getDollar()
{
return dollar;
}
int main()
{
SavingsAccount bank1(200,50);
SavingsAccount bank2;
bank1.deposit(40,50);
bank1.withdrawal(100,98);
cout<<"dollars =
"<<bank1.getDollar()<<" cents =
"<<bank1.getCent()<<endl;
return 1;
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.