STUDENT CLASS class SINHVIEN { #include “iostream” char MASV[30]; #include “stdio.h” char HOTEN[50]; #include “conio.h” int TUOI; #include “iomanip” float DIEM; public: void NHAP(); void XUAT(); }; void SINHVIEN::NHAP() { cout<<"Ma SV: "; fflush(stdin); gets(MASV); cout<<"Ho Ten: "; fflush(stdin); gets(HOTEN); cout<<"Tuoi: "; cin>>TUOI; cout<<"Diem: "; cin>>DIEM; } void SINHVIEN::XUAT() { cout<<"Ma SV: "<<MASV<<endl; cout<<"Ho ten: "<<HOTEN<<endl; cout<<"Tuoi: "<<TUOI<<endl; cout<<"Diem: "<<DIEM<<endl<<endl; } int main() { SINHVIEN a, b; cout<<"Nhap thong tin cua sinh vien a:"<<endl; a.NHAP(); cout<<"Nhap thong tin cua sinh vien b:"<<endl; b.NHAP(); cout<<endl<<"Sinh vien a"<<endl; a.XUAT(); cout<<"Sinh vien b"<<endl; b.XUAT(); return 0; } BÀI 1. RECTANGLE CLASS class HCN { float D, R; public: void NHAP(); void VE(); float DIENTICH(); float CHUVI(); }; void HCN::NHAP() { cout<<"Chieu dai : "; cin>>D; cout<<"Chieu rong: "; cin>>R; } void HCN::VE() { for(int i=0; i<D; i++) { for(int j=0; j<R; j++) cout<<"*"; cout<<endl; } } float HCN::DIENTICH() { return D*R; } float HCN::CHUVI() { return 2*(D+R); } int main() { HCN x; x.VE(); cout<<"Dien tich HCN: "<<x.DIENTICH()<<endl; cout<<"Chu vi HCN : "<<x.CHUVI(); return 0; } BÀI 1. OBJECT ARRAY class HANG { char MAHANG[10]; char TENHANG[20]; float DONGIA; int SOLUONG; public: void NHAP(); void XUAT(); }; void HANG::NHAP() { cout<<"Ma hang : "; fflush(stdin); gets(MAHANG); cout<<"Ten hang : "; fflush(stdin); gets(TENHANG); cout<<"Don gia : "; cin>>DONGIA; cout<<"So luong : "; cin>>SOLUONG; } void HANG::XUAT() { cout<<setw(10)<<MAHANG<<setw(20)<<TENHANG<<setw(10)<<DONGIA<<set w(10)<<SOLUONG<<setw(20)<<DONGIA*SOLUONG<<endl; } int main() { int n; cout<<"Nhap so mat hang: "; cin>>n; Hang * x = new HANG[n]; for(int i=0; i<n; i++) { cout<<"Nhap hang "<<i+1<<endl; x[i].XUAT(); return 0; } BÀI 1. OBJECT ARRAY CONTINUE class SACH { char MASACH[10]; char TENSACH[20]; int SOTRANG; float GIATIEN; public: void NHAP(); void XUAT(); }; void SACH::NHAP() { cout<<"Ma sach : "; fflush(stdin); gets(MASACH); cout<<"Ten sach : "; fflush(stdin); gets(TENSACH); cout<<"So trang : "; cin>>SOTRANG; cout<<"Gia tien : "; cin>>GIATIEN; } void SACH::XUAT() { cout<<setw(10)<<MASACH<<setw(20)<<TENSACH<<setw(10)<<SOTRANG<<setw (10)<<GIATIEN<<endl; } int main() { int n; cout<<"Nhap so sach: "; cin>>n; SACH *x=new SACH[n]; for(int i=0; i<n; i++) { cout<<"Nhap sach thu "<<i+1<<endl; x[i].XUAT(); return 0; } BÀI 1.
ARRAY OF NUMBERS class MANG { int *a; int n; public: void NHAP(); void XUAT(); void SAP(); }; void MANG::NHAP() { cout<<"n= "; cin>>n; a=new int[n]; for(int i=0; i<n; i++) { cout<<"a["<<i<<"]="; cin>>a[i]; } } void MANG::XUAT() { cout<<endl; for(int i=0; i<n; i++) cout<<a[i]<<" "; } void MANG::SAP() { for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) if(a[i]>a[j]) { int tg=a[i]; a[i]=a[j]; a[j]=tg; } } int main() { MANG x; x.XUAT(); return 0; } BÀI 1. COMPLETE class MANG { float *a; int n; public: void NHAP(); void XUAT(); float MAX(); float MIN(); }; void MANG::NHAP() { cout<<"n= "; cin>>n; a=new float[n]; for(int i=0; i<n; i++) { cout<<"a["<<i<<"]="; cin>>a[i]; } } void MANG::XUAT() { cout<<endl; for(int i=0; i<n; i++) cout<<a[i]<<" "; } float MANG::MAX() { float M=a[0]; for(int i=0; i<n; i++) if(a[i]>M) M=a[i] ; return M; } float MANG::MIN() { float M=a[0]; for(int i=0; i<n; i++) if(a[i]<M) M=a[i]; return M; } int main() { MANG x; x.NHAP(); cout<<"Mang vua nhap:"<<endl; x.XUAT(); cout<<"MAX="<<x.MIN(); return 0; } BÀI 2. DATE TYPE class DATE { int D, M, Y; public: void NHAP(); void XUAT(); }; class NHANSU { char MANS[20]; char HOTEN[30]; DATE NS; public: void NHAP(); void XUAT(); }; void DATE::NHAP() { cout<<"Day: "; cin>>D; cout<<"Month: "; cin>>M; cout<<"Year: "; cin>>Y; } void DATE::XUAT() { cout<<setw(10)<<D<<"/"<<M<<"/"<<Y<<endl; } void NHANSU::NHAP() { cout<<"Ma nhan su: "; fflush(stdin); gets(MANS); cout<<"Ten nhan su: "; fflush(stdin); gets(HOTEN); cout<<"Ngay thang nam sinh:"<<endl; NS.NHAP(); } void NHANSU::XUAT() { cout<<setw(10)<<MANS<<setw(15)<<HOTEN; NS.NHAP(); cout<<endl<<"Nhan su vua nhap:"<<endl; x.XUAT(); return 0; } BÀI 2. ONE-ONE RELATIONSHIP class NSX { char MANSX[20]; char TENNSX[20]; char DCNSX[20]; public: void NHAP(); void XUAT(); }; class HANG { char MANHANG[20]; char TENHANG[30]; NSX x; public: void NHAP(); void XUAT(); }; void NSX::NHAP() { cout<<"Ma NSX : "; fflush(stdin); gets(MANSX); cout<<"Ten NSX: "; fflush(stdin); gets(TENNSX); cout<<"DC NSX: "; fflush(stdin); gets(DCNSX); } void NSX::XUAT() { cout<<"Ma NSX : "<<MANSX<<endl; cout<<"Ten NSX: "<<TENNSX<<endl; cout<<"DC NSX: "<<DCNSX<<endl; } void HANG::NHAP() { cout<<"Ma hang: "; fflush(stdin); gets(MANHANG); cout<<"Ten hang: "; fflush(stdin); gets(TENHANG); cout<<"Nha san xuat:"<<endl; x.NHAP(); } void HANG::XUAT() { cout<<"Ma hang: "<<MANHANG<<endl; cout<<"Ten hang: "<<TENHANG<<endl; cout<<"Nha san xuat: "; x.NHAP(); cout<<endl<<"Mat hang vua nhap:"<<endl; x.XUAT(); return 0; } BÀI 2.
ONE-INFINITY RELATIONSHIP class HANG { char MAHANG[20]; char TENHANG[20]; float DONGIA; public: void NHAP(); void XUAT(); }; class PHIEU { char MAPHIEU[20]; HANG *x; int n; public: void NHAP(); void XUAT(); }; void HANG::NHAP() { cout<<"Ma Hang : "; fflush(stdin); gets(MAHANG); cout<<"Ten Hang: "; fflush(stdin); gets(TENHANG); cout<<"Don Gia: "; cin>>DONGIA; } void HANG::XUAT() { cout<<setw(10)<<MAHANG<<setw(20)<<TENHANG<<setw(10)<<DONGIA<<endl; } void PHIEU::NHAP() { cout<<"Ma Phieu: "; fflush(stdin); gets(MAPHIEU); cout<<"Nhap so mat hang: "; cin>>n; x=new HANG[n]; for(int i=0; i<n; i++) x[i].NHAP(); cout<<endl<<setw(30)<<"PHIEU NHAP HANG"<<endl; a.XUAT(); return 0; } BÀI 2. MIXED RELATIONSHIP class MAY { char MAMAY[10]; char KIEUMAY[20]; char TINHTRANG[20]; public: void NHAP(); void XUAT(); }; class QUANLY { char MAQL[10]; char TENQL[20]; public: void NHAP(); void XUAT(); }; class PHONGMAY { char MAPHONG[10]; char TENPHONG[20]; QUANLY x; MAY *y; int n; public: void NHAP(); void XUAT(); }; void MAY::NHAP() { cout<<"Ma May : "; fflush(stdin); gets(MAMAY); cout<<"Kieu May: "; fflush(stdin); gets(KIEUMAY); cout<<"Tinh Trang: "; fflush(stdin); gets(TINHTRANG); } void MAY::XUAT() { cout<<setw(10)<<MAMAY<<setw(20)<<KIEUMAY<<setw(20)<<TINHTRANG<<endl; } void QUANLY::NHAP() { cout<<"Ma nguoi quan ly: "; fflush(stdin); gets(MAQL); cout<<"Ten nguoi quan ly: "; fflush(stdin); gets(TENQL); } void QUANLY::XUAT() { cout<<"Ma nguoi quan ly: "<<MAQL<<endl; cout<<"Ten nguoi quan ly: "<<TENQL<<endl; } void PHONGMAY::NHAP() { cout<<"Ma phong: "; fflush(stdin); gets(MAPHONG); cout<<"Ten phong:"; fflush(stdin); gets(TENPHONG); x.NHAP(); } void PHONGMAY::XUAT() { cout<<endl<<"Ma phong: "<<MAPHONG; cout<<". Ten phong: "<<TENPHONG<<endl; x.XUAT(); return 0; } BÀI 3. FRIEND FUNCTION class SINHVIEN { char MASINHVIEN[10]; char HOTEN[20]; float TOAN, LY, HOA; public: void NHAP(); void XUAT(); friend void SAP(SINHVIEN *a, int n); }; void SINHVIEN::NHAP() { cout<<"Ma sinh vien: "; fflush(stdin); gets(MASINHVIEN); cout<<"Ho ten: "; fflush(stdin); gets(HOTEN); cout<<"Diem toan: "; cin>>TOAN; cout<<"Diem ly: "; cin>>LY; cout<<"Diem hoa: "; cin>>HOA; } void SINHVIEN::XUAT() { cout<<setw(10)<<MASINHVIEN<<setw(20)<<HOTEN<<setw(10)<<TOAN<<setw(10) <<LY<<setw(10)<<HOA<<setw(10)<<TOAN+LY+HOA<<endl; } void SAP(SINHVIEN *a, int n) { for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) if(a[i].HOA) { SINHVIEN tg=a[i]; a[i]=a[j]; a[j]=tg; } } int main() { SINHVIEN *a; int n; cout<<"Nhap so sinh vien: "; cin>>n; a=new SINHVIEN[n]; for(int i=0; i<n; i++) a[i].XUAT(); return 0; } BÀI 3.
FRIEND CLASS class NSX { char MANSX[20]; char TENNSX[20]; char DCNSX[20]; friend class HANG; //lớp bạn }; class HANG { char MANHANG[20]; char TENHANG[30]; float DONGIA, TRONGLUONG; NSX x; public: void NHAP(); void XUAT(); }; void HANG::NHAP() { cout<<"Ma hang: "; fflush(stdin); gets(MANHANG); cout<<"Ten hang: "; fflush(stdin); gets(TENHANG); cout<<"Don gia: "; cin>>DONGIA; cout<<"Trong luong: "; cin>>TRONGLUONG; cout<<"Ma NSX: "; fflush(stdin); gets(x.MANSX); cout<<"Ten NSX:"; fflush(stdin); gets(x.TENNSX); cout<<"Dia chi:"; fflush(stdin); gets(x.DCNSX); } void HANG::XUAT() { cout<<"Ma hang: "<<MANHANG<<endl; cout<<"Ten hang: "<<TENHANG<<endl; cout<<"Don gia: "<<DONGIA<<endl; cout<<"Trong luong: "<<TRONGLUONG<<endl; cout<<"Ma NSX: "<<x.MANSX<<endl; cout<<"Ten NSX: "<<x.TENNSX<<endl; cout<<"Dia chi: "<<x.DCNSX<<endl; } int main() { HANG x; x.NHAP(); cout<<endl<<"Mat hang vua nhap:"<<endl; x.XUAT(); return 0; } BÀI 3. FRIENDS class HANG; class DATE { int D, M, Y; friend void IN(HANG a[], int n, int NAM); friend class HANG; }; class HANG { char MANHANG[20]; char TENHANG[30]; DATE x; public: void NHAP(); void XUAT(); friend void IN(HANG a[], int n); }; void HANG::NHAP() { cout<<"Ma hang: "; fflush(stdin); gets(MANHANG); cout<<"Ten hang: "; fflush(stdin); gets(TENHANG); cout<<"Nhap Ngay san xuat: "<<endl; cout<<"Ngay: "; cin>>x.D; cout<<"Thang: "; cin>>x.M; cout<<"Nam: "; cin>>x.Y; } void HANG::XUAT() { cout<<"Ma hang: "<<MANHANG<<endl; cout<<"Ten hang: "<<TENHANG<<endl; cout<<"Nhap Ngay san xuat: "<<x.Y<<endl; } void IN(HANG a[], int n) { for(int i=0; i<n; i++) if(a[i].NHAP(); cout<<endl<<"Mat hang nhap: 2017"<<endl; IN(a, n); return 0; } BÀI 3. CONSTRUCTOR METHODS class PTB2 { float a, b, c; public: void NHAP(); void XUAT(); void GIAI(); PTB2(); PTB2(float x, float y, float z); }; void PTB2::NHAP() { cout<<"Nhap cac he so: "<<endl; cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"c="; cin>>c; } void PTB2::XUAT() { cout<<"Phuong trinh: "<<a<<"X"<<(char)253<<” + "<<b<<"X + "<<c<<" = 0"<<endl; } void PTB2::GIAI() { if(a==0) cout<<"Day khong phai ptb2"<<endl; else { float delta = b*b-4*a*c; if(delta<0) cout<<"Phuong trinh vo nghiem"<<endl; else { cout<<"X1="<<(-b+sqrt(delta))/(2*a)<<endl; cout<<"X2="<<(-b-sqrt(delta))/(2*a)<<endl; } } } PTB2::PTB2() { a=b=c=0; } PTB2::PTB2(float x, float y, float z) { a=x; b=y; c=z; } int main() { PTB2 P(1, 2, 1); P.GIAI(); return 0; } BÀI 3. CONSTRUCTOR/ DESTRUCTOR METHODS class ARRAY { int *VALUE; int n; public: ARRAY(); ARRAY(int x); ~ARRAY(); void NHAP(); void XUAT(); }; ARRAY::ARRAY() { n=0; VALUE=NULL; } ARRAY::ARRAY(int x) { n=x; VALUE = new int[n]; for(int i=0; i<n; i++) VALUE[i]=0; } ARRAY::~ARRAY() { n=0; VALUE=NULL; //OR: delete [] VALUE; } void ARRAY::NHAP() { if(n==0) {cout<<"n="; cin>>n;} if(VALUE==NULL) VALUE = new int[n]; for(int i=0; i<n; i++) { cout<<"VALUE["<<i<<"]="; cin>>VALUE[i]; } } void ARRAY::XUAT() { for(int i=0; i<n; i++) cout<<VALUE[i]<<" "; } int main() { ARRAY x(8); cout<<endl<<"Mang vua khoi tao : "; x.XUAT(); cout<<endl<<"Nhap mang: "<<endl; x.NHAP(); cout<<endl<<"Mang vua nhap: "; x.XUAT(); return 0; } BÀI O1.
COUPON class NCC { char MANCC[10]; char TENNCC[20]; char DCNCC[20]; public: void NHAP(); void XUAT(); }; class HANG { char TENHANG[20]; float DONGIA; int SOLUONG; public: void NHAP(); void XUAT(); friend class PHIEU; }; class PHIEU { char MAPHIEU[20]; char NGAYLAP[20]; NCC y; HANG *x; int n; public: void NHAP(); void XUAT(); }; void NCC::NHAP() { cout<<"Ma NCC: "; fflush(stdin); gets(MANCC); cout<<"Ten NCC: "; fflush(stdin); gets(TENNCC); cout<<"DC NCC: "; fflush(stdin); gets(DCNCC); } void NCC::XUAT() { cout<<"Ma NCC: "<<setw(15)<<MANCC; cout<<setw(15)<<"Ten NCC: "<<setw(15)<<TENNCC<<endl; cout<<"DC NCC: "<<DCNCC<<endl; } void HANG::NHAP() { cout<<"Ten hang: "; fflush(stdin); gets(TENHANG); cout<<"Don gia: "; cin>>DONGIA; cout<<"So luong: "; cin>>SOLUONG; } void HANG::XUAT() { cout<<setw(20)<<TENHANG<<setw(10)<<DONGIA<<setw(10)<<SOLUONG <<setw(10)<<DONGIA*SOLUONG<<endl; } void PHIEU::NHAP() { cout<<"Ma phieu: "; fflush(stdin); gets(MAPHIEU); cout<<"Ngay lap: "; fflush(stdin); gets(NGAYLAP); y.NHAP(); } void PHIEU::XUAT() { cout<<setw(40)<<"PHIEU NHAP HANG"<<endl; cout<<"Ma phieu: "<<setw(15)<<MAPHIEU; cout<<setw(15)<<"Ngay lap: "<<setw(15)<<NGAYLAP<<endl; y.SOLUONG; cout<<setw(50)<<"Cong thanh tien: "<<TONGTIEN<<endl; } int main() { PHIEU a; a.XUAT(); return 0; } BÀI O1. TRANSCRIPT class SINHVIEN { char MASV[20]; char TENSV[20]; char LOP[10]; char KHOA[10]; public: void NHAP(); void XUAT(); }; class MON { char TENMON[20]; int SOTRINH; float DIEM; public: void NHAP(); void XUAT(); friend class PHIEU; }; class PHIEU { SINHVIEN x; MON *y; int n; public: void NHAP(); void XUAT(); }; void SINHVIEN::NHAP() { cout<<"Ma sv: "; fflush(stdin); gets(MASV); cout<<"Ten sv: "; fflush(stdin); gets(TENSV); cout<<"Lop: "; fflush(stdin); gets(LOP); cout<<"Khoa: "; fflush(stdin); gets(KHOA); } void SINHVIEN::XUAT() { cout<<"Ma sv: "<<MASV<<"\t"; cout<<"Ten sv: "<<TENSV<<endl; cout<<"Lop: "<<LOP<<"\t"; cout<<"Khoa: "<<KHOA<<endl; } void MON::NHAP() { cout<<"Ten mon: "; fflush(stdin); gets(TENMON); cout<<"So trinh:"; cin>>SOTRINH; cout<<"Diem: "; cin>>DIEM; } void MON::XUAT() { cout<<setw(20)<<TENMON<<setw(20)<<SOTRINH<<setw(20)<<DIEM<<endl; } void PHIEU::NHAP() { x.NHAP(); } void PHIEU::XUAT() { cout<<setw(40)<<"PHIEU BAO DIEM"<<endl<<endl; x.n+1)*sizeof(MON)); for(int i = p.n++; } int main() { PHIEU a; a.XUAT(); return 0; } BÀI O1. INVENTORY class PHIEU; class NHANVIEN { char HOTENNV[20]; char CHUCVUNV[20]; public: void NHAP(); void XUAT(); }; class PHONG { char MAPH[20]; char TENPH[20]; char TRUONGPH[20]; public: void NHAP(); void XUAT(); }; class TAISAN { char TENTS[20]; int SOLUONGTS; char TINHTRANGTS[20]; public: void NHAP(); void XUAT(); friend class PHIEU; friend void SUA(PHIEU a); friend void SAP(PHIEU a); }; class PHIEU { char MAPH[20]; char NGAYKK[20]; NHANVIEN x; PHONG y; TAISAN *z; int n; public: void NHAP(); void XUAT(); friend void SUA(PHIEU a); friend void SAP(PHIEU a); }; void NHANVIEN::NHAP() { cout<<"Ho ten: "; fflush(stdin); gets(HOTENNV); cout<<"Chuc vu: "; fflush(stdin); gets(CHUCVUNV); } void NHANVIEN::XUAT() { cout<<"Nhan vien kiem ke: "<<HOTENNV<<"\t"<<"Chuc vu: " <<CHUCVUNV<<endl; } void PHONG::NHAP() { cout<<"Ma phong: "; fflush(stdin); gets(MAPH); cout<<"Ten phong:"; fflush(stdin); gets(TENPH); cout<<"Truong phong: "; fflush(stdin); gets(TRUONGPH); } void PHONG::XUAT() { cout<<"Kiem ke tai phong: "<<TENPH<<"\t"<<"Ma phong: " <<MAPH<<endl; cout<<"Truong phong: "<<TRUONGPH<<endl; } void TAISAN::NHAP() { cout<<"Ten tai san: "; fflush(stdin); gets(TENTS); cout<<"So luong: "; cin>>SOLUONGTS; cout<<"Tinh trang: "; fflush(stdin); gets(TINHTRANGTS); } void TAISAN::XUAT() { cout<<setw(20)<<TENTS<<setw(20)<<SOLUONGTS<<setw(20)<<TINHTRANGTS <<endl; } void PHIEU::NHAP() { cout<<"Ma phieu: "; fflush(stdin); gets(MAPH); cout<<"Ngay kiem ke: "; fflush(stdin); gets(NGAYKK); x.NHAP(); } void PHIEU::XUAT() { cout<<setw(40)<<"PHIEU KIEM KE TAI SAN"<<endl; cout<<"Ma phieu: "<<MAPH<<"\t"<<"Ngay kiem ke: "<<NGAYKK<<endl; x.SOLUONGTS; cout<<"So tai san kiem ke: "<<n<<"\t"<<". Tong so luong: " <<TONGSL<<endl; } Bonus 1: void SUA(PHIEU a) { for(int i=0; i<a.TENTS, “May vi tinh”)==0) a.SOLUONGTS = 20; } Bonus 2: void SAP(PHIEU a) { for(int i=0; i<a.SOLUONGTS) { TAISAN tg = a.XUAT(); return 0; } BÀI 4.