I have this program and I did my .h file but I am having trouble with the .cpp file since they don't involve setters.
Create a class called DollarsCents for performing arithmetic with money. A driver program is given to you to test your class. Use integer variables to represent the private data members of the class:
int cents;
int dollars;
Here cents is the amount (number) of cents and dollars is the amount (number) of dollars. The private data members are set through the two-parameter constructor that has default values for these data members. This class has no setters. However, the values of cents and dollars can be updated via an assignment from one DollarsCents object to another. The cents and dollars data members should be reduced and stored in simplified form (where 0 <= cents < 99) after their values are set within the constructor or after some arithmetic operations. You must code a simplify function.
Provide member functions that perform each of the tasks given in the table below. Each of them should have public access, except for the simplify utility function, which should be a private member function:
return value: none
function: DollarsCents
parameters: int numCents=0
Task: Two parameter constructor with default values for dollasrs and cents provided in the prototype. It should set the dollars and cents data members in simplified form
return value: int
function: getDollars
parameters: none
task: returns the amount of dollars
return value: int
function: getCents
parameters: none
task: returns the amount of cents
return value: DollarsCents
function: Subtract
parameters: DollarCents dc
task: subtract another DollarsCents object from this one and return the result in a third DollarsCents object
return value: DollarsCents
function: add
parameters: DollarCents dc
task: Add another DollarsCents object to this one and return the result in a third DollarsCents object
return value: DollarsCents
function: multiply
parameters: int const num
task: Multiply this DollarsCents object by a whole no. and return the result in another DollarsCents object
return value: DollarsCents
function: divide
parameters: int const num
task: divide this DollarsCents object by a whole no. and return the result in a second DollarsCents object
discard any leftover cents
return value: void
function: simplify
parameters: none
task: utility function that simplifies the data members dollars and cents so that 0 <= cents <100
return value: void
function: print
parameters: none
task: Displays the DollarsCents object as a double
the main function is below:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "DollarsCents.h" // include definition of class DollarsCents
using namespace std;
int main()
{
cout << fixed << setprecision(2);
int const divideBy = 2;
int const multiplyBy = 3;
// Create three DollarsCents objects
DollarsCents dc;
int dollars1 = 2;
int cents1 = 2121;
DollarsCents dc1 (dollars1, cents1);
int dollars2 = 3;
int cents2 = 333;
DollarsCents dc2 (dollars2, cents2);
#include "DollarsCents.h"
/*******************************************************************************
* return value: none
* function: DollarsCents
* parameters: int numCents=0
* Task: Two parameter constructor with default values for dollasrs and cents
* provided in the prototype.
* It should set the dollars and cents data members in simplified form
*******************************************************************************/
DollarsCents::DollarsCents( int numCents )
{
cents = numCents;
dollars = 0;
simplify();
}
/*******************************************************************************
* return value: int
* function: getDollars
* parameters: none
* task: returns the amount of dollars
*******************************************************************************/
/*******************************************************************************
* return value: int
* function: getCents
* parameters: none
* task: returns the amount of cents
*******************************************************************************/
/*******************************************************************************
* return value: DollarsCents
* function: Subtract
* parameters: DollarCents dc
* task: subtract another DollarsCents object from this one
* and return the result in a third DollarsCents object
*******************************************************************************/
/*******************************************************************************
* return value: DollarsCents
* function: add
* parameters: DollarCents dc
* task: Add another DollarsCents object to this one and
* return the result in a third DollarsCents object
*******************************************************************************/
/*******************************************************************************
* return value: DollarsCents
* function: multiply
* parameters: int const num
* task: Multiply this DollarsCents object by a whole no.
* and return the result in another DollarsCents object
*******************************************************************************/
/*******************************************************************************
* return value: DollarsCents
* function: divide
* parameters: int const num
* task: divide this DollarsCents object by a whole no.
* and return the result in a second DollarsCents object
* Discard any leftover cents
*******************************************************************************/
/*******************************************************************************
* return value: void
* function: simplify
* parameters: none
* task: utility function that simplifies the data members dollars and cents
* so that 0 <= cents <100
*******************************************************************************/
void simplify( void )
{
// do logic
}
/*******************************************************************************
* return value: void
* function: print
* parameters: none
* task: Displays the DollarsCents object as a double
*******************************************************************************/
From there you could probably try compiling and check out the errors you will get, undefined functions for starters. Define all of the methods, do what you have to do to make it compile. Then add the logic to the functions. I did the constructor for you