Purchase Solution

Programming: Classes and objects

Not what you're looking for?

Ask Custom Question

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 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 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 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.
Example:
Please input the initial dollars
402
Please input the initial cents
78
Would you like to make a deposit? Y or y for yes
y
Please input the dollars to be deposited
35
Please input the cents to be deposited
67
Would you like to make a deposit? Y or y for yes
y
Please input the dollars to be deposited
35
Please input the cents to be deposited67
Would you like to make a deposit? Y or y for yes
n
Would you like to make a withdrawal Y or y for yes
y
Please input the dollars to be withdrawn
28
Please input the cents to be withdrawn
08
Would you like to make a withdrawal Y or y for yes
y
Please input the dollars to be withdrawn
75
Please input the cents to be withdrawn
78
Would you like to make a withdrawal Y or y for yes
n
Dollars = 370 Cents = 26
Problem 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. 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.

Purchase this Solution

Solution Summary

This Solution is demonstrated in a .cpp file. The classes and objects in programming are determined.

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.