Bài 1: # include < conio.h > # include < stdio.h > # include < iostream.h > # include < math.h > # difine M_PI 3,14 class Point{ private: int x,y; int Mau; public: Point( ){ x = 0; y = 0; Mau = 0; } Point( int x1, int y1, int Mau1 ){ x = x1; y = y1; Mau = Mau1; } void Nhap( ){ cout << “Nhap toa do x, y : ” ; cin >> x >> y ; cout << “Nhap so mau : ” ; cin >> Mau ; } void Xuat( ){ cout << “Toa do diem : ( ” << x << “ ,” << y << “ )” ; cout << “Mau : ” << Mau ; } int GetX( ) { return x ;} int GetY( ) { return y ;} int GetMau( ) { return Mau ;} }; class Circle{ private: int x, y ; int r ; public: Circle( ){ x = 0; y = 0; r = 0; } 1 Circle( int x1, int y1, int r1 ){ x = x1; y = y1; r = r1; } void Nhap( ){ cout << “Nhap toa do tam : ” ; cin >> x >> y ; cout << “Nhap ban kinh : ” ; cin > r ; } void Xuat( ){ cout << “Toa do tam : ( ” << x << “ ,” << y << “ )” ; cout << “\ n Ban kinh : ” < r ; } int GetX( ) { return x ;} int GetY( ) { return y ;} int GetR( ) { return r ;} fload Dientich(){ return M_PI * r * r ;} fload Chuvi(){ return 2 * M_PI * r ;} }; void main ( ){ Circle c ; clrscr ( ) ; c.Nhap() ; c.Xuat() ; cout << “ \n Dien tich duong tron : ” << c.Dientich(); cout << “ \n Chu vi duong tron : ” << c.Chuvi(); getch(); } Bai 2: # . class Thisinh{ private: char Ht[ 30] ; int Ngay, Thang, Nam ; fload Td ; public: Thisinh( ){ strcpy ( Ht, “ ”) ; Ngay = 0; Thang = 0; Nam = 0; Td = 0; 2 } Thisinh( char * ht1, int Ngay1, int Thang1, int Nam1, int td1 ){ strcpy ( Ht, ht1) ; Ngay = Ngay1; Thang = Thang1; Nam = Nam1; Td = td1; } char *GetHt( ) { return Ht ;} int GetNgay( ) { return Ngay ;} int GetThang( ) { return Thang ;} int GetNam( ) { return Nam ;} void Nhap( ){ cout << “Nhap Ho ten : ” ; cin.ignore( 1); cin.get( Ht, 30); cout << “Nhap Ngay, thang, nam sinh : ” ; cin >> Ngay >> Thang >> Nam ; cout << “Nhap Tong diem : ” ; cin >> Td ; } void Xuat( ){ cout << “ \n Ho ten : ” << Ht; cout << “\n Nam sinh : ” << Ngay << “ / ” << Thang << “ / ” << Nam; cout << “ \n Tong diem : ” << Td ; } }; void main(){ Thisinh a[ 100] ; int i, n ; clrscr ( ) ; cout << “ \n Nhap so thi sinh : ” ; cin >> n; cout << “ \n Nhap danh sach thi sinh : ” ; for ( i = 0, i < n, i ++){ cout << “ \n Nhap thi sinh thu : ” << i << “\n” ; a[ i].Nhap(); a[ i].Xuat(); } getch(); } Bai 3: // Xay dung lop Date class Date{ private: 3 int Ngay, Thang, Nam ; public: Date( ){ Ngay = 0; Thang = 0; Nam = 0; } Date( int Ngay1, int Thang1, int Nam1){ Ngay = Ngay1; Thang = Thang1; Nam = Nam1; } int GetNgay( ) { return Ngay ;} int GetThang( ) { return Thang ;} int GetNam( ) { return Nam ;} void Nhap( ){ cout << “Nhap Ngay, thang, nam sinh : ” ; cin >> Ngay >> Thang >> Nam ; } void Xuat( ){ cout << “\n Nam sinh : ” << Ngay << “ / ” << Thang << “ / ” << Nam; } }; // Ham so sanh giua 2 ngay xem ngay nao lon hon //Xay dung lop nhan vien su dung lop Date lam lop thanh phan class Nhanvien : private Date{ private: char Ht[ 30] ; Date ngaysinh ; char Gioi[ 4] ; fload Hsl ; // he so luong public: Nhanvien( ){ strcpy ( Ht, “ ”) ; strcpy ( Gioi, “ Nam”) ; Hsl = 0; } Nhanvien( char * ht1, char * gioi1, float hsl1 ){ strcpy ( Ht, ht1) ; strcpy ( Gioi, gioi1) ; Td = td1; } fload GetHsl( ) { return Hsl ;} void Nhap( ){ 4 cout << “Nhap Ho ten : ” ; cin.ignore( 1); cin.get( Ht, 30); cout << “Nhap Ngay, thang, nam sinh : ” ; cin >> Ngay >> Thang >> Nam ; cout << “Nhap Gioi tinh : ” ; cin.ignore( 1); cin.get( Gioi, 4); cout << “Nhap He so luong : ” ; cin >> Hsl ; } void Xuat( ){ cout << “ \n Ho ten : ” << Ht; cout << “\n Nam sinh : ” << Ngay << “ / ” << Thang << “ / ” << Nam; cout << “ \n Gioi tinh : ” << Gioi; cout << “ \n He so luong : ” << Hsl ; } }; void main(){ Nhanvien a[ 100] ; int i, n ; clrscr ( ) ; cout << “ \n Nhap so nhan vien : ” ; cin >> n; cout << “ \n Nhap danh sach nhan vien : ” ; for ( i = 0, i < n, i ++){ cout << “ \n Nhap nhan vien thu : ” << i << “\n” ; a[ i].Nhap(); a[ i].Xuat(); } getch(); } Bai 4: class Dathuc{ private: int n ; // bac da thuc fload a[ 100] ; // he so da thuc public: Dathuc( ); Dathuc( fload a1, int n1 ); Dathuc operator - ( ) ; Dathuc operator + ( Dathuc d ) ; Dathuc operator - ( Dathuc d ) ; friend istream &operator >> ( istream & is, Dathuc &d ) ; 5 friend istream &operator >> ( istream & is, Dathuc &d ) ; }; Dathuc :: Dathuc( ){ n = -1; } Dathuc :: Dathuc( fload a1, int n1 ){ n =n1; for (int i = 0; i < n; i++) a[ i] = a1[ i] ; } Dathuc Dathuc :: operator - ( ) { Dathuc d1; d1.n = n ; for (int i = 0; i < n; i++) d1.a[ i] = - a[ i] ; return d1; } Dathuc Dathuc :: operator - ( Dathuc d ) { Dathuc d1; int max, min, i ; if( n < d.n ){ min = n ; max = d.n ; } else{ min = d.n ; max = n ; } d1.n = max ; for (int i = 0; i < min ; i++ ) d1.a[ i] = a[ i] + d.a[ i]; if( n > d.n ){ for ( i = min + 1; i <= max; i++) d1.a[ i] = a[ i] ; else for ( i = min + 1; i <= max; i++) d1.a[ i] = d.a[ i] ; } if( n = d.n ) while( d1.[d1.n] ==0 && d1.n >= 0) d1.n --; return d1; } istream &operator >> ( istream & is, Dathuc &d ){ cout << “ Nhap bac da thuc : ” ; is >> d.n ; 6 cout << “ Nhap cac he so : ” ; for (int i = 0; i < d.n; i++){ cout << “ a[” << i << “ ] =” ; is >> d.a[i] ; } return is; } ostream &operator >> (ostream & os, Dathuc &d ){ os << “ Nhap bac da thuc : ” << d.n ; os << “ Nhap cac he so : ” ; for (int i = 0; i < d.n; i++) os << d.a[i] << “ ” ; return os; } void main(){ Dathuc d1, d2; cout << “ Nhap da thuc d1: ” ; cin >> d1; cout << “ Nhap da thuc d2: ” ; cin >> d2; cout << “ \n” << d1<< “ +” << d2 << “ =” d1+ d2 ; cout << “ \n” << d1<< “ -” << d2 << “ =” d1- d2 ; getch() ; } Bai 5: class PS{ private: int T, M ; public: PS( ){ T = 0 ; M= 0 ; } PS( int a, int b){ T = a; M= b; } void ToiGian() ; PS operator +( ) ; PS operator - ( ) ; PS operator + ( PS b ) ; PS operator - ( PS b ) ; PS operator * ( PS b ) ; PS operator / ( PS b ) ; 7 friend istream &operator >> ( istream & is, PS &p ) ; friend ostream &operator << ( ostream & os, PS &p ) ; }; int USCLN( int x, int y){ if ( x == 0 && y == 0) return 1; else if ( x == 0) return y; else if ( y == 0) return x; else { do{ if ( x >= y) x %=y; else{ x += y; y = x- y; x - =y } } } } void PS :: ToiGian(){ if( T == 0) M = 1; else{ if ( M < 0){ T = - T; M = - M; } int u = USCLN( abs( T), M) ; T= T/ u; M= M/ u; } } PS PS :: operator +( ) { return PS( T, M) ; } PS PS :: operator -( ) { return PS( -T, M) ; } PS PS :: operator +( PS b ) { return PS( T*b.M + b.T *M, M * b.M) ; } PS PS :: operator - ( PS b ) { return PS( T*b.M - b.T *M, M * b.M) ; } PS PS :: operator * ( PS b ) { 8 return PS( T*b.T, M * b.M) ; } PS PS :: operator / ( PS b ) { return PS( T*b.M, M * b.T) ; } istream &operator >> ( istream & is, PS &p ){ cout << “ T =” ; is >> a.T ; do { cout << “ M =” ; is >> a.M ; } while ( ! a.M) ; a.Toigian() ; return is ; } ostream &operator >> ( ostream & os, PS &p ){ os << a.T ; if ( a.T && a.M != 1) os << “ / ” << a.M ; return os ; } int main(){ clrscr() ; PS x(T1, M1), y(T2, M2) ; cout << “ x =” << x; cout << “ y =” << y; cout << “x + y =” << x +y; cout << “x - y =” << x - y; cout << “x * y =” << x * y; if( y!=0) cout << “x / y =” << x / y; getch(); } Bai 6: Class Nguoi{ private: char Ht[ 30] ; int Ngay, Thang, Nam ; char Gioi[ 4] ; public: Nguoi( ){ strcpy ( Ht, “ ”) ; Ngay = 0; Thang = 0; 9 Nam = 0; strcpy ( Gioi, “ Nam”) ; } Nhanvien( char * ht1, int Ngay1, int Thang1, int Nam1, char * gioi1){ strcpy ( Ht, ht1) ; Ngay = Ngay1; Thang = Thang1; Nam = Nam1; strcpy ( Gioi, gioi1) ; } void Nhap( ){ cout << “Nhap Ho ten : ” ; cin.ignore( 1); cin.get( Ht, 30); cout << “Nhap nam sinh : ” ; cin >> Ngay >> Thang >> Nam ; cout << “Nhap Gioi tinh : ” ; cin.ignore( 1); cin.get( Gioi, 4); } void Xuat( ){ cout << “ \n Ho ten : ” << Ht; cout << “\n Nam sinh : ” << Ngay << “ / ” << Thang << “ / ” << Nam; cout << “ \n Gioi tinh : ” << Gioi ; } }; Class Giaovien : public Nguoi{ private: char Bomon[ 20] ; char Monday[ 20] ; public: Giaovien( ){ strcpy ( Bomon, “ ”) ; strcpy ( Monday, “ ”) ; } Giaovien( char * B, char * M){ strcpy ( Bomon, B) ; strcpy ( Monday, M) ; } void Nhap( ){ cout << “Nhap Bo mon : ” ; cin.ignore( 1); cin.get( Bomon, 20); cout << “Nhap Mon day : ” ; cin.ignore( 1); 10 . Bài 1: # include < conio.h > # include < stdio.h > # include <