Give a C class declaration called savingsAccount with the fo

Give a C++ class declaration called savingsAccount with the following information: Operations (Member Functions) Open account (with an initial deposit). This is called to put initial values in dollars and cents. Make a deposit. A function that will add value to dollars and cents. Make a withdrawal. A function that will subtract values from dollars and cents. Show current balance. A function that will point dollars and cents. Data(Member Data) dollars cents Give the implementation code for all the member functions.

Solution

#include <iostream>

using namespace std;

class SavingsAccount {
public:
double dollars; // dollars variable
double cents; // cents variable

// Member functions declaration
void openAccount(int, int);
void makeDeposit(int, int);
void withdrawal(int, int);
void displayBalance();
};
// openAccount method declaration
void SavingsAccount::openAccount(int d, int c)
{
dollars = d;
cents = c;
//checks if cents is more than 100 then increment the dollar
while(cents >=100)
{
cents-=100;
dollars++;
}
}
// makeDeposit method declaration
void SavingsAccount::makeDeposit(int d, int c)
{
dollars += d;
cents += c;
//checks if cents is more than 100 then increment the dollar
while(cents >= 100)
{
cents -= 100;
dollars++;
}
}
// withdrawal method declaration
void SavingsAccount::withdrawal(int d, int c)
{
//checks if cents is more than 100 then increment the dollar
while(c >=100)
{
c -= 100;
d++;
};
//checks if cents withdrawn is more than currrent c than decrement the dollar
if(c > cents)
{
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
}
// displayBalance method declaration
void SavingsAccount::displayBalance()
{
cout << \"Dollars = \" << dollars << \" cents = \" << cents << endl;
};

int main()
{
SavingsAccount bank1;
bank1.openAccount(200,50);
bank1.makeDeposit(40,50);
bank1.withdrawal(100,98);
bank1.displayBalance();


return 0;
}

---------------------output--------------
Dollars = 140 cents = 2
-----------------------------------------

//program to take input from the user

#include <iostream>

using namespace std;

class SavingsAccount {
public:
double dollars; // dollars variable
double cents; // cents variable

// Member functions declaration
void openAccount(int, int);
void makeDeposit(int, int);
void withdrawal(int, int);
void displayBalance();
};
// openAccount method declaration
void SavingsAccount::openAccount(int d, int c) {
dollars = d;
cents = c;
//checks if cents is more than 100 then increment the dollar
while (cents >= 100) {
cents -= 100;
dollars++;
}
}
// makeDeposit method declaration
void SavingsAccount::makeDeposit(int d, int c) {
dollars += d;
cents += c;
//checks if cents is more than 100 then increment the dollar
while (cents >= 100) {
cents -= 100;
dollars++;
}
}
// withdrawal method declaration
void SavingsAccount::withdrawal(int d, int c) {
//checks if cents is more than 100 then increment the dollar
while (c >= 100) {
c -= 100;
d++;
};
//checks if cents withdrawn is more than currrent c than decrement the dollar
if (c > cents) {
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
}
// displayBalance method declaration
void SavingsAccount::displayBalance() {
cout << \"Dollars = \" << dollars << \" cents = \" << cents << endl;
};

int main() {
char answer; // To hold Y or N input.
int dollars = 0, cents = 0;
SavingsAccount bank1;
cout << \"This program will help create a new Savings Account!\" << endl;
cout << \"Enter the opening Dollars: \";
cin >> dollars;
cout << \"Enter the opening cents: \";
cin >> cents;

bank1.openAccount(dollars, cents);
cout << \"Input Dollars to Deposit:\" << endl;
cin >> dollars;
cout << \"Input Cents to Deposit:\" << endl;
cin >> cents;

bank1.makeDeposit(dollars, cents);

cout << \"Input Dollars to Withdrawl:\" << endl;
cin >> dollars;
cout << \"Input Cents to Withdrawl:\" << endl;
cin >> cents;
bank1.withdrawal(dollars, cents);

bank1.displayBalance();

return 0;
}
-------------output--------
This program will help create a new Savings Account!   
Enter the opening Dollars: 200
Enter the opening cents: 50   
Input Dollars to Deposit:   
40
Input Cents to Deposit:   
50
Input Dollars to Withdrawl:   
100   
Input Cents to Withdrawl:   
98
Dollars = 140 cents = 2
---------------------

//Note: Both the programs are provided seperatly. Feel free to ask any doubts. God bless you!

 Give a C++ class declaration called savingsAccount with the following information: Operations (Member Functions) Open account (with an initial deposit). This i
 Give a C++ class declaration called savingsAccount with the following information: Operations (Member Functions) Open account (with an initial deposit). This i
 Give a C++ class declaration called savingsAccount with the following information: Operations (Member Functions) Open account (with an initial deposit). This i
 Give a C++ class declaration called savingsAccount with the following information: Operations (Member Functions) Open account (with an initial deposit). This i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site