Skip to content

Instantly share code, notes, and snippets.

@toanalien
Created August 15, 2015 17:59
Show Gist options
  • Save toanalien/3ffaf7b8f000b4530f90 to your computer and use it in GitHub Desktop.
Save toanalien/3ffaf7b8f000b4530f90 to your computer and use it in GitHub Desktop.
cafe
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
ifstream cinFile;
ofstream coutFile;
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 << "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;
coutFile << mang[i].stt << " " << mang[i].ten << "\t" << mang[i].gia << endl;
}
coutFile.close();
}
void chonmon()
{
//doc so thu tu khach hang
int khachhang;
cinFile.open("khachhang.txt");
while (!cinFile.eof())
{
cinFile >> khachhang;
}
cinFile.close();
coutFile.open("khachhang.txt", ios::out | ios::app);
coutFile << khachhang + 1 << endl;
coutFile.close();
//chon mon
int sttmon;
int somoncangoi;
string xuatten = "Ten mon";
int xuatstt = 0;
long xuatgia = 0;
cout << "Menu gom co: \n";
cinFile.open("menu.txt");
int i = 1;
while (!cinFile.eof())
{
cout << xuatstt << "\t" << xuatten << "\t" << xuatgia << endl;
cinFile >> xuatstt >> xuatten >> xuatgia;
mang[i].stt = xuatstt;
mang[i].ten = xuatten;
mang[i].gia = xuatgia;
i++;
}
cinFile.close();
stringstream sstr;
sstr << khachhang;
string stt_donhang = sstr.str();
if (khachhang<10)
coutFile.open("000" + stt_donhang + ".txt");
else if (khachhang <100)
coutFile.open("00" + stt_donhang + ".txt");
else if (khachhang <1000)
coutFile.open("0" + stt_donhang + ".txt");
else coutFile.open(stt_donhang + ".txt");
cout << "So mon ban muon goi la: ";
cin >> somoncangoi;
for (int i = 0; i<somoncangoi; i++)
{
cout << "Ban chon mon co stt: ";
cin >> sttmon;
coutFile << i + 1 << "\t" << mang[sttmon].ten << "\t" << mang[sttmon].gia << endl;
}
coutFile.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) {
cinFile.open("000" + stt_donhang + ".txt", ios::in);
coutFile.open("Hoadon_000" + stt_donhang + ".txt", ios::out);
}
else if (madonhang <100) {
cinFile.open("00" + stt_donhang + ".txt", ios::in);
coutFile.open("Hoadon_00" + stt_donhang + ".txt", ios::out);
}
else if (madonhang <1000) {
cinFile.open("0" + stt_donhang + ".txt", ios::in);
coutFile.open("Hoadon_0" + stt_donhang + ".txt", ios::out);
}
else {
cinFile.open(stt_donhang + ".txt", ios::in);
coutFile.open("Hoadon_" + stt_donhang + ".txt", ios::out);
}
while (!cinFile.eof())
{
coutFile << stt << "\t" << ten << "\t" << gia << endl;
tong = tong + gia;
cinFile >> stt >> ten >> gia;
}
cinFile.close();
coutFile << "Tong:\t \t" << tong;
coutFile.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