1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
#include <iostream> #include <cmath> using namespace std; class frac { private: int n,d; public: void set_n(int n){n=n;} void set_d(int d) { if(d!=0){d=d;} } int get_nu()const{return n;} int get_de()const{return d;} frac &operator=(const frac &a) { int num=a.get_nu(); this->set_n(num); int den=a.get_de(); this->set_d(den); return *this; } frac():n(1),d(1){} frac(int n,int d):n(n),d(d){} }; ostream &operator<<(ostream &out,const frac &a) { out<<a.get_nu(); out<<"/"; out<<a.get_de(); return out; } int main() { frac q; q = frac(3, 2); cout << "q = " << q <<endl; return 0;