Created
July 26, 2018 08:38
-
-
Save bossxomlut/5df5914551a4c51a307b0e5fdc66c217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<conio.h> | |
| #include<iostream> | |
| #include<string.h> | |
| using namespace std; | |
| #pragma warning(disable: 4996) | |
| #define HIHI "UNAVAILABLE" | |
| class ngaysinh | |
| { | |
| private: | |
| int ngay, thang, nam; | |
| public: | |
| ngaysinh() | |
| { | |
| ngay = thang = nam = 0; | |
| } | |
| ngaysinh(int ngay1, int thang1, int nam1) | |
| { | |
| this->ngay = ngay1; | |
| this->thang = thang1; | |
| this->nam = nam1; | |
| } | |
| ngaysinh & operator =(ngaysinh &h) | |
| { | |
| this->ngay = h.ngay; | |
| this->thang = h.thang; | |
| this->nam = h.nam; | |
| return h; | |
| } | |
| friend istream& operator >>(istream& input_, ngaysinh &h) | |
| { | |
| cout << "NHAP NGAY:"; input_ >> h.ngay; | |
| cout << "NHAP THANG:"; input_ >> h.thang; | |
| cout << "NHAP NAM:"; input_ >> h.nam; | |
| return input_; | |
| } | |
| friend ostream& operator <<(ostream &output_, ngaysinh &h) | |
| { | |
| output_ << h.ngay << "/" << h.thang << "/" << h.nam; | |
| return output_; | |
| } | |
| }; | |
| class ngayMT | |
| { | |
| private: | |
| ngaysinh ngaymuon , ngaytra ; | |
| public: | |
| ngayMT() | |
| { | |
| this->ngaymuon = ngaysinh(); | |
| this->ngaytra = ngaysinh(); | |
| } | |
| ngayMT(int ngay1, int thang1, int nam1, int ngay2, int thang2, int nam2) | |
| { | |
| this->ngaymuon = ngaysinh(ngay1,thang1,nam1); | |
| this->ngaytra = ngaysinh(ngay2, thang2, nam2); // code tới đây mình đã hiểu ra là cái dẫn xuất dẫn được tới các thành phần | |
| } | |
| friend istream& operator >>(istream& input_, ngayMT &h) | |
| { | |
| int ngay1, ngay2, thang1, thang2, nam1, nam2; | |
| cout << "NHAP NGAY MUON:"; cin >> ngay1; | |
| cout << "NHAP THANG MUON:"; cin >> thang1; | |
| cout << "NHAP NAM MUON:"; cin >> nam1; | |
| cout << "NHAP NGAY TRA:"; cin >> ngay2; | |
| cout << "NHAP THANG TRA:"; cin >> thang2; | |
| cout << "NHAP NAM TRA:"; cin >> nam2; | |
| h = ngayMT(ngay1, thang1, nam1, ngay2, thang2, nam2); | |
| return input_; | |
| } | |
| friend ostream& operator <<(ostream &output_, ngayMT &h) | |
| { | |
| cout << "THOI GIAN MUON: " << h.ngaymuon; | |
| cout <<"\nTHOI GIAN TRA: " << h.ngaytra; | |
| return output_; | |
| } | |
| }; | |
| class nguoi | |
| { | |
| private: | |
| char *ht; | |
| ngaysinh ns; | |
| public: | |
| nguoi() | |
| { | |
| ht = strdup(HIHI); | |
| this->ns = ngaysinh(); | |
| } | |
| nguoi(char ht1[], short ngay1, short thang1, short nam1) | |
| { | |
| int n = strlen(ht1); | |
| this->ht = new char[n + 1]; | |
| strupr(ht1); | |
| strcpy(this->ht, ht1); | |
| this->ns = ngaysinh(ngay1, thang1, nam1); | |
| } | |
| ~nguoi() | |
| { | |
| this->ns = ngaysinh(); | |
| if (this->ht != NULL) | |
| { | |
| delete this->ht; | |
| this->ht = NULL; | |
| } | |
| } | |
| friend istream& operator >>(istream& input_, nguoi &h) | |
| { | |
| cout << "NHAP HO VA TEN:"; | |
| if (h.ht != NULL) delete h.ht; | |
| char ch[20]; | |
| fflush(stdin); | |
| gets(ch); | |
| strupr(ch); | |
| h.ht = strdup(ch); | |
| input_ >> h.ns; | |
| return input_; | |
| } | |
| friend ostream& operator <<(ostream &output_, nguoi &h) | |
| { | |
| cout << "NAME:"; output_ << h.ht; | |
| cout << "\nDATE OF BIRTH: "; | |
| output_ << h.ns; | |
| return output_; | |
| } | |
| }; | |
| class sach | |
| { | |
| private: | |
| char *tensach; | |
| char *tentg; | |
| int namsanxuat; | |
| public: | |
| sach() | |
| { | |
| this->tensach = strdup(HIHI); | |
| this->tentg = strdup(HIHI); | |
| this->namsanxuat = 0; | |
| } | |
| ~sach() | |
| { | |
| if (this->tensach != NULL) | |
| { | |
| delete this->tensach; | |
| this->tensach = NULL; | |
| } | |
| if (this->tentg != NULL) | |
| { | |
| delete this->tentg; | |
| this->tentg = NULL; | |
| } | |
| this->namsanxuat = 0; | |
| } | |
| sach(char tensach1[], char tentg1[], int namsanxuat1) | |
| { | |
| this->namsanxuat = namsanxuat1; | |
| strupr(tensach1); | |
| strupr(tentg1); | |
| this->tensach = strdup(tensach1); | |
| this->tentg = strdup(tentg1); | |
| } | |
| friend istream& operator >> (istream& input_, sach& h) | |
| { | |
| cout << "NHAP TEN SACH: "; | |
| if (h.tensach != NULL) delete h.tensach; | |
| char ch[20]; | |
| fflush(stdin); | |
| gets(ch); | |
| strupr(ch); | |
| h.tensach = strdup(ch); | |
| cout << "NHAP TAC GIA: "; | |
| if (h.tentg != NULL) delete h.tentg; | |
| fflush(stdin); | |
| gets(ch); | |
| strupr(ch); | |
| h.tentg = strdup(ch); | |
| cout << "NHAP NAM XUAT BAN:"; | |
| input_ >> h.namsanxuat; | |
| return input_; | |
| } | |
| friend ostream& operator << (ostream& output_, sach& h) | |
| { | |
| output_ << "TEN SACH: " << h.tensach << "\nTEN TAC GIA: " << h.tentg << "\nNAM SAN XUAT: " << h.namsanxuat; | |
| return output_; | |
| } | |
| }; | |
| class maso | |
| { | |
| private: | |
| int ms; | |
| public: | |
| maso() | |
| { | |
| this->ms = 0; | |
| } | |
| maso(int ms1) | |
| { | |
| this->ms = ms1; | |
| } | |
| friend istream& operator >> (istream& input_, maso& h) | |
| { | |
| cout << "NHAP MA SO:"; input_ >> h.ms; | |
| return input_; | |
| } | |
| friend ostream& operator << (ostream& output_, maso& h) | |
| { | |
| cout << "MA SO:"; output_ << h.ms; | |
| return output_; | |
| } | |
| }; | |
| void main() | |
| { | |
| maso ms(171916); | |
| cout << ms<<"\n"; | |
| char ht[] = "ngo tan vinh"; | |
| nguoi a(ht,15,12,1999); | |
| cout << a; | |
| char ts[] = "bien may troi"; | |
| sach sc(ts,ht,2020); | |
| cout <<"\n"<< sc; | |
| ngayMT ngan; | |
| cin >> ngan; | |
| cout << ngan; | |
| a.~nguoi(); | |
| sc.~sach(); | |
| _getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment