Question

In: Computer Science

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 (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.

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.

Solutions

Expert Solution

GIVEN DATA:

Savings Account:

#include <iostream>
using namespace std;
class SavingsAccount {
public:
double dollars;
double cents;
void openAccount(int, int);
void makeDeposit(int, int);
void withdrawal(int, int);
void displayBalance();
};
void SavingsAccount::openAccount(int d, int c)
{
dollars = d;
cents = c;
while(cents >=100)
{
cents-=100;
dollars++;
}
}
void SavingsAccount::makeDeposit(int d, int c)
{
dollars += d;
cents += c;
while(cents >= 100)
{
cents -= 100;
dollars++;
}
}
void SavingsAccount::withdrawal(int d, int c)
{
while(c >=100)
{
c -= 100;
d++;
};
if(c > cents)
{
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
}
void SavingsAccount::displayBalance()
{
cout << "Dollars = " << dollars << " cents = " << cents << endl;
};

int main()
{
SavingsAccount bank1;
bank1.openAccount(200,50);
bank1.makeDeposit(40,50);
bank1.withdrawal(100,98);
bank1.displayBalance();


return 0;
}

Out Put:

Dollars = 140 cents = 2


//program to take input from the user:

#include <iostream>

using namespace std;

class SavingsAccount {
public:
double dollars;
double cents;
void openAccount(int, int);
void makeDeposit(int, int);
void withdrawal(int, int);
void displayBalance();
};
void SavingsAccount::openAccount(int d, int c) {
dollars = d;
cents = c;
while (cents >= 100) {
cents -= 100;
dollars++;
}
}
void SavingsAccount::makeDeposit(int d, int c) {
dollars += d;
cents += c;
while (cents >= 100) {
cents -= 100;
dollars++;
}
}
void SavingsAccount::withdrawal(int d, int c) {
while (c >= 100) {
c -= 100;
d++;
};
if (c > cents) {
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
}
void SavingsAccount::displayBalance() {
cout << "Dollars = " << dollars << " cents = " << cents << endl;
};
int main() {
char answer; // To hold Y or N input.
int dollars = 0, cents = 0;
SavingsAccount bank1;
cout << "This program will help create a new Savings Account!" << endl;
cout << "Enter the opening Dollars: ";
cin >> dollars;
cout << "Enter the opening cents: ";
cin >> cents;

bank1.openAccount(dollars, cents);
cout << "Input Dollars to Deposit:" << endl;
cin >> dollars;
cout << "Input Cents to Deposit:" << endl;
cin >> cents;

bank1.makeDeposit(dollars, cents);

cout << "Input Dollars to Withdrawl:" << endl;
cin >> dollars;
cout << "Input Cents to Withdrawl:" << endl;
cin >> cents;
bank1.withdrawal(dollars, cents);

bank1.displayBalance();

return 0;
}

Out Put:

This program will help create a new Savings Account!   
Enter the opening Dollars: 200
Enter the opening cents: 50   
Input Dollars to Deposit:   
40
Input Cents to Deposit:   
50
Input Dollars to Withdrawl:   
100   
Input Cents to Withdrawl:   
98
Dollars = 140 cents = 2


Related Solutions

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...
In C++ please Your class could have the following member functions and member variables. However, it's...
In C++ please Your class could have the following member functions and member variables. However, it's up to you to design the class however you like. The following is a suggestion, you can add more member variables and functions or remove any as you like, except shuffle() and printDeck(): (Note: operators must be implemented) bool empty(); //returns true if deck has no cards int cardIndex; //marks the index of the next card in the deck Card deck[52];// this is your...
Write a C++ programs to: 1. Create a class called Student with four (4) private member...
Write a C++ programs to: 1. Create a class called Student with four (4) private member variables, name (string), quiz, midterm, final (all double type); 2. Include all necessary member functions for this class (at least 1 constructor, 1 get function, and 1 grading function – see #6); 3. Declare three (3) objects of Student type (individual or array); 4. Read from the keyboard three (3) sets of values of name, quiz, midterm, final and assign them to each object;...
4.3 Lab: Queues 1 Write the c++ implementation of the following four member functions of the...
4.3 Lab: Queues 1 Write the c++ implementation of the following four member functions of the Queue class: getLength(): returns the number of elements in the queue isEmpty(): returns true if the queue is empty, false otherwise peek(): returns the value at the front of the queue without removing it. Assumes queue is not empty (no need to check) peekRear(): returns the value at the end of the queue without removing it. Assumes queue is not empty (no need to...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
In C++, implement a class called setOper that provides several simple set operations. The class only...
In C++, implement a class called setOper that provides several simple set operations. The class only needs to deal with sets that are closed intervals specified by two real numbers; for example, the pair (2.5, 4.5) represent the interval [2.5, 4.5]. The following operations should be supported: - Check if the value x belongs to the given interval. - Check if the value x belongs to the intersection of two intervals. - Check if the value x belongs to the...
1. A constructor is a special Class member method. It is automatically called when an object...
1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and abstraction are both the pillars of Object-Oriented...
In C++ Programming Language: 1a. Declare a class, namely ReverseUniverse, that contains three public member functions....
In C++ Programming Language: 1a. Declare a class, namely ReverseUniverse, that contains three public member functions. Please see Q2 and Q3 for the name of the second and third function. (5 points) Write a function string reverseString that reverses a string (first member function). It takes a string parameter and returns its reversed version. (10 points) 1b. In the class ReverseUniverse in Q1. Write a function vector reverseVector that reverses a vector (second member function). It takes a double vector...
5. In the following code snippet, which member function of the class Car is called first?...
5. In the following code snippet, which member function of the class Car is called first? class Car { public: void start(); void accelerate(double acc_speed); void stop(); double get_speed() const; Car(); private: double speed; }; Car::Car() { speed = 0; } void Car::start() { accelerate(get_speed() + 10); } void Car::stop() { speed = 0; } void Car::accelerate(double acc_speed) { speed = speed + acc_speed; } double Car::get_speed() const { return speed; } int main() { Car c1; c1.start(); c1.accelerate(10); c1.get_speed();...
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT