#include <iostream>
#include <fstream>
#include <cstring> // Thêm thư viện để làm việc với chuỗi
using namespace std;
class TL {
char Tensp[ 30 ] ;
char Mausac[ 20 ] ;
float Gia;
public :
// Constructor mặc định
TL( ) {
strcpy ( Tensp, "" ) ;
strcpy ( Mausac, "" ) ;
Gia = 0.0 ;
}
// Constructor có tham số
TL( const char ten[ 30 ] , const char mau[ 20 ] , float gia) {
strcpy ( Tensp, ten) ;
strcpy ( Mausac, mau) ;
Gia = gia;
}
// Phương thức toán tử >=
bool operator>= ( TL y) {
return ( Gia > 250 && strcmp ( Mausac, "trang" ) == 0 ) ;
}
// Toán tử xuất <<
friend ostream& operator<< ( ostream& x, const TL& y) {
x << "Ten san pham: " << y.Tensp << endl;
x << "Mau sac: " << y.Mausac << endl;
x << "Gia: " << y.Gia << endl;
return x;
}
// Toán tử nhập >>
friend istream& operator>> ( istream& x, TL& y) {
cout << "Nhap ten san pham: " ;
x.ignore ( ) ; // Loại bỏ ký tự xuống dòng còn trong bộ đệm
x.getline ( y.Tensp , 30 ) ;
cout << "Nhap mau sac: " ;
x.getline ( y.Mausac , 20 ) ;
cout << "Nhap gia: " ;
x >> y.Gia ;
return x;
}
// Toán tử ==
bool operator== ( TL y) {
return ( strcmp ( Tensp, y.Tensp ) == 0 && strcmp ( Mausac, y.Mausac ) == 0 && Gia == y.Gia ) ;
}
} ;
int main( ) {
TL A( "LG" , "trang" , 5000 ) ;
cout << "Thong tin tu lanh A:" << endl;
cout << A << endl;
TL B;
cout << "Nhap thong tin tu lanh B: " << endl;
cin >> B;
ofstream f( "Tl.txt" ) ;
if ( A == B) {
cout << "2 tu lanh co cung thong tin!" << endl;
f << "2 tu lanh co cung thong tin!" << endl;
} else {
cout << "2 tu lanh khong co cung thong tin!" << endl;
f << "2 tu lanh khong co cung thong tin!" << endl;
}
if ( A >= A || B >= B) {
cout << "Co tu lanh co gia > 250 va mau trang!" << endl;
f << "Co tu lanh co gia > 250 va mau trang!" << endl;
} else {
cout << "Khong co tu lanh nao thoa man dieu kien!" << endl;
f << "Khong co tu lanh nao thoa man dieu kien!" << endl;
}
f.close ( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGNzdHJpbmc+IC8vIFRow6ptIHRoxrAgdmnhu4duIMSR4buDIGzDoG0gdmnhu4djIHbhu5tpIGNodeG7l2kKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIFRMIHsKICAgIGNoYXIgVGVuc3BbMzBdOwogICAgY2hhciBNYXVzYWNbMjBdOwogICAgZmxvYXQgR2lhOwoKcHVibGljOgogICAgLy8gQ29uc3RydWN0b3IgbeG6t2MgxJHhu4tuaAogICAgVEwoKSB7CiAgICAgICAgc3RyY3B5KFRlbnNwLCAiIik7CiAgICAgICAgc3RyY3B5KE1hdXNhYywgIiIpOwogICAgICAgIEdpYSA9IDAuMDsKICAgIH0KCiAgICAvLyBDb25zdHJ1Y3RvciBjw7MgdGhhbSBz4buRCiAgICBUTChjb25zdCBjaGFyIHRlblszMF0sIGNvbnN0IGNoYXIgbWF1WzIwXSwgZmxvYXQgZ2lhKSB7CiAgICAgICAgc3RyY3B5KFRlbnNwLCB0ZW4pOwogICAgICAgIHN0cmNweShNYXVzYWMsIG1hdSk7CiAgICAgICAgR2lhID0gZ2lhOwogICAgfQoKICAgIC8vIFBoxrDGoW5nIHRo4bupYyB0b8OhbiB04butID49CiAgICBib29sIG9wZXJhdG9yPj0oVEwgeSkgewogICAgICAgIHJldHVybiAoR2lhID4gMjUwICYmIHN0cmNtcChNYXVzYWMsICJ0cmFuZyIpID09IDApOwogICAgfQoKICAgIC8vIFRvw6FuIHThu60geHXhuqV0IDw8CiAgICBmcmllbmQgb3N0cmVhbSYgb3BlcmF0b3I8PChvc3RyZWFtJiB4LCBjb25zdCBUTCYgeSkgewogICAgICAgIHggPDwgIlRlbiBzYW4gcGhhbTogIiA8PCB5LlRlbnNwIDw8IGVuZGw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