Classes and Objects - Help please

I'm learning how to work with classes and objects, however I'm having issues with comprehending what to do. I get the fundamentals like what classes are, the member variables and the functions. But I'm having issues on how to write the definitions for the functions of the class such as the constructors. below is the problem I'm working on. if someone could walk me through it that would be great. I'm not looking for someone to do my assignment for me because I really do want to understand this and I feel like I've used up enough of my instructors time outside of class. but if someone could help and explain how to write the function definitions that would be awesome.

Dollars class. In general banks do not use floating-point data types (such as double) to store amounts of money, because calculations involving floating-point numbers are inherently imprecise. Accordingly, create a class called Dollars, representing an amount of money in dollars — your class (despite its name) will store the amount of money as the number of cents using a long long member variable (an integer type, thereby solving the precision problem). Provide the following member functions in your class:
constructor taking a double parameter (the number of dollars) — e.g., Dollars(5.0) should give a Dollars object representing $5 and Dollars(113.87) would representing $113.87.
constructor taking a long long parameter (the number of cents) — e.g., Dollars(500) would be $5 and Dollars(11387) would be $113.87.
Dollars add(Dollars other) and Dollars subtract(Dollars other) — adds/subtracts this number of dollars and returns a new Dollars of the result (e.g. $50 + $40.09 = $90.09)
Dollars multiply(double factor) and Dollars divide(double factor) — multiplies/divides this number of dollars and returns a new Dollars (e.g. $50 * 1.25 = $62.50)
double toDouble() — returns a double version of the number of dollars ($90.09 would return the double 90.09)
void print(ostream &out = cout) — prints the amount of money in dollars, e.g. "$132.68" (make sure to get exactly two digits after the decimal point). Negative amounts of dollars should be put in parentheses, e.g. "($10.57)" would represent a deficit of $10.57.

below is the code I've written so far.

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
  #include <iostream>
using namespace std;

class Dollars{

private:
    long long cents;
public:




    long long int getCents() const {
        return cents;
    }

    // constructors:
    Dollars ();
    Dollars (double dollars);
    Dollars (long long initCents);

    // member functions:
    Dollars add(Dollars other)const;
    Dollars subtract(Dollars other)const;
    Dollars multiply(double factor)const;
    Dollars divide(double factor)const;
    double toDouble()const;
    void Print(ostream &out = cout)const;
};

Dollars::Dollars(){
    cents = 0;
}
Dollars::Dollars(double dollars){
    cents = dollars*10;
}



int main() {
    Dollars f;
    f = 4.22;

    Dollars input2(long long cents = 560);





    return 0;
}

Dollars add(Dollars other){

}
add(...) would look like this:
1
2
3
4
5
Dollars Dollars::add(Dollars other){ // Note the scope Dollars::
  Dollars result;
  result.cents = cents + other.cents;
  return result;
}
Similar for subtract(...).

Line 35: You need to multiply by 100 not 10.
Topic archived. No new replies allowed.