Professional Documents
Culture Documents
BTH Cmu CS 316 Ris
BTH Cmu CS 316 Ris
//toan tu mo rong
Fraction operator+=(int x); p += 4; p.output(); // p = 9/2
Fraction operator+=(Fraction f2); p += f; p.output(); // p = 21/4
Fraction operator-=(int x);
Fraction operator-=(Fraction f2);
Fraction operator*=(int x);
Fraction operator*=(Fraction f2);
Fraction operator/=(int x);
Fraction operator/=(Fraction f2);
//so sanh
bool operator==(Fraction f2); System.out.println( p == f); //false
bool operator!=(Fraction f2);
bool operator<(Fraction f2);
bool operator<=(Fraction f2);
bool operator>(Fraction f2);
bool operator>=(Fraction f2);
Bài 2: Mở file Set.h ra cài đặt bổ sung các hàm chồng toán tử
Cài đặt các hàm chồng toán tử trong lớp Fraction Ví dụ minh hoạ
bool operator==(Set &s); //bang Tự gọi các chồng toán tử ở hàm main
bool operator!=(Set &s); //khong bang
Set operator *(Set &s); //giao cua 2 Set
Set operator-(Set &); // tru cua 2 Set
Set operator+ (Set &); //hop cua 2 Set
//chong toan tu get(index)
int operator[](int index){return a[index];}