I don't quite understand what you're doing here, at least not yet. But it did spark some ideas.
What if I moved the global vars from the member function file, into the class header, and made them public class vars, like this:
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
|
#ifndef RATIONAL_H
#define RATIONAL_H
/*
Create a class, Rational.
The class member functions are placed in 'public'
The class member variables are defined in private.
*/
class Rational
{
public:
//default constructor
Rational(int = 1, int = 1, int = 1, int = 1); // Rational default constructor initializes class Shapes's private data members
// public variables
int numerator_total;
int num1, num2; // each are set via cross multiplying the opposing fraction's denominator
int common_denominator; // set when multiplying each denominator
int numerator_total_set; // set when adding num 1 + num 2
/***** SET functions *****/
int set_add();
int set_subtract();
int set_multiply();
int set_add(int, int, int, int); // add 2 Rational numbers (add 2 fractions)
//int set_subtract(int, int, int, int);
//int set_divide(int, int, int, int);
/***** GET functions (printing results) *****/
void combine_fractions(int, int, int, int);
void get_dimensions(); // show dimensions which are input
void get_reduced_fraction(); //(int, int); // takes a fraction and puts it in reduced form
//void_get_decimal(); // prints fraction in decimal form
private:
//fraction 1
int numerator_1;
int denominator_1;
//fraction 2
int numerator_2;
int denominator_2;
};
#endif
#pragma once
| |
Then I was thinking, somehow, I'd be able to access and write to these public vars, using an object to publicly access them in
main.cpp. Something like:
t4.numerator_total = combine_fractions(7, 2, 4, 6);
t4.numerator_total_set = combine_fractions(7, 2, 4, 6);
t4.common_denominator = combine_fractions(7, 2, 4, 6);
t4.num1 = combine_fractions(7, 2, 4, 6);
t4.num2 = combine_fractions(7, 2, 4, 6);
All the public class vars are now written to.
Then, also in
main.cpp, I would then pass these vars into the function calls. Using ADD as an example,
int set_add(numerator_total_set, num1, num2, common_denominator);
This would pass these vars to the rewritten member function:
1 2 3 4 5 6 7 8 9 10 11
|
int set_add(numerator_total_set, num1, num2, common_denominator);
{
// add and prints combined fractions
cout << "\n***** ADD FRACTIONS *****" << endl;
numerator_total_set = num1 + num2;
cout << "\nAdded fractions = " << numerator_total_set << " / " << common_denominator << endl;
cout << endl;
return numerator_total_set;
}
| |
This would then return the mixed fraction with the public vars
numerator_total_set and
common_denominator being written to.
Finally, I would rewrite the member function for reducing fractions, call it from
main.cpp, pass these 2 public class vars in where they're received in the member function, as:
int Rational::get_reduced_fraction(int numerator_total_set, int common-denominator)
Does this make sense, or am I just on a wild goose chase?