代写C++ Lab作业、代写Fraction程序作业、代做留学生C++作业


Create a Fraction class which conforms to the following requirements. The class name should be Fraction with the declaration in Fraction.h and the definitions in Fraction.cpp. The following constructors, getters, setters, functions and operator overloading should be provided within your class. The class should pass all the tests provided in driver.cpp without modifying driver.cpp! YOU should update the functions appropriately in the resulting .h file (meaning I have intentionally left out things like friend, const, and passing by reference from functions and parameters, etc.)! There are comments to include a few (like getters) as inline functions. Likewise, there is a requirement that the ! operator call the invert function (this call can be done inline as well). Select operators can be defined in terms of its pair – and those definitions should be left as-is. Comments for functionality of some functions are provided. However, pre and post conditions are not always included below (but it may be wise to add those comments in to help with code clarity).

Note the location of multFracs – it is neither a member function, nor a friend function of the class (meaning you cannot directly access the member variables of the lhs and rhs parameters).

///////////CONSTRUCTORS///////////
//default constructor setting fraction to 0/1
//constructor setting fraction to num/1
//constructor setting fraction to num/den or num/1 if den is zero
//copy constructor where num = source.num, den = source.den

///////////FUNCTIONS//////////////
///////////MEMBER/////////////////
//Description: Fraction's numerator and denominator are set to the users' input
// (unless they enter a denominator of zero!)
void readin();

//Fraction is print to cout in (N/D) format (numerator / denominator)
void print();

//Post: A new fraction is returned where
// the new numerator is the calling object's denominator
// and the new denominator is the calling object's numerator
Fraction reciprocal();

//Post: Calling object's numerator and denominator are individually multiplied by m
void unreduce(int m);

//Post: fraction value is returned as a float
inline float toDecimal() //inline definition

///////////////// ACCESSOR FUNCTIONS //////////////////
int getNumer() //inlined definition
int getDenom() //inlined definition
static double getZeroTol();

///////////////// MUTATOR FUNCTIONS ////////////////////
void setNumer(int n);
//Description: TRUE is returned if update was successful.
bool setDenom(int d);
static void setZeroTol(double d);

///////////OPERATORS//////////////
///////////MEMBER/////////////////
Fraction & operator= (Fraction rhs);
Fraction & operator*= (Fraction rhs);
void operator! () //inline; call the invert function on the calling object
///////////NON MEMBER/////////////////
ostream & operator<< (ostream & out, Fraction source);
Fraction operator* (Fraction lhs, Fraction rhs);
bool operator== (Fraction lhs, Fraction rhs);
bool operator!= (const Fraction & lhs, const Fraction & rhs) {return !(lhs==rhs);}
bool operator> (Fraction lhs, Fraction rhs);
bool operator<= (const Fraction & lhs, const Fraction & rhs) {return !(lhs > rhs);}
bool operator< (Fraction lhs, Fraction rhs);
bool operator>= (const Fraction & lhs, const Fraction & rhs) {return !(lhs < rhs);}

///////////FRIEND/////////////////
//Pre: Numerator cannot be zero
//Post: The fraction values are swapped - where
// the new numerator is the original denominator
// and the new denominator is the original numerator
friend void invert(Fraction & f);

private:
int m_Numerator; //fraction's numerator
int m_Denominator; //fraction's denominator
static double zero_tolerance; //initial value should be set to 0.0001
};// END of class declaration

//Pre: lhs and rhs are valid fractions (neither den = 0)
//Post: returned fraction's numerator is the lhs numerator * rhs numerator
// returned fraction's denominator is the lhs denominator * rhs denominator
Fraction multFracs(const Fraction & lhs, const Fraction & rhs);
http://www.6daixie.com/contents/13/1469.html

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/javastudying/p/9146899.html