#include<bits/stdc++.h>
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>> y.Tensp ;
cout << "Nhap mau sac: " ; x>> y.Mausac ;
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 ;
}
I2luY2x1ZGU8Yml0cy9zd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