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
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]
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
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:...
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...
Write a OOP class called BookList that uses a Book class and allows multiple books to...
Write a OOP class called BookList that uses a Book class and allows multiple books to be entered into a BookList object. Include normally useful methods and boolean addBook(Book b), Book searchBook(String title, String author). addBook returns true if b is successfully added to the list. searchBook returns a book matching either the title or author from the current list. You do not need to write Book (assume there are suitable constructors and methods) or any test code (main). You...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT