Xây dựng class phân số c++

PhanSo.hpp



#ifndef PhanSo_hpp
#define PhanSo_hpp

class PhanSo{
private:
    int tu;
    int mau;
public:
    void set(int,int);
    void nhap();
    void xuat() const;
    PhanSo cong(const PhanSo&) const;
    PhanSo tru(const PhanSo&) const;
    PhanSo nhan(const PhanSo&) const;
    PhanSo chia(const PhanSo&) const;
};

#endif /* PhanSo_hpp */

PhanSo.cpp


#include "PhanSo.hpp"
#include < iostream >
using namespace std;
void PhanSo::set(int t, int m){
    tu = t;
    mau = m;
}
void PhanSo::nhap(){
    cout << "Nhap tu so:";
    cin >> tu;
    cout << "Nhap mau so:";
    cin >> mau;
}
void PhanSo::xuat()const{
    cout << tu << "/" << mau;
}
PhanSo PhanSo::cong(const PhanSo &ps2) const {
    PhanSo kq;
    kq.tu = tu * ps2.mau + mau*ps2.tu;
    kq.mau = mau * ps2.mau;
    return kq;
}
PhanSo PhanSo::tru(const PhanSo &ps2) const {
    PhanSo kq;
    kq.tu = tu * ps2.mau - mau*ps2.tu;
    kq.mau = mau * ps2.mau;
    return kq;
}
PhanSo PhanSo::nhan(const PhanSo &ps2) const {
    PhanSo kq;
    kq.tu = tu *ps2.tu;
    kq.mau = mau * ps2.mau;
    return kq;
}
PhanSo PhanSo::chia(const PhanSo &ps2) const {
    PhanSo kq;
    kq.tu = tu * ps2.mau;
    kq.mau = mau * ps2.tu;
    return kq;
}