Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

\"font-size: 14pt; line-height: 115%; font-family: \"Times New Roman\",\"serif\"

ID: 3536219 • Letter: #

Question


"font-size: 14pt; line-height: 115%; font-family: "Times New Roman","serif";">

Could someone please help me with this assignment?


"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Exercise 1: Give a C++ class declaration called SavingsAccount with

the following information:

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Operations (Member Functions)

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

1. Open account (with an initial deposit). This is called to put

initial values in

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

dollars and cents.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

2. Make a deposit. A function that will add value to dollars and

cents

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

3. Make a withdrawal. A function that will subtract values from

dollars and

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

cents.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

4. Show current balance. A function that will print dollars and

cents.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Data (Member Data)

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

1. dollars

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

2. cents

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Give the implementation code for all the member

functions.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

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 234, then dollars must be increased by

2 and cents reduced to 34.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Write code that will create an object called bank1. The code will

then initially place $200.50 in the account. The code will deposit

$40.50 and then withdraw

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

$100.98. It will print out the final value of dollars and

cents.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

The following output should be produced:

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Dollars = 140 cents = 2.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Part 2: Change the program to allow the user to input the initial

values, deposit and withdrawal.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

270

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

LESSON SET 13

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Introduction to Classes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Example:

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the initial dollars

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

402

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the initial cents

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

78

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a deposit? Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

y

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the dollars to be deposited

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

35

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the cents to be deposited

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

67

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a deposit? Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

y

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the dollars to be deposited

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

35

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the cents to be deposited

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

67

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a deposit? Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

n

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a withdrawal Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

y

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the dollars to be withdrawn

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

28

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the cents to be withdrawn

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

08

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a withdrawal Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

y

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the dollars to be withdrawn

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

75

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Please input the cents to be withdrawn

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

78

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Would you like to make a withdrawal Y or y for yes

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

n

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Dollars = 370 Cents = 26

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">

Exercise 2: Replace the initial member function by two

constructors. One constructor is the default constructor that sets

both dollars and cents to 0. The other constructor has 2 parameters

that set dollars and cents to the indicated values.

"font-size: 12pt; line-height: 115%; font-family: "Times New Roman","serif";">

Have the code generate two objects: bank1 (which has its values set

during definition by the user) and bank2 that uses the default

constructor. Have the code input deposits and withdrawals for both

bank1 and bank2.

"font-size:12.0pt;line-height:115%;font-family: "Times New Roman","serif"">



Explanation / Answer

Here you go my friend - have fun


#include <iostream>
using namespace std;

class SavingsAccount
{
private:
    long dollars,cents;
public:
    SavingsAccount()
    {
    dollars=0;
    cents=0;
    }
    SavingsAccount(int newDol, int newCent)
    {
    dollars=newDol;
    cents=newCent;
    }

   void deposit (int depDol,int depCent)
   {
    dollars+=depDol;
    cents+=depCent;
    int extra=cents/100;
    dollars+=extra;
    cents=cents-extra*100;
   }

   void withdrawal(int wdDol, int wdCent)
   {
    int extra;
    if(wdCent>100)
    {
         extra=wdCent%100;
        wdDol+=extra;
        wdCent-=(wdCent/100);
    }
    if(wdDol>dollars)
    {
         cout<<"Insufficient funds. ";
         return;
    }
    dollars-=wdDol;
    cents-=wdCent;
    if(cents<0)
    {
         dollars--;
        cents+=100;
    }
   }

   double showBalance()
{
    double amt=dollars+cents/100.;
    return amt;
}
};

int main()
{
char choice='y';
int d,c;
cout<<"Input the initial dollars: ";
cin>>d;
cout<<"Input the initial cents: ";
cin>>c;
SavingsAccount a(d,c);
cout<<"Would you like to make a deposit(Y or y for yes)? ";
cin>>choice;

    while(choice=='y'||choice=='Y')
    {
        cout<<"Input the dollars to be deposited: ";
        cin>>d;
        cout<<"Input the cents to be deposited: ";
        cin>>c;
        a.deposit(d,c);
        cout<<"Would you like to make another deposit(Y or y for yes)? ";
        cin>>choice;
    }
cout<<"Would you like to make a withdrawal(Y or y for yes)? ";
cin>>choice;
    while(choice=='y'||choice=='Y')
    {
        cout<<"Input the dollars to be withdrawn: ";
        cin>>d;
        cout<<"Input the cents to be withdrawn: ";
        cin>>c;
        a.withdrawal(d,c);
        cout<<"Would you like to make another withdrawal(Y or y for yes)? ";
        cin>>choice;
    }
cout<<" Your balance is: $"<<a.showBalance()<<endl;
// cout<<"Dollars = "<<d<<" Cents = "<<c<<endl;
return 0;
}