Student Generated Code Assignments Exercise 1: Give a C++ class declaration call
ID: 3778883 • Letter: S
Question
Student Generated Code Assignments Exercise 1: Give a C++ class declaration called s with the following information Operations (Member Functions) 1. Open account (with an initial deposit). This is called to put initial values in dollars and cents. 2. Make a deposit. A function that will add value to dollars and cents 3. Make a withdrawal. A function that will subtract values from dollars and Cents. 4. Show current balance. A function that will print dollars and cents. Data Member Data) 1. dollars 2. cents Give the implementation code for all the member functions. NOTE: You must perform normalization on cents. This means that if cents is 100 or more, it must increment dollars by the appropriate amount. Example: if cents is 4, then dollars must be increased by 2 and cents reduced to 34. Write code that will create an object called bankl. The code will then 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. Part 2: Change the program to allow the user to input the initial values, deposit and withdrawal.Explanation / Answer
#include<iostream>
using namespace std;
class SavingsAccount
{
private:
int dollars;
int cents;
public:
void setOpen(int, int);
void setDeposit(int, int);
void setWithdrawl(int, int);
void showBalance();
};
void SavingsAccount::setOpen(int d, int c)
{
dollars = d;
cents = c;
cout << "Input Dollars for Opening Balance:"<<endl;
cin >> dollars;
cout << "Input Cents for Opening Balance:"<<endl;
cin >> cents;
while(cents >=100)
{
cents-=100;
dollars++;
}
}
void SavingsAccount::setDeposit(int d, int c)
{
dollars = d;
cents = c;
cout << "Input Dollars to Deposit:"<<endl;
cin >> dollars;
cout << "Input Cents to Deposit:"<<endl;
cin >> cents;
dollars += d;
cents += c;
while(cents >= 100)
{
cents -= 100;
dollars++;
}
}
void SavingsAccount::setWithdrawl(int d, int c)
{
dollars = d;
cents = c;
cout << "Input Dollars to Withdrawl:"<<endl;
cin >> dollars;
cout << "Input Cents to Withdrawl:"<<endl;
cin >> cents;
while(c >=100)
{
c -= 100;
d++;
};
if(c > cents)
{
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
}
void SavingsAccount::showBalance()
{
cout << "Your current balance is: $" << dollars << "." << cents << endl;
};