I. An initial class Rational for fractions like, e.g. 4/5, is defined as follows. the following questions should modify

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

I. An initial class Rational for fractions like, e.g. 4/5, is defined as follows. the following questions should modify

Post by answerhappygod »

I An Initial Class Rational For Fractions Like E G 4 5 Is Defined As Follows The Following Questions Should Modify 1
I An Initial Class Rational For Fractions Like E G 4 5 Is Defined As Follows The Following Questions Should Modify 1 (198.95 KiB) Viewed 30 times
I. An initial class Rational for fractions like, e.g. 4/5, is defined as follows. the following questions should modify this definition as required. class Rational II (a, d: 20%, others 10 % each) { public: Rational( int , int ); // default constructor Rational addition( const Rational & ); // function addition Rational subtraction( const Rational & ); // function subtraction void printRational (); // print rational format void setRationalNumber(int, int); // set rational number private: int numerator; // integer numerator int denominator; // integer denominator }; // end class Rational a) Implement the constructor that takes two integers as arguments, e.g. 5, 12, to initialize the data members by using member-initializer syntax. Remember to prevents a 0 denominator in a fraction. Make this constructor a default constructor too by assigning the two data members both to values 1. The constructor also prints out a message like: Rational number 5/12 is constructed. b) Define a destructor that prints a message like: Rational number 5/12 is destroyed. c) Define and implement a copy constructor that creates a rational number object by using the values of another rational number object. d) Implement the other four public functions as the names suggest, i.e. add a rational object to this object, subtract a rational object from this object, print out a rational object as 5/12, and set the two data members of a rational object by two integer arguments.
e) Overload the addition operator (+) as a member function to add another rational number to this rational number object. Make this overloaded function able to perform cascaded operations like: Ra+Rb+Rc. f) Overload the stream insertion operator << and stream extraction operator >> as global functions to print out a rational number as cout << rationalObject directly and to input a rational number directly as cin >> rationalObject. g) Overload the == and the != operators to allow comparisons of two rational numbers. (please use definition of == to define !=) h) Overload the ++ the -- operators for pre- and post-increment and decrement operations that adds 1 to and minus 1 from a Rational number object.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply