Created
August 15, 2015 20:06
-
-
Save toanalien/9732a98f6cb4581f98ba to your computer and use it in GitHub Desktop.
cafe_fina
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, a, b, c, somon, bien = 0; | |
struct menu | |
{ | |
int stt; | |
string ten; | |
long gia; | |
}; | |
menu mang[100]; | |
void nhapmenu() | |
{ | |
int somon; | |
cout << "Nhap menu: " << endl; | |
cout << "\t 1. Nhap toi da 4 mon stt_donhangac nhau: " << endl; | |
cout << "\t 2 Nhap stt_donhangong gioi han so mon: " << endl; | |
cout << "Ban chon: "; | |
cin >> a; | |
f.open("menu.txt", ios::out); | |
if (a == 1) | |
{ | |
for (int i = 1; i <= 4; i++) | |
{ | |
cout << "Nhap ten mon: "; | |
fflush(stdin); | |
getline(cin, mang[i].ten); | |
cout << "Nhap gia: "; | |
cin >> mang[i].gia; | |
mang[i].stt = i; | |
f << mang[i].stt << " " << mang[i].ten << "\t" << mang[i].gia << endl; | |
} | |
f.close(); | |
} | |
else if (a == 2) | |
{ | |
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].stt = i; | |
f << mang[i].stt << " " << mang[i].ten << "\t" << mang[i].gia << endl; | |
} | |
f.close(); | |
} | |
} | |
void chonmon() | |
{ | |
//doc so thu tu stt_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 << khachhang; | |
f.close(); | |
int sttmon; | |
int somoncangoi; | |
string xuatten = "Ten mon"; | |
int xuatstt = 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 << xuatstt << "\t" << xuatten << "\t" << xuatgia << endl; | |
f >> xuatstt >> xuatten >> xuatgia; | |
mang[i].stt = xuatstt; | |
mang[i].ten = xuatten; | |
mang[i].gia = xuatgia; | |
i++; | |
} | |
f.close(); | |
char buffer[33]; | |
itoa(khachhang, buffer, 10); | |
string stt_donhang(buffer); | |
if (khachhang<10) | |
f.open("000" + stt_donhang + ".txt", ios::out); | |
else if (khachhang <100) | |
f.open("00" + stt_donhang + ".txt", ios::out); | |
else if (khachhang <1000) | |
f.open("0" + stt_donhang + ".txt", ios::out); | |
else | |
f.open(stt_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 stt: "; | |
cin >> sttmon; | |
f << i + 1 << "\t" << mang[sttmon].ten << "\t" << mang[sttmon].gia << endl; | |
} | |
f.close(); | |
} | |
} | |
void inhoadon() | |
{ | |
int madonhang; | |
int stt = 0; | |
string ten = "Ten"; | |
long gia = 0; | |
long tong = 0; | |
cout << "Nhap ma don hang: "; | |
cin >> madonhang; | |
stringstream sstr; | |
sstr << madonhang; | |
string stt_donhang = sstr.str(); | |
if (madonhang<10) { | |
f.open("000" + stt_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_000" + stt_donhang + ".txt", ios::out); | |
} | |
else if (madonhang <100) { | |
f.open("00" + stt_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_00" + stt_donhang + ".txt", ios::out); | |
} | |
else if (madonhang <1000) { | |
f.open("0" + stt_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_0" + stt_donhang + ".txt", ios::out); | |
} | |
else { | |
f.open(stt_donhang + ".txt", ios::in); | |
f_out.open("Hoadon_" + stt_donhang + ".txt", ios::out); | |
} | |
while (!f.eof()) | |
{ | |
f_out << stt << "\t" << ten << "\t" << gia << endl; | |
tong = tong + gia; | |
f >> stt >> ten >> gia; | |
} | |
f.close(); | |
f_out << "Tong:\t \t" << tong; | |
f_out.close(); | |
cout << "Da in hoa don!" << endl; | |
} | |
int main() | |
{ | |
cout << "Cac tinh nang: " << endl; | |
cout << "\t 1.Nhap menu: " << endl; | |
cout << "\t 2.Chon mon: " << endl; | |
cout << "\t 3.In hoa don: " << endl; | |
cout << "Ban chon: "; | |
cin >> n; | |
switch (n) | |
{ | |
case 1: { | |
nhapmenu(); | |
break; | |
} | |
case 2: { | |
chonmon(); | |
break; | |
} | |
case 3: | |
{ | |
inhoadon(); | |
break; | |
} | |
} | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment