NEED HELP ON PROGRAM

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#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); 

// Addition

cout << “Adding “ << dollars2 << “ dollars and “ << cents2 
     << “ cents” << endl;
cout << “To “ << dollars1 << “ dollars and “ << cents1 
<< “ cents :“ << endl << endl;  

dc1.print(); 			// prints DollarsCents object dc1
cout << " + ";
dc2.print();  			// prints DollarsCents object dc2		

dc = dc1.add(dc2); 	  	// adds object dc2 to dc21 
cout << " = ";          	// places results in DollarsCents dc
dc.print(); 			// prints DollarsCents object dc
cout << endl << endl;

// Subtraction

cout << “Subtracting “ << dollars2 << “ dollars and “ << cents2 
     << “ cents” << endl;
cout << “From “ << dollars1 << “ dollars and “ << cents1 
<< “ cents:“ << endl << endl;

dc1.print(); 			// prints DollarsCents object dc1
cout << " - ";
dc2.print();  			// prints DollarsCents object dc2				
dc = dc1.subtract(dc2); 	// subtracts object dc2 from dc1 
cout << " = ";          	// places results in DollarsCents dc
dc.print(); 			// prints DollarsCents object dc
cout << endl << endl;

// Multiplication by a constant

cout << “Multiplying “ << dollars1 << “ dollars and “ << cents1 
     << “ cents” << “ by “ << multiplyBy << “:“ << endl << endl;

dc1.print(); 			// prints DollarsCents object dc1
cout << " * " << multiplyBy;
				
dc = dc1.multiply(multiplyBy); // multiplies object dc1 by multiplyBy
cout << " = ";          	      // places results in DollarsCents dc
dc.print(); 				 // prints DollarsCents object dc
cout << endl << endl;
           
// Division by a constant 

cout << “Dividing “ << dollars1 << “ dollars and “ << cents1 
     << “ cents” << “ by “ << divideBy << “:“ << endl << endl;

dc1.print(); 			// prints DollarsCents object dc1
cout << " / " << divideBy;
				
dc = dc1.divide(divideBy); 	// divides object dc1 in divideBy
cout << " = ";          		// places results in DollarsCents dc
dc.print(); 				// prints DollarsCents object dc
cout << endl << endl;
   	
system("pause");
return 0;
} // end main



ANYTHING WILL HELP
Last edited on
There are no questions in your post.
I don't even know where to start with the .h file, I have all the information that goes in the file, I just do not know what to do. I had no trouble with the main file, I just don't know how to do the .h file. I need help with that, it's not an actual question just me saying I need help getting started maybe with examples or if someone could code it. It is for a study guide in preparation for an exam.
Basically, you need to write a class named DollarsCents, which will be used to perform arithmetic on money. The class declaration needs to go into a header file named "DollarsCents.h", and it's implementation should go in a separate .cpp file.
Based on the "driver program" which was given to you (main() function), you can figure out what methods the class needs, and how those methods should be used.

By looking at the main() function, here are some methods your class will need.

1.)Default constructor

2.)Constructor which takes dollars and cents as parameters

3.)Method to print dollars and cents (method name "print()")

4.)Method which takes a DollarsCents object, adds the dollars and cents from that object to itself and returns a DollarsCents object (method name "add()")

5.)Method which does the same thing, just with subtraction (method name "subtract()")

6.)Method which takes a constant integer to multiply its dollars and cents with, and returns a DollarCents object (method name "multiply()")

7.)Method which does the same thing, just with division (method name "divide()")

8.)Possibly Operator overloading of =
Last edited on
That is what the directions said as well, I was more looking for an example or a format to follow
Most of the people here have taken at least one programming course. To anyone of them, you come across as the typical I-screwed-around-the-entire-course-and-now-that-there's-an-exam-in-two-days-I-need-to-get-this-or-fail guy. No one wants to help someone like that.

If you were given this assignment, you should at least have the vaguest of ideas of how to get started. If you're truly completely lost then there's no example that will help you. If you aren't, then you should be able to write something. Something that will tell us we're not just wasting our time by helping you. If you can, then go do it and come back when you get stuck.
If you can't, then read this, and good luck: http://www.cplusplus.com/doc/tutorial/
Not to be rude, but I created an account for help. I am not a programmer, nor do Iwant to be in the future. I am taking this course to meet a requirement and am unfortunately at a community college that offers little help to students who need help in computer science classes. I have not screwed around all course I simply just do not grasp the concept of header files and my professor isn't helping in a way that I understand. But thank you for the lecture. I will gladly wait for someone who is willing to help someone who simply needs help. I am not a procrastinator and if you don't want to help "someone like that" then please keep it to yourself. Thanks.
and for the record this is the first programming course I have ever taken and my exam is in a week and a half.
I'm sorry to hear that you have to take this course for a requirement, even though you may or may not be interested in the field.
However, helios was not exaggerating. The only way anyone will write code for you (and even then it will be out of pity) is if you can make us believe that you really had a good, long talk with your instructor, and told him/her what's troubling you. I can't know if you have seeked their guidance, but it's important just to reiterate that they should be the first person you ask for help anyways.

So, it's not because we hate beginners, it's because we have conflicting expectations.
Topic archived. No new replies allowed.