fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class tl{
  4. char ten[30];
  5. char mau[30];
  6. float gia;
  7. public:
  8. tl(){
  9. strcpy(ten," ");
  10. strcpy(mau," ");
  11. gia=0;
  12. }
  13. tl(const char tensp[30],const char mausac[30],float giatien){
  14. strcpy(ten,tensp);
  15. strcpy(mau,mausac);
  16. gia=giatien;
  17. }
  18. bool operator*(tl y){
  19. return (gia>250&&strcmp(mau,"trang")==0);
  20. }
  21. friend istream&operator>>(istream&x,tl&y);
  22. friend ostream&operator<<(ostream&x,tl y);
  23. bool operator==(tl y);
  24. };
  25. istream&operator>>(istream&x,tl&y){
  26. cout<<"ten :";x>>y.ten;
  27. cout<<"mau sac:"; x>>y.mau;
  28. cout<<"gia: "; x>>y.gia;
  29. return x;
  30. }
  31. ostream&operator<<(ostream&x,tl y){
  32. cout<<"ten :"<<y.ten<<endl;
  33. cout<<"mau sac:"<<y.mau<<endl;
  34. cout<<"gia: "<<y.gia<<endl;
  35. return x;
  36. }
  37. bool tl::operator==(tl y){
  38. return(strcmp(ten,y.ten)==0&&strcmp(mau,y.mau)==0&&gia==y.gia);
  39. }
  40. int main(){
  41. tl a("LG","trang",2000);
  42. tl b;
  43. cout<<"thong tin tu lanh a: "<<endl;
  44. cout<<a<<endl;
  45. cout<<"nhap thong tin tu lanh b"<<endl;
  46. cin>>b;
  47. ofstream f("tl.txt");
  48. if(a*a){
  49. cout<<"tu lanh a co gia >250 & mau trang!"<<endl;
  50. f<<"tu lanh a co gia >250 & mau trang!"<<endl;
  51. }
  52. else{
  53. cout<<"tu lanh a ko co gia >250 & mau trang!"<<endl;
  54. f<<"tu lanh a ko co gia >250 & mau trang!"<<endl;
  55. }
  56. if(b*b){
  57. cout<<"tu lanh b co gia >250 & mau trang!"<<endl;
  58. f<<"tu lanh b co gia >250 & mau trang!"<<endl;
  59. }
  60. else{
  61. cout<<"tu lanh b ko co gia >250 & mau trang!"<<endl;
  62. f<<"tu lanh b ko co gia >250 & mau trang!"<<endl;
  63. }
  64. if(a==b){
  65. cout<<"2 tu lanh co thong tin giong nhau!"<<endl;
  66. f<<"2 tu lanh co thong tin giong nhau!"<<endl;
  67. }
  68. else{
  69. cout<<"2 tu lanh ko co thong tin giong nhau!"<<endl;
  70. f<<"2 tu lanh ko co thong tin giong nhau!"<<endl;
  71. }
  72. f.close();
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
thong tin tu lanh a: 
ten :LG
mau sac:trang
gia: 2000

nhap thong tin tu lanh b
ten :mau sac:gia: tu lanh a co gia >250 & mau trang!
tu lanh b ko co gia >250 & mau trang!
2 tu lanh ko co thong tin giong nhau!