Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; class SavingsAccount { int dollars; int cents; int balance; public: void OpenAccount (int a, int b) { dollars = a; cents

image text in transcribed

#include

using namespace std;

class SavingsAccount

{

int dollars;

int cents;

int balance;

public:

void OpenAccount (int a, int b)

{

dollars = a;

cents = b;

if (b > 100)

{

balance = dollars + cents / 100;

}

else

{

balance = dollars + cents / 100;

}

}

void deposit (int deposit)

{

balance = balance + deposit;

}

void withdrawl (int amount)

{

balance = balance - amount;

}

void currBalance ()

{

cout

cout

cout

cout

}

};

int main ()

{

SavingsAccount bank1;

bank1.OpenAccount (200, 50);

bank1.currBalance ();

bank1.deposit (40.50);

bank1.currBalance ();

bank1.withdrawl (100.98);

bank1.currBalance ();

return 0;

}

image text in transcribed

#include

#include

using namespace std;

class SavingsAccount

{

int dollars;

int cents;

int balance;

public:

void OpenAccount ()

{

cout

cin >> dollars;

cout

cin >> cents;

if (cents > 100)

{

balance = dollars + cents / 100;

}

else

{

balance = dollars + cents / 100;

}

}

void deposit ()

{

cout

cin >> dollars;

cout

cin >> cents;

if (cents > 100)

{

balance = balance + dollars + cents / 100;

}

else

{

balance = balance + dollars + cents / 100;

}

}

void withdrawl()

{

cout

cin >> dollars;

cout

cin >> cents;

balance = balance - dollars - cents / 100;

}

void currBalance()

{

cout

cout

cout

cout

}

};

int main ()

{

SavingsAccount bank1;

bank1.OpenAccount();

char ch1,ch2;

deposits:

cout

cin>>ch1;

switch(ch1)

{

case 'y':

bank1.deposit();

goto deposits;

case 'n':

withdrawls:

cout

cin>>ch2;

switch(ch2){

case 'y':

bank1.withdrawl();

goto withdrawls;

case 'n':

bank1.currBalance();

break;

default:

cout

}

}

return 0;

}

image text in transcribed

--This part have has errors, could it be solved?

#include

using namespace std;

class SavingsAccount

{

int dollars;

int cents;

int balance;

public:

SavingsAccount(){

dollars = 0;

cents = 0;

if (cents > 100)

{

balance = dollars + cents / 100;

}

else

{

balance = dollars + cents / 100;

}

}

SavingsAccount(int x , int y){

dollars = x;

cents = y;

if (cents > 100)

{

balance = dollars + cents / 100;

}

else

{

balance = dollars + cents / 100;

}

}

void deposit ()

{

cout

cin >> dollars;

cout

cin >> cents;

if (cents > 100)

{

balance = balance + dollars + cents / 100;

}

else

{

balance = balance + dollars + cents / 100;

}

}

void withdrawl()

{

cout

cin >> dollars;

cout

cin >> cents;

balance = balance - dollars - cents / 100;

}

void currBalance()

{

cout

cout

cout

cout

cout

}

};

int main ()

{

SavingsAccount bank1(23,60); // initialise with dollars = 23 and cents = 60

char ch1,ch2;

cout

deposits:

cout

cin>>ch1;

switch(ch1)

{

case 'y':

bank1.deposit();

goto deposits;

case 'n':

withdrawls:

cout

cin>>ch2;

switch(ch2){

case 'y':

bank1.withdrawl();

goto withdrawls;

case 'n':

bank1.currBalance();

break;

default:

cout

}

}

SavingsAccount bank2; // automatically initialised with dollars = 0 and cents = 0

cout

deposits1:

cout

cin>>ch1;

switch(ch1)

{

case 'y':

bank2.deposit();

goto deposits;

case 'n':

withdrawls1:

cout

cin>>ch2;

switch(ch2){

case 'y':

bank2.withdrawl();

goto withdrawls1;

case 'n':

bank2.currBalance();

break;

default:

cout

}

}

return 0;

}

LAB 13.5 Student Generated Code Assignments Exercise 1: Give a C++ class declaration called SavingsAccount with the following information: Operations (Member Functions) 1. Open account (with an initial deposit). This is called to put i 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 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, 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 banki. The code will then initially place $200.50 in the account. The code will deposit $40.50 and then withdraw S100.98. It will print out the final value of dollars and cents. The following output should be produced: Dol lars 140 0ents 2 Part 2: Change the program to allow the user to input the initial values, deposit and withdrawal. Example Please input the initial dollars 402 Please input the initial cents 78 Nould you like to nake a deposit? Y or y for yes Please input the dollars to be deposited 35 Please input the cents to be deposited 67 Nould you like to nake a deposit? Y or y for yes Please input the dollars to be deposited 35 Please input the cents to be deposited 67 Nould you like to nake a deposit? Y or y for yes Nould you like to nake a withdrawal Y or y for yes Please input the dollars to be withdrawn 28 Please input the cents to be withdrawn 08 Nould you like to nake a withdrawal Y or y for yes Please input the dollars to be withdrawn 75 Please input the cents to be withdrawn 78 Nould you like to nake a withdrawal Y or y for yes Dollars 370 Cents26 Exerie2 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 Have the code generate two objects: bankl (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 bankl and bank2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions