本文共 17582 字,大约阅读时间需要 58 分钟。
已知在汽车零部件生产过程中,需要对生产的零部件进行质量检测,保证生产质量,以便对出现生产质量问题的责任人进行考核,设计一个汽车零部件质检管理程序,该程序应该具有完成如下功能:
(1)能从键盘输入质检信息。 (2)指定质检编号,显示质检信息。 (3)指定生产者,显示质检信息。 (4)指定质检编号,修改质检信息。 (5)指定质检编号,删除质检信息。(1)按照分析、设计、编码、调试、测试的软件过程完成这个应用程序。
(2) 质检信息包括:质检编号、零部件名称、生产者、生产部门、质检结果(合格/不合格)、质量问题(设计缺陷/装配质量/加工质量)、质检员、质检日期。 (3) 为程序设计windows窗口,在该窗口上以按钮的形式为用户提供“菜单”,通过点击各个功能项对应的按钮完成操作。 输入要求: (1)用户可以根据需求,选定相应的操作项目。进入每个操作后,通过窗口的文本框,从键盘输入相应的信息。程序根据用户输入的信息完成相应的处理,实现要求的功能。 (2)能对输入的数据进行简单的校验,例如,质检日期必须是一个合法的日期格式,质检编号是唯一的(一个质检编号对应一次质检的质检信息)。(1)应用程序运行后,要在屏幕上显示一个按钮形式的“菜单”。
(2)要求用户输入数据时,给出清晰、明确的提示信息,包括输入的数据内容、格式以及结束方式等。 (3)在程序完成处理后,要清楚地给出程序的处理结果。例如,在给定质检编号删除质检信息时,如果该质检信息不存在,要提示没能删除,如果删除成功要提示删除成功。(1)在程序中使用链表存储质检信息。
(2)采用模块化程序设计的方法,将程序中的各项功能用函数实现。 提示: (1)使用结构体表示质检信息,一个结点保存一条质检信息。 扩展功能: (1)提供一些统计功能。例如统计生产者质检不合格的次数,统计各种质量问题出现次数。 (2)质检信息从文件读入。 (3)将质检信息保存到文件中。#include#include #include #include typedef struct product { char ID[100]; //质检编号 char producers[20]; //生产者 char name[20]; //零部件名称 char department[20]; //生产部门 char lookjieguo[20]; //质检结果 char lookwenti[20]; //质量问题 char lookers[20]; //质检员 char year[5]; //年 char month[5]; //月 char day[5]; //日 struct product* next;}PRO;LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);//函数声明void add();int existNode(PRO *node);void insertBack(PRO *p);void freeList();PRO* findBack();void query();PRO* findByName(char *ID);PRO* findByProducers(char *producers);void clean();void dispaly();void dispaly(HWND hWnd,PRO *p);void del();void mdy();void output();void input();void tongji();PRO head; //头结点PRO ss;RECT rect,rect2,rect3,rect4,rect5,rect6,rect7,rect8,rect9,rect10,rect11,rect12,rect13;int i,j=0; //循环变量HDC hDC;PAINTSTRUCT paint;HWND hWnd;int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){ head.next=NULL; char *cName = "myWindow";//定义个字符指针表示窗口类的名字 WNDCLASS wc;//定义变量 MSG Msg; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);;//设置窗口背景为白色 wc.hCursor = NULL;//窗口的光标不设置 wc.hIcon = NULL;//窗口图标设置 wc.hInstance = hInstance;//当前程序的句柄,hInstance是由主函数传递 wc.lpfnWndProc = WinProc;//窗口处理过程的窗口函数。 wc.lpszClassName =(LPSTR)cName;//窗口类的名字。 wc.lpszMenuName = NULL;//目录名,不设置 wc.style = CS_HREDRAW | CS_VREDRAW; //窗口类的风格 RegisterClass(&wc);//在系统中注册窗口 hWnd = CreateWindow(cName,TEXT("管理人:软件151何金洋"),WS_OVERLAPPEDWINDOW,50, 20, 800, 600, NULL, NULL, hInstance, NULL) ; ShowWindow(hWnd,nShowCmd);//显示窗口 UpdateWindow(hWnd);//更新窗口 while(GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg);//翻译消息 DispatchMessage(&Msg);//分派消息 } return Msg.message;//程序结束后返回消息}LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam){ //处理消息过程 static HWND btnHwnd ; static HWND inputHwnd ; switch(Msg)//对消息进行判断 { case WM_PAINT: hDC=BeginPaint(hWnd,&paint);//获取设备上下文 rect.top=20;//设置矩形框的属性 rect.right=20; rect.bottom=40; rect.left=90; rect2.top=20; rect2.right=5; rect2.bottom=130; rect2.left=110; rect3.top=20; rect3.right=5; rect3.bottom=130; rect3.left=750; rect4.top=20; rect4.right=0; rect4.bottom=220; rect4.left=110; rect5.top=20; rect5.right=20; rect5.bottom=220; rect5.left=750; rect6.top=20; rect6.right=20; rect6.bottom=310; rect6.left=110; rect7.top=20; rect7.right=20; rect7.bottom=310; rect7.left=750; rect8.top=20; rect8.right=20; rect8.bottom=400; rect8.left=110; rect9.top=20; rect9.right=20; rect9.bottom=400; rect9.left=750; rect10.top=20; rect10.right=20; rect10.bottom=490; rect10.left=110; rect11.top=20; rect11.right=300; rect11.bottom=400; rect11.left=750; rect12.top=20; rect12.right=425; rect12.bottom=400; rect12.left=750; rect13.top=20; rect13.right=550; rect13.bottom=400; rect13.left=750; DrawText(hDC,"文件:",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"质检编号:",-1,&rect2,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"生产者:",-1,&rect3,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"零部件名称:",-1,&rect4,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"生产部门:",-1,&rect5,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"质检结果:",-1,&rect6,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"质量问题:",-1,&rect7,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"质量员:",-1,&rect8,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"质量日期:",-1,&rect9,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"结果:",-1,&rect10,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"年",-1,&rect11,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"月",-1,&rect12,DT_SINGLELINE|DT_CENTER|DT_VCENTER); DrawText(hDC,"日",-1,&rect13,DT_SINGLELINE|DT_CENTER|DT_VCENTER); EndPaint(hWnd,&paint); return 0; case WM_CREATE: //响应窗口的创建事件 //创建按钮 btnHwnd = CreateWindow( TEXT("button"), TEXT("导入"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 50, 380, 60, 30, hWnd, (HMENU)10, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("添加"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 140, 380, 60, 30, hWnd, (HMENU)11, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("查找"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 230, 380, 60, 30, hWnd, (HMENU)12, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("删除"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 320, 380, 60, 30, hWnd, (HMENU)13, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("统计"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 410, 380, 60, 30, hWnd, (HMENU)14, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("修改"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 500, 380, 60, 30, hWnd, (HMENU)15, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; btnHwnd = CreateWindow( TEXT("button"), TEXT("保存"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 590, 380, 60, 30, hWnd, (HMENU)16, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ), NULL ) ; //创建文本框 /*文件框22*/inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_LEFT | ES_MULTILINE , 110, 20,550, 20, hWnd, (HMENU)22, ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; for(i=0;i<4;i++) { inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_LEFT | ES_MULTILINE , 110, 65+45*i, 220, 20, hWnd, (HMENU)(i+1), ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; } for(i=0;i<3;i++) { inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_LEFT | ES_MULTILINE , 440, 65+45*i, 220, 20, hWnd, (HMENU)(i+5), ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; } /*年77*/inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_RIGHT | ES_MULTILINE , 440, 65+45*3, 70, 20, hWnd, (HMENU)77, ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; /*月88*/inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_RIGHT| ES_MULTILINE , 535, 65+45*3, 40, 20, hWnd, (HMENU)88, ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; /*日99*/inputHwnd = CreateWindow( TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |ES_RIGHT | ES_MULTILINE , 600, 65+45*3, 40, 20, hWnd, (HMENU)99, ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; /*大框44*/inputHwnd = CreateWindow( TEXT("edit"), NULL, WS_VSCROLL|WS_CHILD | WS_VISIBLE | WS_BORDER |ES_LEFT | ES_MULTILINE|ES_WANTRETURN, 110, 250, 550, 120, hWnd, (HMENU)44, ((LPCREATESTRUCT) lParam) -> hInstance,NULL ) ; return 0 ; case WM_COMMAND://响应命令 { SetDlgItemText(hWnd,44,NULL); switch(LOWORD(wParam)) { case 10:// 是ID号为11的按钮点击 导入 { input(); break; } case 11:// 是ID号为11的按钮点击 添加 { add(); break; } case 12:// 是ID号为12的按钮点击 查找 { query(); break; } case 13:// 是ID号为12的按钮点击 删除 { del(); break; } case 14:// 是ID号为12的按钮点击 统计 { tongji(); break; } case 15:// 是ID号为12的按钮点击 修改 { mdy(); break; } case 16:// 是ID号为12的按钮点击 保存 { output(); break; } } return 0; } case WM_DESTROY://如果是点击关闭窗口时的消息 PostQuitMessage(0);//退出消息队列 return 0;//返回0,结束函数 } //如果是其余的消息,调用默认消息处理函数,将消息该函数处理并将返回值返回 return DefWindowProc(hWnd,Msg,wParam,lParam);}void tongji() //统计{ PRO *p; int a=0,b=0,c=0,d=0,e=0; char aa[4],bb[4],cc[4],dd[4],ee[4]; char str1[400]="质检信息总数量:"; char str[400]="质检结果不合格数量:"; char str2[40]="质检设计缺陷问题数量:"; char str3[40]="质检装配质量问题数量:"; char str4[40]="质检加工质量问题数量:"; p=head.next; //p指向第一个结点 while(p!=NULL) { e++; if(strcmp(p->lookjieguo,"不合格")==0) a++; //质检结果不合格 a+1 if(strcmp(p->lookwenti,"设计缺陷")==0) b++; if(strcmp(p->lookwenti,"装配质量")==0) c++; if(strcmp(p->lookwenti,"加工质量")==0) d++; p=p->next; } itoa(a, aa, 10); itoa(b, bb, 10); itoa(c, cc, 10); itoa(d, dd, 10); itoa(e, ee, 10); strcat(str1,ee); strcat(str1,"\r\n"); strcat(str1,str); strcat(str1,aa); strcat(str1,"\r\n"); strcat(str1,str2); strcat(str1,bb); strcat(str1,"\r\n"); strcat(str1,str3); strcat(str1,cc); strcat(str1,"\r\n"); strcat(str1,str4); strcat(str1,dd); SetDlgItemText(hWnd,44,str1);}void input(){ FILE *fp; PRO *p; int count; char filename[20]; GetDlgItemText(hWnd,22,filename,sizeof(filename)/sizeof(char)); fp=fopen(filename,"r"); if(fp==NULL) { SetDlgItemText(hWnd,44,"文件打开失败!"); return; } while(!feof(fp)) { p=(PRO*)malloc(sizeof(PRO)); count=fscanf(fp,"%10s%10s%10s%10s%10s%10s%10s%5s%5s%5s",p->ID,p->lookers,p->lookjieguo,p->lookwenti,p->producers,p->name,p->department ,p->year,p->month,p->day); if(count<10) { free(p); break; } if(existNode(p)) { SetDlgItemText(hWnd,44,"存在相同质检信息"); free(p); } else { insertBack(p); SetDlgItemText(hWnd,44,"导入成功"); } } fclose(fp); SetDlgItemText(hWnd,44,"导入成功"); return;}void output(){ FILE *fp; PRO *p; char filename[20]; GetDlgItemText(hWnd,22,filename,sizeof(filename)/sizeof(char)); fp=fopen(filename,"w"); if(fp==NULL) { SetDlgItemText(hWnd,44,"文件打开失败"); return; } p=head.next; /*p指向第一个结点*/ while(p!=NULL) { fprintf(fp,"%10s%10s%10s%10s%10s%10s%10s%5s%5s%5s\n",p->ID,p->lookers,p->lookjieguo,p->lookwenti,p->producers,p->name,p->department,p->year,p->month,p->day); p=p->next; } SetDlgItemText(hWnd,44,"保存成功!"); fclose(fp); return;}void mdy(){ PRO *p,temp; GetDlgItemText(hWnd,1,temp.ID,sizeof(temp.ID)/sizeof(char)); GetDlgItemText(hWnd,2,temp.name,sizeof(temp.name)/sizeof(char)); GetDlgItemText(hWnd,3,temp.lookjieguo,sizeof(temp.lookjieguo)/sizeof(char)); GetDlgItemText(hWnd,4,temp.lookers,sizeof(temp.lookers)/sizeof(char)); GetDlgItemText(hWnd,5,temp.producers,sizeof(temp.producers)/sizeof(char)); GetDlgItemText(hWnd,6,temp.department,sizeof(temp.department)/sizeof(char)); GetDlgItemText(hWnd,7,temp.lookwenti,sizeof(temp.lookwenti)/sizeof(char)); GetDlgItemText(hWnd,77,temp.year,sizeof(temp.year)/sizeof(char)); GetDlgItemText(hWnd,88,temp.month,sizeof(temp.month)/sizeof(char)); GetDlgItemText(hWnd,99,temp.day,sizeof(temp.day)/sizeof(char)); p=findByName(temp.ID); //查找NO对应的结点地址 strcpy(p->ID,temp.ID); strcpy(p->name,temp.name); strcpy(p->lookjieguo,temp.lookjieguo); strcpy(p->lookers,temp.lookers); strcpy(p->producers,temp.producers); strcpy(p->department,temp.department); strcpy(p->lookwenti,temp.lookwenti); strcpy(p->year,p->year); strcpy(p->month,p->month); strcpy(p->day,p->day); SetDlgItemText(hWnd,44,"修改成功!"); clean();}void query(){ PRO *p; char ID[20]; char producers[20]; GetDlgItemText(hWnd,1,ID,sizeof(ID)/sizeof(char)); GetDlgItemText(hWnd,5,producers,sizeof(producers)/sizeof(char)); p=findByName(ID); //查找 if(strcmp(ID,"")!=0) { if(p==NULL) { SetDlgItemText(hWnd,44,"质检编号不存在"); } else { dispaly(hWnd,p); return; } } if(strcmp(producers,"")!=0) { p=findByProducers(producers); if(p==NULL) { SetDlgItemText(hWnd,44,"生产者不存在"); } else { dispaly(hWnd,p); } }}void del() //删除{ PRO *p,*pre; char ID[20]; GetDlgItemText(hWnd,1,ID,sizeof(ID)/sizeof(char)); pre=&head; //pre指向头结点 p=head.next; //p指向第一个结点 while(p!=NULL) { if(strcmp(p->ID,ID)==0) break; pre=pre->next; //p pre指向下一个结点 pre在p之前 p=p->next; } if(p!=NULL) //如果找到 { pre->next=p->next; //将p所指向的结点从链表删除 free(p); clean(); SetDlgItemText(hWnd,44,"删除成功"); return; } else { SetDlgItemText(hWnd,44,"编号不存在,没能删除"); } clean(); return;}void add(){ int d1,d2,d3; //控制日期的变量 PRO *p; p=(PRO *)malloc(sizeof(PRO)); /*新建结点*/ if(p==NULL) { SetDlgItemText(hWnd,44,"动态内存分配失败!"); return; } ZeroMemory(p->ID,sizeof(p->ID)); GetDlgItemText(hWnd,1,p->ID,sizeof(p->ID)/sizeof(char)); GetDlgItemText(hWnd,2,p->name,sizeof(p->name)/sizeof(char)); GetDlgItemText(hWnd,3,p->lookjieguo,sizeof(p->lookjieguo)/sizeof(char)); GetDlgItemText(hWnd,4,p->lookers,sizeof(p->lookers)/sizeof(char)); GetDlgItemText(hWnd,5,p->producers,sizeof(p->producers)/sizeof(char)); GetDlgItemText(hWnd,6,p->department,sizeof(p->department)/sizeof(char)); GetDlgItemText(hWnd,7,p->lookwenti,sizeof(p->lookwenti)/sizeof(char)); GetDlgItemText(hWnd,77,p->year,sizeof(p->year)/sizeof(char)); GetDlgItemText(hWnd,88,p->month,sizeof(p->month)/sizeof(char)); GetDlgItemText(hWnd,99,p->day,sizeof(p->day)/sizeof(char)); d1 = atoi(p->year); d2 = atoi(p->month); d3 = atoi(p->day); if(d1>2016||d1<0) { SetDlgItemText(hWnd,44,"年份错误,请重新输出"); return; } if(d2>12||d2<1) { SetDlgItemText(hWnd,44,"月份错误,请重新输出"); return; } /*日期合法性检验*/ if(d2==4||d2==6||d2==9||d2==11) { if(d3<1||d3>30) { SetDlgItemText(hWnd,44,"日份错误,请重新输出"); return; } } if(d2==1||d2==3||d2==5||d2==7||d2==8||d2==10||d2==12) { if(d3<1||d3>31) { SetDlgItemText(hWnd,44,"日份错误,请重新输出"); return; } } if(d2==2) { if(((d1%4==0)&&(d1%100!=0))||(d1%400==0)) { if(d3<1&&d3>29) { SetDlgItemText(hWnd,44,"日份错误,请重新输出"); return; } } } /**/ if(existNode(p)) { SetDlgItemText(hWnd,44,"存在相同的质检编号"); } else { insertBack(p); //在链表后面插入一个结点 SetDlgItemText(hWnd,44,"添加成功!"); } clean(); return;}// ZeroMemory(ss.ID,sizeof(ss.ID)); //获取文本框中内容 //GetDlgItemText(hWnd,2,ss.ID,sizeof(ss.ID)/sizeof(char));/*函数功能:判断参数表示的产品信息结点是否在链表中已经存在人口参数:node表示产品信息的结点 返回值:若找到返回1,否则返回0*/int existNode(PRO *node){ PRO *p; p=head.next; //p指向第一个结点 while(p!=NULL) //当p不为NULL { if(strcmp(p->ID,node->ID)==0) return 1; p=p->next; //p指向下一个结点 } return 0;}/*函数功能:查找尾结点的地址返回值:存放尾结点的地址*/PRO* findBack(){ PRO *p; p=&head; while(p->next!=NULL) { p=p->next; //p指向下一个结点 } return p;}/*函数功能:使用尾插法在链表后面插入一个结点人口参数:p为待插入的结点地址*/void insertBack(PRO *p){ PRO *tail; tail=findBack(); tail->next=p; p->next=NULL; return;}/*函数功能:释放链表中所有存放产品信息的结点*/void freeList(){ PRO *p; p=head.next; //p指向第一个结点 while(p!=NULL) //如果p不为NULL { head.next=p->next; //保存p的下一个结点的地址 free(p); //释放p指向的存储单元 p=head.next; //将p指向下一个结点 } return;}/*函数功能:根据姓名查找存放通讯录信息结点的地址人口参数:ID为质检编号返回值:若找到,返回存放质检信息结点的地址,否则返回NULL*/PRO* findByName(char *ID){ PRO *p; p=head.next; while(p!=NULL) { if(strcmp(p->ID,ID)==0) break; p=p->next; //指向下个结点 } return p;}PRO* findByProducers(char *producers){ PRO *p; p=head.next; while(p!=NULL) { if(strcmp(p->producers,producers)==0) break; p=p->next; //指向下个结点 } return p;}void clean(){ SetDlgItemText(hWnd,1,NULL);//在文本框中显示 SetDlgItemText(hWnd,2,NULL); SetDlgItemText(hWnd,3,NULL); SetDlgItemText(hWnd,4,NULL); SetDlgItemText(hWnd,5,NULL); SetDlgItemText(hWnd,6,NULL); SetDlgItemText(hWnd,7,NULL); SetDlgItemText(hWnd,77,NULL); SetDlgItemText(hWnd,88,NULL); SetDlgItemText(hWnd,99,NULL);}void dispaly(HWND hWnd,PRO *p) //显示{ SetDlgItemText(hWnd,1,p->ID);//在文本框中显示 SetDlgItemText(hWnd,2,p->name); SetDlgItemText(hWnd,3,p->lookjieguo); SetDlgItemText(hWnd,4,p->lookers); SetDlgItemText(hWnd,5,p->producers); SetDlgItemText(hWnd,6,p->department); SetDlgItemText(hWnd,7,p->lookwenti); SetDlgItemText(hWnd,77,p->year); SetDlgItemText(hWnd,88,p->month); SetDlgItemText(hWnd,99,p->day);}
转载地址:http://bjjpx.baihongyu.com/