Created
August 16, 2015 05:45
-
-
Save toanalien/f144737d8279b34717d1 to your computer and use it in GitHub Desktop.
cafemini.cpp
This file contains 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 <iostream> | |
#include <fstream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
fstream f, f_out; | |
int n, b, c, somon; | |
int bien = 0; | |
struct menu | |
{ | |
int soThuTu; | |
string ten; | |
long gia; | |
}; | |
menu mang[1000]; | |
void thietLapMenu(); | |
void chonmon(); | |
void inhoadon(); | |
int main() | |
{ | |
bool done=false; | |
while (!done) | |
{ | |
cout << "Moi ban chon cac tinh nang: " << endl; | |
cout << " 1.Thiet lap menu cho quan " << endl; | |
cout << " 2.Chon thuc uong " << endl; | |
cout << " 3.In hoa don " << endl; | |
cout << " 4.Thoat" << endl; | |
cout << "Ban chon: "; | |
cin >> n; | |
{ | |
switch (n) | |
{ | |
case 1: | |
{ | |
thietLapMenu(); | |
break; | |
} | |
case 2: | |
{ | |
chonmon(); | |
break; | |
} | |
case 3: | |
{ | |
inhoadon(); | |
break; | |
} | |
case 4: | |
{ | |
done =true; | |
break; | |
} | |
} | |
} | |
} | |
return 0; | |
} | |
void thietLapMenu() | |
{ | |
int somon; | |
cout << "Nhap menu: " << endl; | |
f.open("menu.txt", ios::out); | |
cout << "So mon can nhap la: "; | |
cin >> somon; | |
for (int i = 1; i <= somon; i++) | |
{ | |
cout << "Nhap ten mon: "; | |
fflush(stdin); | |
getline(cin, mang[i].ten); | |
cout << "Nhap gia: "; | |
cin >> mang[i].gia; | |
mang[i].soThuTu = i; | |
f << mang[i].soThuTu << " " << mang[i].ten << " " << mang[i].gia << endl; | |
f.close(); | |
} | |
} | |
void chonmon() | |
{ | |
//doc so thu tu soThuTu_donhangach hang | |
int khachhang; | |
f.open("khachhang.txt", ios::in); | |
if (!f) { | |
khachhang = 0; | |
} | |
else { | |
while (!f.eof()) | |
f >> khachhang; | |
} | |
f.close(); | |
f.open("khachhang.txt", ios::out | ios::trunc); | |
khachhang += 1; | |
f << khachhang << endl; | |
cout << " Khach hang thu " << khachhang << endl; | |
f.close(); | |
int soThuTumon; | |
int somoncangoi; | |
string xuatten = "Ten mon"; | |
int xuatsoThuTu = 0; | |
long xuatgia = 0; | |
cout << " Menu gom co: \n"; | |
f.open("menu.txt", ios::in); | |
if (!f) | |
cout << "Chua co menu !"; | |
else | |
{ | |
int i = 1; | |
while (!f.eof()) | |
{ | |
cout << xuatsoThuTu << " " << xuatten << " " << xuatgia << endl; | |
f >> xuatsoThuTu >> xuatten >> xuatgia; | |
mang[i].soThuTu = xuatsoThuTu; | |
mang[i].ten = xuatten; | |
mang[i].gia = xuatgia; | |
i++; | |
} | |
f.close(); | |
char buffer[33]; | |
itoa(khachhang, buffer, 10); | |
string soThuTu_donhang(buffer); | |
if (khachhang<10) | |
f.open("000" + soThuTu_donhang + ".txt", ios::out); | |
else if (khachhang <100) | |
f.open("00" + soThuTu_donhang + ".txt", ios::out); | |
else if (khachhang <1000) | |
f.open("0" + soThuTu_donhang + ".txt", ios::out); | |
else | |
f.open(soThuTu_donhang + ".txt", ios::out); | |
cout << "So mon ban muon goi la: "; | |
cin >> somoncangoi; | |
for (int i = 0; i<somoncangoi; i++) | |
{ | |
cout << "Ban chon mon co soThuTu: "; | |
cin >> soThuTumon; | |
f << i + 1 << " " << mang[soThuTumon].ten << " " << mang[soThuTumon].gia << endl; | |
} | |
f.close(); | |
} | |
} | |
void inhoadon() | |
{ | |
int maHoaDon; | |
int soThuTu = 0; | |
string ten = "Ten"; | |
long gia = 0; | |
long tong = 0; | |
cout << "Nhap ma don hang: \n Vi du:0001,0002,0003.... " << endl; | |
cin >> maHoaDon; | |
stringstream sstr; | |
sstr << maHoaDon; | |
string soThuTu_donhang = sstr.str(); | |
if (maHoaDon<10) { | |
f.open("000" + soThuTu_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_000" + soThuTu_donhang + ".txt", ios::out); | |
} | |
else if (maHoaDon <100) { | |
f.open("00" + soThuTu_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_00" + soThuTu_donhang + ".txt", ios::out); | |
} | |
else if (maHoaDon <1000) { | |
f.open("0" + soThuTu_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_0" + soThuTu_donhang + ".txt", ios::out); | |
} | |
else { | |
f.open(soThuTu_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_" + soThuTu_donhang + ".txt", ios::out); | |
} | |
while (!f.eof()) | |
{ | |
f_out << soThuTu << "\t" << ten << "\t" << gia << endl; | |
tong = tong + gia; | |
f >> soThuTu >> ten >> gia; | |
} | |
f.close(); | |
f_out << "Tong:\t \t" << tong; | |
f_out.close(); | |
cout << "Hoa don cua ban da duoc in \n" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment