按你要求随便写的一个 不知道合要求不
#include <iostream>
#include <iomanip>
#include <string>
using namespace std
// 打印菜单
void printMenu(char a[][20],float b[])
// 打印选择结果
void printChoseRes(char Mname[][20],float Mprice[],int Mfarray[])
static int number=0 //记录点菜个数
int main()
{
// 菜单
char Menu[][20]={
{"土豆肉丝"},
{"千张肉丝"},
{"农家小炒肉"},
{"麻辣鸡丁"},
{"宫爆鸡丁"},
{"鱼香肉丝"},
{"油淋茄子"},
{"清炒小白菜"},
}
// 价格
float Price[]={5,6,7,6.5,5.5,4.5,5,4}
int farray[20] // 记录用户选择
int index=0 // 标记farray的位置
int flag // 标记用户选择
float sumPrice=0 //记录总价
printMenu(Menu,Price)
while(1)
{
cout << "请您点菜,或者按0退出:"
cin >> flag
if(flag==0)
break
else
{
farray[index++]=flag
sumPrice+=Price[flag-1]
}
number++
}
cout << endl
printChoseRes(Menu,Price,farray)
cout << "合计:" << "¥" << sumPrice << "元" << endl
cout << endl
return 0
}
// 打印菜单
void printMenu(char a[][20],float b[])
{
int i
for(i=0i<8i++)
cout << left << setw(2) << i+1 << " "
<< setw(10) 者凳<< a[i] << " "
<< "¥" << setw(10) << b[i] <<endl
cout << setw(2) << i+1 << " "
<< setw(10) << "退晌告出" << endl
cout << endl
}
// 打印选择结果
void printChoseRes(char Mname[][20],float Mprice[],int Mfarray[])
{
for(int j=0j<numberj++)
{
int i
i=Mfarray[j]
cout << left << setw(10) << Mname[i-1] << " "
<< "¥" << 宴嫌明setw(10) << Mprice[i-1] <<endl
}
}
模块,流程....然后
依照段型纤规划,
后台mssql2000或者msaccess做数据库,建些握仿表,
前台用vb.
窗体如图
属性设置:
form1-caption:顾客点菜单
list1:multiselect=2\style=0
list2:multiselect=0\style=1
command1:caption=添加
command2=caption=删除
lable1:caption=饭店菜谱
lable2:caption=顾客点菜
代码:
Private
Sub
Form_Load()
List1.AddItem
"*******"
'以下格式相同(*表示菜名)
End
Sub
Private
Sub
Command1_Click()
Dim
i%
'定义循环变量
For
i
=
List1.ListCount
-
1
To
0
Step
-1
If
List1.Selected(i)
Then
'判断是否被选中
List2.AddItem
List1.List(i)
'在list2中租山添加list1中被选中的
List1.RemoveItem
i
End
If
Next
i
End
Sub
Private
Sub
Command2_Click()
Dim
i%
For
i
=
List2.ListCount
-
1
To
0
Step
-1
If
List2.Selected(i)
Then
List1.AddItem
List2.List(i)
List2.RemoveItem
i
'从List2中删除此选中项
End
If
Next
i
End
Sub
// 下面是前期的点餐系统的基础数据维护,其它功能运团你可以自己尝试写,如果遇到什么问题可以提出来追问喔,相信你可以解决的(我怕代码太多提交会受字数限制)。
// mm.h 头文件#include<stdio.h>
#include<stdlib.h>
#define MENU_NUM_MAX 100 // 假设有100种菜式
#define LEN sizeof(struct MenuInfo)
struct MenuInfo
{
int ID
char MenuName[20]
float price
}Menu[MENU_NUM_MAX]
/* 基础数据维护 */
void AddMenu()
{
FILE *fp
int menu_num
printf("\t\t 你要添加多少种菜?:")
scanf("%d",&menu_num)
for(int i=0i<menu_numi++)
{
printf("\n") // added this line
printf("\t\t请输入ID:")
scanf("%d",&Menu[i].ID)
printf("\t\t请输入菜名毁启:")
scanf("%s",Menu[i].MenuName)
printf("\t\t请输入[%s]菜的价格:",Menu[i].MenuName)
Menu[i].price=0.0f //initial float price
scanf("%f",&Menu[i].price)
fflush(stdin)
}
if((fp=fopen("MenuInfo.dat","ab"))==NULL) // open binary file
{
printf("Can't open file\n")
exit(1)
}
for(int j=0j<menu_numj++)
{
if(fwrite(&Menu[j],LEN,1,fp)!=1) //writing data to binary file
printf("Error writing file.\n")
}
fclose(fp) // close file point
}
void DisplayMenuInfo()
{
纤悄如FILE *fp
printf("\n\t\tID 菜名\t\t价格\n") // column headings
if((fp=fopen("MenuInfo.dat","rb"))==NULL) // open binary file
{
printf("Can't open file\n")
exit(1)
}
int i=0
do
{
fseek(fp,i*LEN,SEEK_SET) // move file head location
if(fread(&Menu[i],LEN,1,fp)) // read data save to structure variable
{
printf("\t\t%d %5s\t\t%5.1f元\n",Menu[i].ID,Menu[i].MenuName,Menu[i].price)
i++
}
}while(!feof(fp))
fclose(fp)
}
void DeleteToMenu()
{
FILE *fp
int MenuID
int todelete=-1
int i=0
printf("请输入要删除的菜名的ID:")
scanf("%d",&MenuID)
/* load or reload the file and check that record with that ID exists */
if((fp=fopen("MenuInfo.dat","rb"))==NULL) // open binary file
{
printf("Can't open file\n")
exit(1)
}
do
{
fseek(fp,i*LEN,SEEK_SET) // move file head location
if(fread(&Menu[i],LEN,1,fp))
{
if (Menu[i].ID==MenuID) todelete=i
i++
}
}while(!feof(fp))
fclose(fp)
if (todelete==-1)
{
printf("A menu with that ID doesn't exist\n")
}
else
{
/* write records back to file excluding one to be deleted */
if((fp=fopen("MenuInfo.dat","wb"))==NULL) // open binary file
{
printf("Can't open file\n")
exit(1)
}
for(int j=0j<ij++)
{
if (j==todelete) continue /* skip record to be deleted */
if(fwrite(&Menu[j],LEN,1,fp)!=1) //writing data to binary file
printf("Error writing file.\n")
}
fclose(fp) // close file point
}
}
void FindMenu()
{
FILE *fp
int MenuID
bool find_mark=false
printf("\n\t\t请输入你要查找的菜名ID:")
scanf("%d",&MenuID)
printf("\n\t\tID 菜名\t\t价格\n") // column headings
if((fp=fopen("MenuInfo.dat","rb"))==NULL) // open binary file
{
printf("Can't open file\n")
exit(1)
}
int i=0
do
{
fseek(fp,i*LEN,SEEK_SET) // move file head location
fread(&Menu[i],LEN,1,fp) // read data save to structure variable
if(Menu[i].ID==MenuID)
{
printf("\t\t%d %5s\t\t%5.1f元\n",Menu[i].ID,Menu[i].MenuName,Menu[i].price)
find_mark=true
break
}
i++
}while(!feof(fp))
if(!find_mark) printf("\n\t 尊敬的客户:我们餐厅没有你要点的菜喔,你可以试试我们的招牌菜啊^-^.\n")
fclose(fp)
}
/* 基础数据维护完毕 */
// sc.cpp主文件
#include <stdio.h>
#include <stdlib.h>
#include "mm.h"
void main(void)
{
//AddMenu()
//DisplayMenuInfo()
//FindMenu()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)