Question

In: Computer Science

Problem Description: SavingsAccount Develop a C++ class declaration called SavingsAccount class that allows user to input...

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

Solutions

Expert Solution

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.


Related Solutions

Give a C++ class declaration called SavingsAccount with the following information: Operations (Member Functions) 1. Open...
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 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 Operations...
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
Write a C++ function called parse that reads one line of user input from the keyboard...
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input.  Your function should be passed the array and a reference variable that is to be assigned the length of the array.  Prompt the user and read the input from within the function. For example:  If the user inputs copy this that, the resulting array would have length 3 and contain the strings “copy”, “this”, and “that”....
C++ include a class called VendingMachine. A user can buy a bottle of water ($1.50), a...
C++ include a class called VendingMachine. A user can buy a bottle of water ($1.50), a bottle of coffee ($2.00), a chip ($1.00), and a chocolate bar ($2.50) from the machine. The user can select several item(s) if the items are available from the machine. Furthermore, the user can de-select item(s) that are already selected. After finishing the selection of item(s), the user can pay for the items with either a debit card (Valid PIN: 7777) or cash. A user...
Using RAPTOR create a program that allows the user to input a list of first names...
Using RAPTOR create a program that allows the user to input a list of first names in on array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. the output should be a list of email address where the address is of the following form: [email protected]
I am creating a program in Python that allows the user to input a credit card...
I am creating a program in Python that allows the user to input a credit card number, and determine if the card is valid. This should be done by taking every other number, starting from the right, and adding them together. The doubling each of the other digits, and adding them together as single digits, and then adding the two sums together. For example, if the number 4833 1200 3412 3456 is used, the first sum should be 6+4+2+4+0+2+3+8=29, the...
Create program which verifies if input string is a valid variable declaration or not. Use C...
Create program which verifies if input string is a valid variable declaration or not. Use C programming language. - This program can only use the following variable types: char, float, and int - Remove any newline \n from input string - The input prompt should say ">>> " - If input declaration is valid, it should print "Valid dec\n" - If input declaration is invalid, it should print "Invalid dec\n" - Make sure the identifier entered matches the rules of...
You have been asked to write program that allows the user to input a first name,...
You have been asked to write program that allows the user to input a first name, middle initial (without the period), and last name of a user and then display that person’s name with the first, middle initial followed by a period, and last name last. BEFORE creating the program, use structured programming principles to document how you are going to develop the program. Use Microsoft Word to complete this part of the assessment. Answer each of the following areas:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT