Skip to content

Instantly share code, notes, and snippets.

@nguyentruongky
Created July 14, 2021 12:30
Show Gist options
  • Save nguyentruongky/23deff201c2ec53855db92d6232693db to your computer and use it in GitHub Desktop.
Save nguyentruongky/23deff201c2ec53855db92d6232693db to your computer and use it in GitHub Desktop.
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
using namespace std;
struct Sach
{
string id;
string tenSach;
string tacGia;
int giaBan;
int namXuatBan;
void nhapSach()
{
cout << "Ten sach: ";
cin.ignore(); // Dung lai cho nhap ten sach
getline(cin, tenSach);
cout << "Tac gia: ";
getline(cin, tacGia);
cout << "Gia ban: ";
cin >> giaBan;
cout << "Nam xuat ban: ";
cin >> namXuatBan;
}
void inThongTin()
{
cout << "==== Thong tin sach ====\n";
cout << "Ten sach: " << tenSach << "\n";
cout << "Tac gia: " << tacGia + "\n";
cout << "Gia: " << giaBan << "\n";
cout << "Xuat ban: " << namXuatBan << "\n";
}
};
int showMenu() {
cout << "==============";
cout << "Xin chao! Vui long chon hanh dong ban muon thuc hien:\n";
cout << "1. Nhap 1 quyen sach moi\n";
cout << "2. Tim sach\n"; // tim bang ten sach hoac ten tac gia
cout << "3. Thay doi thong tin sach\n";
cout << "4. Doc file tu dia cung\n";
cout << "5. Thay doi thong tin sach\n";
cout << "6. Sap xep sach";
cout << "\n";
cout << "Nhap so de lua chon: ";
int luaChon;
cin >> luaChon;
return luaChon;
}
void themSach() {
Sach sach;
sach.nhapSach();
sach.inThongTin();
cout << "==============";
cout << "Ban co muon nhap them sach hay khong? Y/N";
string yesOrNo;
cin >> yesOrNo;
if (yesOrNo == "Y") {
cout << "Chuan bi nhap sach moi...\n";
themSach();
} else {
showMenu();
}
}
void timSach() {
cout << "==============";
cout << "Nhap ten sach can tim: \n";
cin.ignore();
string tenSach;
getline(cin, tenSach);
cout << "Dang tim sach " << tenSach << " cho ban. Cho chut...\n";
cout << "Tim ";
}
int main()
{
int luaChon = showMenu();
if (luaChon == 1)
{
themSach();
} else if (luaChon == 2) {
timSach();
} else if (luaChon == 3) {
cout << "Nhap ID cua quyen sach ma ban muon thay doi\n";
int id;
cin >> id;
// tim sach bang id (luaChon 2)
cout << "Khong tim duoc quyen sach nay\n";
}
else {
cout << "May ngu qua, co 1 va 2 thoi.\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment