#include<iostream>
#include<Windows.h>
#include<string>
#include<conio.h>
#include<stdio.h>
using namespace std;
class THUVIEN{
private:
string ID, Date, NXB;
float SoLuong, DonGia;
float Pay;
public:
string getID();
string getDate();
string getNXB();
float getPay();
float getSL();
float getDG();
void setSL(float sl);
void setDG(float dg);
void setPay(float pay);
void setID(string id);
void setDate(string date);
void setNXB(string nxb);
THUVIEN();
THUVIEN(string id, string date, string nxb, float sl, float dgia, float pay);
virtual float ThanhTien()=0;
virtual void NHAP();
virtual void Xuat();
};
class SACHGIAOKHOA:public THUVIEN{
private:
int TinhTrang;
public:
SACHGIAOKHOA();
SACHGIAOKHOA(string id, string date, string nxb, int sl, int dgia, float pay, int tt);
int getTinhTrang();
void setTinhTrang(int ttrang);
float ThanhTien();
void NHAP();
void Xuat();
};
class SACHTHANKHAO:public THUVIEN{
private:
float Thue;
public:
float getThue();
void setThue(float thue);
SACHTHANKHAO();
SACHTHANKHAO(string id, string date, string nxb, int sl, int dgia, float pay, float thue);
float ThanhTien();
void NHAP();
void Xuat();
};
void exit();
void keybk();
// MAIN///////////////////////////////////////
/////////////////////////////////////////////
int main(){
THUVIEN *TV[100];
int key, count=0, count_STK=0;
float TongTienSGK = 0, TongTienSTK=0;
float TongTien=0, TBC_SKK=0;
do{
system("cls");
cout<<"===== MENU ====="<<endl;
cout<<"\n1_ Nhap Sach Giao Khoa\n2_ Nhap Sach Tham Khao\n3_ Xuat All Danh Sach"<<endl;
cout<<"4_ Tong Tien Tung Loai Sach\n5_ TBC Sach Tham Khao\n6_ Tim\n0_ Exit!!!"<<endl;
cout<<"Ban Muon Chon?: ";
cin>>key;
switch(key){
case 0: break;
case 1:{
cout<<"\n==== NHAP SACH Giao KHAO ===="<<endl;
TV[count] = new SACHGIAOKHOA();
TV[count]->NHAP();
TongTienSGK = TongTienSGK + TV[count]->getPay();
count++;
break;
}
case 2:{
cout<<"\n==== NHAP SACH THAM KHAO ===="<<endl;
TV[count] = new SACHTHANKHAO();
TV[count]->NHAP();
TongTienSTK = TongTienSTK + TV[count]->getPay();
TBC_SKK = TBC_SKK + TV[count]->getPay();
count++;
count_STK++;
break;
}
case 3:{
cout<<"\n==== XUAT ALL LIST ===="<<endl;
for(int i=0; i<count; i++){
TV[i]->Xuat();
cout<<endl;
}
keybk();
getch();
break;
}
case 4:{
cout<<"\n==== Tong Tien Tung Loai Sach ====\n"<<endl;
cout<<"Tong Tien Cua Sach Giao Khoa: "<<TongTienSGK<<" VND"<<endl;
cout<<"Tong Tien Cua Sach Tham Khao: "<<TongTienSTK<<" VND"<<endl;
keybk();
getch();
break;
}
case 5:{
cout<<"\n==== TBC DON GIA SACH THAM KHAO ====\n"<<endl;
float result= (float)TBC_SKK/count_STK;
cout<<"TBC Don Gia STK= "<<result<<" VND"<<endl;
keybk();
getch();
break;
}
case 6:{
cout<<"\n==== XUAT Sach Giao Khoa Cua Nha Xuat Ban X ===="<<endl;
string x; cin.ignore();
cout<<"Nhap Ten NXB Can Tim: "; getline(std::cin,x);
for(int i=0; i<count; i++){
if(TV[i]->getNXB() == x) TV[i]->Xuat();
}
keybk();
getch();
break;
}
default:{
cout<<"\nKhong co lua chon nay!!!"<<endl;
break;
}
}
}while(key!=0);
exit();
return 0;
}
// CLASS THUVIEN//////////////////////////////////////
/////////////////////////////////////////////////////
void THUVIEN::setDate(string date){
Date = date;
}
void THUVIEN::setDG(float dg){
DonGia = dg;
}
void THUVIEN::setID(string id){
ID = id;
}
void THUVIEN::setNXB(string nxb){
NXB = nxb;
}
void THUVIEN::setPay(float pay){
Pay = pay;
}
void THUVIEN::setSL(float sl){
SoLuong = sl;
}
string THUVIEN::getDate(){
return Date;
}
float THUVIEN::getDG(){
return DonGia;
}
string THUVIEN::getID(){
return ID;
}
string THUVIEN::getNXB(){
return NXB;
}
float THUVIEN::getPay(){
return Pay;
}
float THUVIEN::getSL(){
return SoLuong;
}
THUVIEN::THUVIEN(){
setDate("0/0/0");
setDG(0);
setID(" ");
setNXB(" ");
setPay(0);
setSL(0);
}
THUVIEN::THUVIEN(string id, string date, string nxb, float sl, float dgia, float pay){
setID(id);
setDate(date);
setNXB(nxb);
setSL(sl);
setDG(dgia);
setPay(pay);
}
void THUVIEN::NHAP(){
cin.ignore();
cout<<"Nhap ID: ";
string id;
getline(std::cin,id);
setID(id);
cout<<"Ngay Nhap: ";
string date;
getline(std::cin,date);
setDate(date);
cout<<"Nhap Ten NXB: ";
string nxb;
getline(std::cin,nxb);
setNXB(nxb);
cout<<"Nhap So Luong: ";
float sl;
cin>>sl;
setSL(sl);
cout<<"Nhap Don Gia: ";
float dg;
cin>>dg;
setDG(dg);
}
void THUVIEN::Xuat(){
cout<<"\nID: "<<getID()<<"\nNgay Nhap: "<<getDate()<<"\nNXB: "<<getNXB()<<endl;
cout<<"So Luong: "<<getSL()<<"\nDon Gia: "<<getDG()<<endl;
}
// CLASS SACH GIAO KHOA//////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
int SACHGIAOKHOA::getTinhTrang(){
return TinhTrang;
}
void SACHGIAOKHOA::setTinhTrang(int ttrang){
TinhTrang = ttrang;
}
SACHGIAOKHOA::SACHGIAOKHOA(){
setDate("0/0/0");
setDG(0);
setID(" ");
setNXB(" ");
setPay(0);
setSL(0);
setTinhTrang(0);
}
SACHGIAOKHOA::SACHGIAOKHOA(string id, string date, string nxb, int sl, int dgia, float pay, int tt){
setID(id);
setDate(date);
setNXB(nxb);
setSL(sl);
setDG(dgia);
setPay(pay);
setTinhTrang(tt);
}
void SACHGIAOKHOA::NHAP(){
cin.ignore();
cout<<"Nhap ID: ";
string id;
getline(std::cin,id);
setID(id);
cout<<"Ngay Nhap: ";
string date;
getline(std::cin,date);
setDate(date);
cout<<"Nhap Ten NXB: ";
string nxb;
getline(std::cin,nxb);
setNXB(nxb);
cout<<"Nhap So Luong: ";
float sl;
cin>>sl;
setSL(sl);
cout<<"Nhap Don Gia: ";
float dg;
cin>>dg;
setDG(dg);
cin.ignore();
cout<<"Nhap Tinh Trang (1-Moi/0-Cu): ";
int tt;
cin>>tt;
setTinhTrang(tt);
float tien = ThanhTien();
setPay(tien);
}
float SACHGIAOKHOA::ThanhTien(){
float tien=0;
if(getTinhTrang() == 1){
tien = getSL()*getDG();
return tien;
}
if(getTinhTrang()==0){
tien = (float) getSL() * getDG() * (float)(0.5);
return tien;
}
return 0;
}
void SACHGIAOKHOA::Xuat(){
cout<<"\nID: "<<getID()<<"\nNgay Nhap: "<<getDate()<<"\nNXB: "<<getNXB()<<endl;
cout<<"So Luong: "<<getSL()<<"\nDon Gia: "<<getDG()<<"\nThanh Tien: "<<getPay()<<" VND"<<endl;
}
// CLASS SACH THAM KHAO /////////////////////////////////////////
////////////////////////////////////////////////////////////////
float SACHTHANKHAO::getThue(){
return Thue;
}
void SACHTHANKHAO::setThue(float thue){
Thue = thue;
}
SACHTHANKHAO::SACHTHANKHAO(){
setDate("0/0/0");
setDG(0);
setID(" ");
setNXB(" ");
setPay(0);
setSL(0);
setThue(0);
}
SACHTHANKHAO::SACHTHANKHAO(string id, string date, string nxb, int sl, int dgia, float pay, float thue){
setID(id);
setDate(date);
setNXB(nxb);
setSL(sl);
setDG(dgia);
setPay(pay);
setThue(thue);
}
float SACHTHANKHAO::ThanhTien(){
float thanhtien;
thanhtien = (float)getSL()*(getDG()+getThue());
return thanhtien;
}
void SACHTHANKHAO::NHAP(){
cin.ignore();
cout<<"Nhap ID: ";
string id;
getline(std::cin,id);
setID(id);
cout<<"Ngay Nhap: ";
string date;
getline(std::cin,date);
setDate(date);
cout<<"Nhap Ten NXB: ";
string nxb;
getline(std::cin,nxb);
setNXB(nxb);
cout<<"Nhap So Luong: ";
float sl;
cin>>sl;
setSL(sl);
cout<<"Nhap Don Gia: ";
float dg;
cin>>dg;
setDG(dg);
cin.ignore();
cout<<"Nhap Thue: ";
float thue;
cin>>thue;
setThue(thue);
float tien = ThanhTien();
setPay(tien);
}
void SACHTHANKHAO::Xuat(){
cout<<"\nID: "<<getID()<<"\nNgay Nhap: "<<getDate()<<"\nNXB: "<<getNXB()<<endl;
cout<<"So Luong: "<<getSL()<<"\nDon Gia: "<<getDG()<<"\nThue: "<<getThue()<<"\nThanh Tien: "<<getPay()<<" VND"<<endl;
}
void exit(){
string a = "Ban Da Thoat Khoi Chuong Trinh!!!\nBYE!";
for(int i=0; i<a.length(); i++){
Sleep(10);
cout<<a[i];
}
}
void keybk(){
string a = "\nNhan Phim Bat Ky De Tro Lai Menu!!!";
for(int i=0; i<a.length(); i++){
Sleep(10);
cout<<a[i];
}
}
No Comment to " Bài Tập 2 - C5 (Môn LT Hướng Đối Tượng C++) "