人人范文网 范文大全

c语言课程设计(食堂刷卡)

发布时间:2020-03-02 11:04:20 来源:范文大全 收藏本文 下载本文 手机版

#include \"stdafx.h\" #include #include #include #include #include #include #include #define MAX 100 #define Stu struct student int Num; CComPtr pVoice; HRESULT hr; Stu { char name[10]; //学生姓名

int kh; //学生卡号

char bm[33]; //学生卡编码

float cash; //金额

float xf; //消费 }; void menu(); void _10_2(Stu*); void Register(Stu*); void CZ(); void XF(); void Award(); void Tj(); int InitVoice() { CComPtr pEnum; CComPtr pVoiceToken; int i; ::CoInitialize(NULL); if(FAILED(hr=SpEnumTokens(SPCAT_VOICES,L\"Language=804\",NULL,&pEnum)))

return 0; for(i=0;i

{

pVoiceToken.Release();

pEnum->Next(1, &pVoiceToken, NULL); } if(FAILED(hr=pVoice.CoCreateInstance(CLSID_SpVoice)))

return 0; if(FAILED(hr = pVoice->SetVoice(pVoiceToken)))

return 0; return 1; } void ReleaseVoice() { pVoice.Release(); CoUninitialize(); } void Speak(char *Txt) { CSpDynamicString s(Txt); pVoice->Speak(s,0,0); } void main()

{ menu(); } void menu() //主菜单 { Stu strStu; char ch; loop:

system(\"cls\");

printf(\" *********************************\\n\");

printf(\" * 1: 卡登记 * \\n\");

printf(\" * 2: 饭卡充值 * \\n\");

printf(\" * 3: 食堂消费 * \\n\");

printf(\" * 4: 有奖消费 * \\n\");

printf(\" * 5: 财务统计 * \\n\");

printf(\" * 6: 退出 * \\n\");

printf(\" *********************************\\n\");

printf(\" \\n\");

printf(\" 请选择输入选项[1\\2\\3\\4\\5\\6]:>\"); if(!InitVoice()) return ; Speak(\"请 选 择 输 入 选 项\"); ReleaseVoice();

while(ch=getch())

{

switch(ch)

{

case \'1\': Register(&strStu);goto loop;

case \'2\': CZ();

case \'3\': XF();

case \'4\': Award();

case \'5\': Tj();

case \'6\': exit(0);

}

} goto loop; } void Register(Stu *a) //卡登记 { FILE *fp; system(\"cls\"); a->xf=0; printf(\"**********卡登记***************\\n\"); if(!InitVoice())

return ; Speak(\"卡登记\"); ReleaseVoice(); printf(\"输入姓名:\"); if(!InitVoice())

return ; Speak(\"输入姓名\"); ReleaseVoice(); scanf(\"%s\",a->name); printf(\"输入卡号:\"); if(!InitVoice())

return ; Speak(\"输入卡号\"); ReleaseVoice();

scanf(\"%d\",&a->kh); printf(\"输入初始金额:\"); if(!InitVoice())

return ; Speak(\"输入初始金额\"); ReleaseVoice(); scanf(\"%f\",&a->cash); _10_2(a); printf(\"你的二进制卡编码是:%s\",a->bm); if(!InitVoice())

return ; Speak(\"你的二进制卡编码是\"); ReleaseVoice(); if(!InitVoice())

return ; Speak(a->bm); ReleaseVoice(); if((fp=fopen(\"stu.txt\",\"a\"))==NULL) {

printf(\"ERROR\\n\");

exit(0); } fprintf(fp,\"%s\\t%d\\t%s\\t%.2f\\t%.2f\",a->name,a->kh,a->bm,a->cash,a->xf); fputc(\'\\n\',fp); fclose(fp); } void _10_2(Stu*a) //10 进制转2进制 { int n,i,t=1; n=a->kh; getchar(); for(a->bm[0]=\'1\',i=1;n;i++) {

a->bm[i]=n%2+48;

n/=2;

if(a->bm[i]==\'1\') t++; } if(t%2==1) a->bm[31]=\'1\'; else a->bm[31]=\'0\'; for(i;i

a->bm[i]=\'0\'; a->bm[32]=\'\\0\'; } void CZ() //饭卡充值 { FILE *fp; char bm[33]; Stu strshare[MAX]; float cash; int nNum=0,i; system(\"cls\"); printf(\"**************饭卡充值**************\\n\"); if(!InitVoice())

return ; Speak(\"饭卡充值\"); ReleaseVoice(); printf(\"请输入你的卡编码:\"); if(!InitVoice())

return ; Speak(\"请输入你的卡编码\"); ReleaseVoice(); gets(bm); if((fp=fopen(\"stu.txt\",\"r\"))==NULL) {

printf(\"ERROR\\n\");

exit(0); } while(!feof(fp)) {

fscanf(fp,\"%s%*c%d%*c%s%*c%f%*c%f%*c\",strshare[nNum].name,&strshare[nNum].kh,strshare[nNum].bm,&strshare[nNum].cash,&strshare[nNum].xf);

nNum++; } nNum--; fclose(fp); for(i=0;i

if(strcmp(strshare[i].bm,bm)==0)

{

printf(\"请输入充值金额:\"); if(!InitVoice()) return ; Speak(\"请输入充值金额\"); ReleaseVoice();

scanf(\"%f\",&cash);

strshare[i].cash+=cash; if((fp=fopen(\"stu.txt\",\"w\"))==NULL)

{

printf(\"ERROR\\n\"); exit(0);

}

for(i=0;i

fprintf(fp,\"%s\\t%d\\t%s\\t%.2f\\t%.2f\\n\",strshare[i].name,strshare[i].kh,strshare[i].bm,strshare[i].cash,strshare[i].xf);

fclose(fp);

menu();

} } if(i>=nNum) {

printf(\"你尚未登记!\\n\"); if(!InitVoice())

return ; Speak(\"你尚未登记\"); ReleaseVoice(); menu(); } menu(); } void XF() // 卡消费 { FILE *fp; char bm[33]; Stu strshare[MAX];

float xf; int nNum=0,i; system(\"cls\"); printf(\"**************食堂消费**************\\n\"); if(!InitVoice())

return ; Speak(\"食堂消费\"); ReleaseVoice(); printf(\"请输入你的卡编码:\"); if(!InitVoice())

return ; Speak(\"请输入你的卡编码\"); ReleaseVoice(); gets(bm); if((fp=fopen(\"stu.txt\",\"r\"))==NULL) {

printf(\"ERROR\\n\");

exit(0); } while(!feof(fp)) {

fscanf(fp,\"%s%*c%d%*c%s%*c%f%*c%f%*c\",strshare[nNum].name,&strshare[nNum].kh,strshare[nNum].bm,&strshare[nNum].cash,&strshare[nNum].xf);

nNum++; } nNum--; fclose(fp); for(i=0;i

if(strcmp(strshare[i].bm,bm)==0)

{

printf(\"请输入消费金额:\"); if(!InitVoice()) return ; Speak(\"请输入消费金额\"); ReleaseVoice();

scanf(\"%f\",&xf);

strshare[i].xf+=xf;

strshare[i].cash-=strshare[i].xf; if((fp=fopen(\"stu.txt\",\"w\"))==NULL)

{

printf(\"ERROR\\n\"); exit(0);

}

for(i=0;i

fprintf(fp,\"%s\\t%d\\t%s\\t%.2f\\t%.2f\\n\",strshare[i].name,strshare[i].kh,strshare[i].bm,strshare[i].cash,strshare[i].xf);

fclose(fp);

menu();

} } if(i>=nNum) {

printf(\"你尚未登记!\\n\"); if(!InitVoice()) return ;

Speak(\"你尚未登记\"); ReleaseVoice();

menu(); } menu(); } void Award() //有奖消费 { FILE *fp; Stu strshare[MAX],*p[MAX],*temp=NULL; int nNum=0,i,j; system(\"cls\"); printf(\"********有奖消费****************\\n\"); if(!InitVoice()) return ; Speak(\"有奖消费\"); ReleaseVoice(); if((fp=fopen(\"stu.txt\",\"r\"))==NULL) {

printf(\"ERROR!\\n\");

exit(0); } while(!feof(fp)) {

fscanf(fp,\"%s%*c%d%*c%s%*c%f%*c%f%*c\",strshare[nNum].name,&strshare[nNum].kh,strshare[nNum].bm,&strshare[nNum].cash,&strshare[nNum].xf);

nNum++; } nNum--; fclose(fp); for(i=0;i

p[i]=&strshare[i]; for(i=0;i

for(j=0;j

if(p[j]->xfxf)

{

temp=p[j];

p[j]=p[j+1];

p[j+1]=temp;

} for(i=0;i

p[i]->cash+=(p[i]->xf)/100*5; printf(\"今日大胃王:\\n\"); if(!InitVoice()) return ; Speak(\"今日大胃王\"); ReleaseVoice(); for(i=0;i

printf(\"%s\\t%d\\t%s\\t%.2f\\t%.2f\\n\",p[i]->name,p[i]->kh,p[i]->bm,p[i]->cash,p[i]->xf); if((fp=fopen(\"stu.txt\",\"w\"))==NULL) {

printf(\"ERROR!\\n\");

exit(0); } for(i=0;i

fprintf(fp,\"%s\\t%d\\t%s\\t%.2f\\t%.2f\\n\",strshare[i].name,strshare[i].kh,strshare[i].bm,strshare[i].cash,strshare[i].xf); fclose(fp); menu(); } void Tj() //财务统计 { FILE *fp; Stu strshare[MAX]; int nNum=0,i; float total=0,ave; system(\"cls\"); printf(\"*******校方统计****************\\n\"); if(!InitVoice()) return ; Speak(\"校方统计\"); ReleaseVoice(); if((fp=fopen(\"stu.txt\",\"r\"))==NULL) {

printf(\"ERROR!\\n\");

exit(0); } while(!feof(fp)) {

fscanf(fp,\"%s%*c%d%*c%s%*c%f%*c%f%*c\",strshare[nNum].name,&strshare[nNum].kh,strshare[nNum].bm,&strshare[nNum].cash,&strshare[nNum].xf);

nNum++; } nNum--; fclose(fp); for(i=0;i

total+=strshare[i].xf; ave=total/nNum; printf(\"今日消费总额:%.2f\\n学生平均消费水平:%.2f\\n\",total,ave); }

C语言课程设计

C语言课程设计

C语言课程设计

C语言课程设计

C语言课程设计

C语言课程设计

C语言课程设计

C语言课程设计黑白棋

课程设计报告 C语言

C语言课程设计程序

c语言课程设计(食堂刷卡)
《c语言课程设计(食堂刷卡).doc》
将本文的Word文档下载到电脑,方便编辑。
推荐度:
点击下载文档
点击下载本文文档