Help with making a function perform on the operator

I figured out how to correct the code. Now I need assitance with making the correct values display and how to play the fracMult(f2) be perormed on f1


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
class fraction

{
    private:
        int numerator;
        int denom;
        bool positive;
    
    public:
        void inputFrac();
        void printFrac();
     
        fraction fracMult(fraction b);
        fraction fracDiv(fraction b);
        fraction fracAdd(fraction b);
        fraction fracSub(fraction b);
};

 void fraction::printFrac()
{
    if (!positive)
    {
    cout << "-";
    }
    cout << numerator << " / " << denom;
}
void fraction::inputFrac()
{    
    cout<<"Please input the numerator ";
    cin>>numerator;
    cout<< "Please input the denominator ";
    cin>>denom;           
}

 fraction fraction::fracMult(fraction b)
{
     
     numerator=b.numerator;
     denom=b.denom;
}

int main(int argc, char** argv) {

    fraction f1, f2, fresult;
    
    f1.inputFrac(); //input the first fraction
    f2.inputFrac(); //input the second fraction
    cout<<endl;
    f1.printFrac();
    cout<<endl;
    f2.printFrac();
    cout<<endl;

    cout << "The result of a * b is: ";
    
    fresult = f1.fracMult(f2); // calculate a * b
    fresult.printFrac(); // print out the result 
Last edited on
Please just use one topic. Post this code over in http://www.cplusplus.com/forum/beginner/179741/
Topic archived. No new replies allowed.