Question
Calling Fraction() C++ ATTACHED ARE THE ASSIGNMENT AND OUTPUT SAMPLES. THANKS IN ADVANCE Please update and make changes on the source coding as needed. However,
Calling Fraction() C++
ATTACHED ARE THE ASSIGNMENT AND OUTPUT SAMPLES. THANKS IN ADVANCE
Please update and make changes on the source coding as needed. However, some functions and member functions are required.
NOTE: int main() should only call:
displayClassInfoYourName(); // already got it
menuHw1Ex4(); // which means, menu#4 should contain all the menus and display all the outputs
NOTE: void build2Fraction(Fraction** , Fraction** ); // To build the fractions should be either Fraction** or Fraction*&
NOTE: the print member function displays the current Fraction object
the stand alone print function prints the required Fraction objects:
THE CURRENT CODING IS:
class Fraction {
public:
Fraction(); // Default constructor
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&, const Fraction&);
Fraction subtract(const Fraction&, const Fraction&);
Fraction multiply(const Fraction&, const Fraction&);
Fraction divide(const Fraction&, 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;
};
void displayClassInfoYourName(void); void menuHw1Ex4(void); void print(void); // print required Fraction objects void build2Fraction(Fraction** , Fraction** ); //NOTE IT SHOULD BE EITHER Fraction** or Fraction*&
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&);
int main() {
displayClassInfoYourName();
menuHw1Ex4();
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
void menuHw1Ex4() { int option; Fraction* leftOp = nullptr; // left Fraction Fraction* rightOp = nullptr; // right Fraction Fraction* resultOp = nullptr; // result Fraction
// Menu Display do { cout
// Ask an option from the menu to cin >> option
cin >> option;
// If option is 1, 2, 3, 4, 5, 6, or 7 follow the cases switch (option) { // If option is 1, Initialize with subMenu 1 case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; default: break; } } while (option != 7); }
void print() { // print required Fraction objects }
void build2Fraction(Fraction** leftPtr, Fraction** rightOp) { //NOTE: IT SHOULD BE EITHER Fraction** or Fraction*& }
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
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