Question
Calling Fraction() C++ PLEASE DO NOT ANSWER WITH OTHER POSTED ANSWERS . ATTACHED ARE THE ASSIGNMENT AND OUTPUT SAMPLES. PLEASE UPDATE AND ADD FUNCTIONS AS
Calling Fraction() C++
PLEASE DO NOT ANSWER WITH OTHER POSTED ANSWERS. ATTACHED ARE THE ASSIGNMENT AND OUTPUT SAMPLES.
PLEASE UPDATE AND ADD FUNCTIONS AS NEEDED. AVOID AS POSSIBLE TO CHANGE THE FUNCTIONS I ALREADY HAVE.
TRY TO SEND COPIES OF FRACTIONS IN EACH MENU // ex: menuAdding(Fraction*, Fraction*)
AND PLEASE, READ THE NOTES AND MAKE CHANGES BASE ON THE FOLLOWING CODING. AND THANKS IN ADVANCE
NOTE: int main() // should call:
displayClassInfoYourName(); // do not worry about this one
menuHw4(); // inside menuHw#4, it should include the calling of each submenu. ex: calling menuAdding, calling menuSubtracting...
NOTE: void build2Fraction(Fraction** , Fraction** ); // IT IS REQUIRED.
THE CURRENT CODING IS:
class Fraction {
public:
Fraction(); // Default constructor
Fraction(int);
Fraction(int, int);
Fraction(const Fraction&); // Copy Constructor
~Fraction(); // destructor
void setNum(int); // Function Member to set numerator
void setDenom(int); // Function Member to set denominator
int getNum(void) const; // Function Member to get numerator. get back the value
int getDenom(void) const; // Function Member to get denominator
int getCommondBF(int, int) const; // get common factor
void print(void) const; // print current Fraction object
Fraction add(const Fraction&);
Fraction subtract(const Fraction&);
Fraction multiply(const Fraction&);
Fraction divide(const Fraction&);
Fraction operator=(const Fraction& that);
Fraction operator+(const Fraction& that);
Fraction operator-(const Fraction& that);
Fraction operator*(const Fraction& that);
Fraction operator/(const Fraction& that);
private:
int num;
int denom;
};
//stand-alone functions
void displayClassInfoYourName(void); // do not worry about this one
Fraction init(); // setting up or updating 2 required Fraction objects Fraction add(const Fraction&, const Fraction&); Fraction subtract(const Fraction&, const Fraction&); Fraction multiply(const Fraction&, const Fraction&); Fraction divide(const Fraction&, const Fraction&);
void build2Fraction(Fraction** , Fraction** );
void menuHw1Ex4(void);
void menuInit();
void menuAdding();
void menuSubtracting(void);
void menuMultiplying(void);
void menuDividing(void);
void menuPrint(void);
void print(void); // print required Fraction objects
int main() {
displayClassInfoYourName();
menuHw4();
return 0; }
Fraction::Fraction() : num(0), denom(1) {
cout
void Fraction::setNum(int n) { int num; int commonFactor; num = n; num
int Fraction::getNum() const { return num; } // gets the numerator
void Fraction::setDenom(int d) { int denom; int commonFactor; denom = d; commonFactor = getCommondBF(num, denom); // calling function to get common factor denom /= commonFactor; // get denom factor
} // sets the denominator
int Fraction::getDenom(void) const { return denom; } // gets the denominator
int Fraction::getCommondBF(int n, int d) const { int gcd = 1; int tmp = (num
//Stand Alone Function Definition
void menuHw1Ex4() {
int option;
do {
cout
"* MENU - HW #4 * "
"* 1. Initializing * "
"* 2. Adding * "
"* 3. Subtracting * "
"* 4. Multiplying * "
"* 5. Dividing * "
"* 6. Printing * "
"* 7. Quit * "
"*********************"
cout
cin >> option;
switch (option) {
case 1:
cout
menuInit();
break;
case 2:
cout
if (!lOp || !rOp) {
cout
"are available!"
}
else
menuAdding();
break;
case 3:
cout
if (!lOp || !rOp) {
cout
"are available!"
}
else
menuSubtracting();
break;
case 4:
cout
if (!lOp || !rOp) {
cout
"are available!"
}
else
menuMultiplying();
break;
case 5:
cout
if (!lOp || !rOp) {
cout
"are available!"
}
else
menuDividing();
break;
case 6:
cout
if (!lOp || !rOp) {
cout
"are available!"
}
else
menuPrint();
break;
case 7:
cout
break;
default:
cout
break;
}
} while (option != 7);
}
void print() { // print required Fraction objects }
void build2Fraction(Fraction** leftPtr, Fraction** rightOp) { }
Fraction init() { // setting up or updating 2 required Fraction objects return Fraction(); } Fraction add(const Fraction& leftOp, const Fraction& rightOp) { return Fraction(); } Fraction subtract(const Fraction& leftOp, const Fraction& rightOp) { return Fraction(); } Fraction multiply(const Fraction& leftOp, const Fraction& rightOp) { return Fraction(); } Fraction divide(const Fraction& leftOp, const Fraction& rightOp) { return Fraction(); } void displayClassInfoYourName() { cout CIS25-C++ Programming: Homework #4-Page 2 of 10 1. Code Assignment/Exercise Exercise 1 A. Update the Fraction class given in the Lecture notes or as discussed in class meetings as follows, 1. Add your FIRST NAME and the initial of your last name to the name Fraction and use this as your updated class. For examples, if your first name is John Smith then updatc thc class namc to bc FractionJohns 2. Add and update all class constructors for your Fraction class to handle the initialization appropriately There must be as least 2 constructors of (i) Default; and i Copy Each constructor should print the confirmation (e.g., "Calling Fraction )", or "Calling Fraction (const Fraction&)) 3- Provide a destructor with a confirmation when removing the object (i.e., Calling Fraction )"). 4. Provide get/set member functions for each private member data 5. A member function print that will print the current Fraction object. B. Provide the following member functions, a. A function add) to add a Fraction objcct; and b. A function subtract) to subtract a Fraction object; and c. A function multiply) to multiply a Fraction objcct; and d. A function divide) to divide a Fraction object; and C. Provide the following member operator functions, e. A function operator- to assign a Fraction object f. A function operatortto add a Fraction object; and g. A function operator-) to subtract a Fraction object; and h. A function operator to multiply a Fraction objcct; and i. A function operator to divide a Fraction object; and D. Provide the following stand-alone functions, j. A function init to set up or update the 2 required Fraction objects k. A function add to add 2 Fraction objects; and I. A function subtract) to subtract 2 Fraction objccts; and m. A function multiply) to multiply 2 Fraction objects; and n. A function divide () to divide 2 Fraction objects; and CIS25-C++ Programming: Homework #4-Page 2 of 10 1. Code Assignment/Exercise Exercise 1 A. Update the Fraction class given in the Lecture notes or as discussed in class meetings as follows, 1. Add your FIRST NAME and the initial of your last name to the name Fraction and use this as your updated class. For examples, if your first name is John Smith then updatc thc class namc to bc FractionJohns 2. Add and update all class constructors for your Fraction class to handle the initialization appropriately There must be as least 2 constructors of (i) Default; and i Copy Each constructor should print the confirmation (e.g., "Calling Fraction )", or "Calling Fraction (const Fraction&)) 3- Provide a destructor with a confirmation when removing the object (i.e., Calling Fraction )"). 4. Provide get/set member functions for each private member data 5. A member function print that will print the current Fraction object. B. Provide the following member functions, a. A function add) to add a Fraction objcct; and b. A function subtract) to subtract a Fraction object; and c. A function multiply) to multiply a Fraction objcct; and d. A function divide) to divide a Fraction object; and C. Provide the following member operator functions, e. A function operator- to assign a Fraction object f. A function operatortto add a Fraction object; and g. A function operator-) to subtract a Fraction object; and h. A function operator to multiply a Fraction objcct; and i. A function operator to divide a Fraction object; and D. Provide the following stand-alone functions, j. A function init to set up or update the 2 required Fraction objects k. A function add to add 2 Fraction objects; and I. A function subtract) to subtract 2 Fraction objccts; and m. A function multiply) to multiply 2 Fraction objects; and n. A function divide () to divide 2 Fraction objects; and
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started