




已阅读5页,还剩25页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西北农林科技大学信息工程学院数据结构与c语言综合训练实习报告题 目: 汽车租借公司的管理 学 号2010012843姓 名陈金亚专业班级计算机科学与技术102班指导教师蔡骋完成日期2011年7月8日7月17日目 录一、综合训练目的与要求3二、综合训练任务描述3三、算法设计3四、详细设计说明12五、调试与测试13六、实习日志15七、实习总结15八、附录:核心代码清单1530一、综合训练目的与要求本综合训练是软件工程专业重要的实践性环节之一,是在学生学习完算法分析课程后进行的综合练习。本课综合训练的目的和任务:1. 巩固和加深学生对算法分析课程基本知识的理解和掌握;2. 培养利用算法知识解决实际问题的能力;3. 掌握利用程序设计语言进行算法程序的开发、调试、测试的能力;4. 掌握书写算法设计说明文档的能力;5. 提高综合运用算法、程序设计语言、数据结构知识的能力。6. 应用线性数据结构存储信息,并能够应用上面的基本操作实现事务管理。二、综合训练任务描述设计数据结构及算法完成某个汽车租借公司日常工作的组织与管理。该管理系统的基本管理对象为汽车,每台汽车用一个license number进行唯一标识。每个汽车存在三种可能状态:可以租借(available for rent)已借(rented)修理中(in repair)其中在available队列中汽车应该依据汽车行驶过的路程进行排序,行驶路程最少的汽车排在最前面。在rented队列中的汽车应依据其预期返回时间进行排序,排在最前的应是预期最早返回的汽车。三、算法设计(1) 文字描述用三个链表组织三种状态的汽车, 能够实现租借的日常事务:引入新车,租借,收费,修理等。租借收费应根据汽车行驶的路程及借去的时间综合计算得出,路程收费标准如下:低于100km收费20.00元, 100km以外的路程枚km收费0.15元, 汽车根据行驶的路程定期进行维护, 还需实现辅助操作:汽车查询,打印全部信息,计算并打印收入、成本及收益, 主要集中在链表的基本操作上管理系统应有完整地界面(最好是图形化界面)主要集中在链表的基本操作上,主要是链表的插入、删除、排序,文件导入导出。(2) 框图导出文件保存按车牌查找按车名查找开始退出结束初始化导入文件删除成功,链表操作添加成功,链表操作已修成功,链表操作修理成功,链表操作归还成功,链表操作租赁成功,链表操作输入车辆信息输入车辆信息输入车辆信息输入车辆信息输入车辆信息输入车辆信息打印车辆信息打印收益查看车辆选择车辆查找车辆查看收益删除车辆添加车辆已修车辆修理车辆租赁车辆归还车辆(3) 伪代码struct carrecord/ 汽车记录结构体 int number; char *name; int journey; char *information; int availablerent; int rentedtime; int repairtime; float fee; float earn; float benifit;int lable;tchar way256; ;/ carrecordstruct carnode/节点结构体 carrecord record; carnode *next; carnode *front;/ carnodestruct head/三个链表的结构体 carnode *available; int an; carnode *rented; int ren; carnode *repair; int repn;/ headvoid linkinsert(carnode *head, carnode *node)/链表头插入 node-next = head-next; if(head-next) head-next-front=node; head-next = node; node-front = head;/if/ linkinsertint loadrecord(char *path,carnode *head ,int lable)/文件导入 file *file= fopen(path,rt); fscanf(file,%dn,&num); carnode *cars; for(i=0 ; irecord.name = (char *)malloc(nmax); fscanf(file,%dn,&carsi-record.number); fgets(carsi-record.name,nmax,file); fscanf(file,%dn,&carsi-record.journey); fscanf(file,%dn,&carsi-record.rentedtime); fscanf(file,%dn,&carsi-record.repairtime); fscanf(file,%fn,&carsi-record.fee); fscanf(file,%fn,&carsi-record.earn);fscanf(file,%fn,&carsi-record.benifit); carsi-record.information = (char *)malloc(imax); fgets(carsi-record.information,imax,file);carsi-record.lable = lable+ ;itoa(carsi-record.number, carsi-record.way, 10);strcat(carsi-record.way,.jpg); inkinsert(head,carsi); fclose(file); return num;/ loadrecordvoid putinfile(carnode* head, char *path,int n) /文件导出 file *fp=fopen(path,w); p=head-next; fprintf(fp,%dn,n); while(p) fprintf(fp,%dn%s%dn%dn%dn%.2fn%.2fn%.2fn%s,p-record.number,p-record.name,p-record.journey,p-record.rentedtime,p-record.repairtime,p-record.fee,p-record.earn,p-record.benifit,p-record.information); p=p-next; fclose(fp); / putinfileint node1moveto2(carnode *head1, carnode *head2,int n)/节点转移 p=head1-next; while(p) if(p-record.number=n) break; p=p-next; if(p=null) return 1; else if(p-next=null) p-front-next = p-next; else p-next-front = p-front; p-front-next = p-next; linkinsert(head2,p); return 0;/ node1moveto2carnode* nodesortavailable(carnode *head,int n) /链表递增排序 i=0; head1=(carnode*)malloc(sizeof(carnode); u= head1-next; while(inext; if(p!=null&(q-record.journeyrecord.journey) q=p; if(q-next=null) q-front-next=q-next; else if(q-next) q-front-next=q-next; q-next-front =q-front; linkinsert(head1, q); +i; p=head-next; q=p; q=head; while(q)/删除原链表 u=q; q=q-next; free(u); head= head1;/新链表赋予head free(q); free(p); return head1;/ nodesortavailablecarnode* nodesortrented(carnode *head,int n);/类似nodesortrented()carnode* nodesortrepair(carnode *head,int n); /类似nodesortrented()void rentcar(head &head, int num,int rt);/利用node1moveto2()函数void repaircar(head &head, int num,int rpt) ;/利用node1moveto2()函数void returncar(head &head, int num,int l,int t) ;/利用node1moveto2()函数int returnrepaircar(head &head, int num,float fee) ;/利用node1moveto2()函数int addcar(carnode* head,char*path,char *strnum ,char *name,char *strjourney, char *infor) node=(carnode*)malloc(sizeof(carnode); initnode(node); node-record.name = (char *)malloc(nmax); node-record.information = (char *)malloc(imax);number = atoi(strnum);journey = atoi(strjourney);node-record.number= number;node-record.name = name;node-record.journey = journey;node-record.information = infor;if(number =0 |name=n |journey=0|infor =n )return 1; node-record.rentedtime=0; node-record.repairtime=0; node-record.fee=0; node-record.earn=0;node-record.number,node-record.name,node-record.journey,node-record.rentedtime,node-record.repairtime,node-record.fee,node-record.earn,node-record.information); if(head-next=null) node-next=head-next; head-next =node; node-front = head; else if(head-next!=null) linkinsert(head,node); return 0; /addcarfloat charge(int num, int journey,int t, carnode *p) charge=0; s= journey- p-record.journey; if(sum100) charge=20+(sum-100)*0.15+t*500; p-record.journey=journey; return charge;/ chargefloat benifit(head &head, float &fee, float &earn)/清算总收益 p=head.available-next; if(p) while(p) earn =earn +p-record.earn; fee = fee+ p-record.fee; p=p-next; p=head.rented-next; if(p) while(p) earn =earn +p-record.earn; fee = fee+ p-record.fee; p=p-next; p=head.repair-next; if(p) while(p) earn =earn +p-record.earn; fee = fee+ p-record.fee; p=p-next; ben = earn -fee; return ben;/ benefitvoid findcar(head head, int num) n=0; p=head.available-next; while(p) if(p-record.number=num) n=num; return p; p=p-next; p=head.repair-next; while(p)/同上 p=head.rented-next; while(p)/同上 if(n=0) return 0;/findcarint delcar(head &head,int num)n=0; p=head.available-next; while(p) if(p-record.number=num) n=num; return 0; p=p-next; if(n=0) return 1; p-front-next = p-next; p-next-front =p-front; head.an-; free(p);return 0;/ delcarvoid destroylink(head &head)/摧毁数据 p=head.available; while(p) u=p; p=p-next; free(u); p=head.rented;while(p);/同上 p=head.repair;while(p);/同上 free(p); / destroylinkvoid main_oncommand(hwnd hwnd, int id, hwnd hwndctl, uint codenotify) hwnd hwndcombocars =getdlgitem(hwnd,idc_combocars); hwnd hwndcombosearch =getdlgitem(hwnd,idc_combosearch); switch(id) case idc_lookcar: break; /*省略功能按钮*/ case idc_returncar: break; case idc_benifit: break; case idc_delcar: case id_menuview: /*省略菜单按钮*/ case id_menuquit: enddialog(hwnd, 0); break; default: break; void main_onclose(hwnd hwnd) enddialog(hwnd, 0); (4) 复杂度分析(选作)链表插入删除复杂度均为o(n);链表排序为o(n2)四、详细设计说明用三个链表组织三种状态的汽车, 将头节点设置成为结构体head,三个链表分别为h.available, h.rented, h.repair,是三个链表能够统一起来,链表的操作有初始化通过initcarnode()实现,链表的插入有函数linkinsert(),链表的排序通过插入排序,建立一个新的排序链表,然后将旧的未排序链表删除,将新链表赋予原来的表头,通过nodesort()函数实现,由于三个链表的排序关键字不同,所以设计了nodesortavailable(),nodesortrented (),nodesortrepair()三个函数,对三个链表进行排序。为了能是操作简单一些,我设计的是双向链表,那么删除是就可以直接删除,减少时间的消耗,删除节点的函数是delcar(),代码部分主要就是对双向链表的常规操作。为了使导入数据方便,数据的导入方式为文件导入,三种状态的车辆信息分别放在carsavailable.txt,carsrented.txt,carsrepair.txt里面,打开程序后遍自动导入,导入同时进行排序。同时可以在这三个文件里经行修改管理。图形界面为一个简单的对话框模式,初始化对话的为main_oninitdialog(),对命令经行响应的是main_oncommand()函数,将源代码与图形界面结合后,是程序更人性化,是操作更简单明了。对于图片的展示,由于水平有限,使用windows自带的图片浏览器。五、调试与测试5-1 无图形界面测试(针对代码测试)(堆)调试分为两个部分,第一部分是代码的测试,第二部分是图形界面与代码结合的测试。5-2 图形界面测试5-3 数据文本格式六、实习日志7月8日,进行选题和最后确认,对题目进行思考;7月9日,编写链表部分代码,主要针对链表的插入、删除、排序等;7月10日,加入功能函数,运用链表的操作,实现部分汽车租赁管理功能;7月11日,对功能进行调试和优化,构思图形界面;7月12日,通过网上的视频教程等自学vc+ 6.0,为图形界面设计做准备。同时继续对代码进行debug;7月13日,学习vc+ 6.0,编写小型图形界面熟悉messagebox()等函数;7月14日,学习vc+ 6.0,跟随视频教程学习,运用combobox宏编写小程序;7月15日,设计图形界面,尝试代码和图形的结合;7月16日,在代码和图形结合时,对代码不完善的地方,和不适用图形的部分进行修改和删减,并可以通过图形进行操作,增加了通过车牌和车名进行查找;7月17日,完善图形界面和代码,撰写实习报告。七、实习总结本次实习总共历时10天,培养学生的动手操作能力和创新能力。我在实习中遇到不少问题,其中不乏很多简单的但是被我忽略的错误,导致一个错误很长时间无法解决,却是因为一个初始化问题。同时由于编译器不同,对代码的严谨程度也不同,codeblocks对许多错误能够容忍不报错,而vc+ 6.0就不同了,由于初始的代码实在codeblocks里编写的,所以复制到vc+ 6.0后,修改了很长时间的代码,从中学到不少书本上没有的知识。令人欣慰的是,最终摆脱了黑底白字的命令行,实现图形界面的操作。但是,在学习过程中,并没有真正运用到vc+的特性,只是将代码与图形界面生拉硬拽联系上的,在以后的学习中,还要努力。八、附录:核心代码清单#include stdafx.h#include #include #include resource.h#include maindlg.h#include #include iostream#include shellapi.h#include string.h#include stdlib.h#include stdio.h/*包含的函数*/int addcar(carnode* head,char*path,char *strnum ,char *name,char *strjourney, char *infor);float benifit(head &head, float &fee, float &earn);float charge(int num, int journey,int t, carnode *p);int delcar(head &head,int num);void destroylink(head &head);carnode* findcar(head head, int num);carnode* findcarlable(head head, int i);carnode* findcarname(head head, tchar name256);void initcarrecord(carrecord &record);void initnode(carnode *node);void linkinsert(carnode *head, carnode *node);int loadrecord(char *path,carnode *head ,int lable);void main_onclose(hwnd hwnd);void main_oncommand(hwnd hwnd, int id, hwnd hwndctl, uint codenotify);bool main_oninitdialog(hwnd hwnd, hwnd hwndfocus, lparam lparam);bool winapi main_proc(hwnd hwnd, uint umsg, wparam wparam, lparam lparam);int node1moveto2(carnode *head1, carnode *head2,int n);carnode* nodesortavailable(carnode *head,int n);carnode* nodesortrented(carnode *head,int n);carnode* nodesortrepair(carnode *head,int n);int putinfile(carnode* head, char *path,int n);int rentcar(head &head, int num,int rt);int repaircar(head &head, int num,int rpt);float returncar(head &head, int num,int l,int t);int returnrepaircar(head &head, int num,float fee);/*/*部分核心代码*/void linkinsert(carnode *head, carnode *node)/插入节点node-next = head-next;if(head-next) head-next-front=node;head-next = node;node-front = head;/移动节点int node1moveto2(carnode *head1, carnode *head2,int n) carnode *p;p=head1-next;while(p)if(p-record.number=n) break;p=p-next;if(p=null) return 1;else if(p-next=null) p-front-next = p-next;elsep-next-front = p-front;p-front-next = p-next;linkinsert(head2,p);return 0;/导入文本数据int loadrecord(char *path,carnode *head ,int lable) int num,i;file *file= fopen(path,rt);fscanf(file,%dn,&num);carnode *cars;cars = (carnode*)malloc(num*sizeof(carnode*);for(i=0 ; inum; i+)carsi=(carnode*)malloc(sizeof(carnode);initnode(carsi);for(i=0 ; irecord.name = (char *)malloc(nmax);fscanf(file,%dn,&carsi-record.number);fgets(carsi-record.name,nmax,file);fscanf(file,%sn,&carsi-record.name);fscanf(file,%dn,&carsi-record.journey);fscanf(file,%dn,&carsi-record.rentedtime);fscanf(file,%dn,&carsi-record.repairtime);fscanf(file,%fn,&carsi-record.fee);fscanf(file,%fn,&carsi-record.earn);fscanf(file,%fn,&carsi-record.benifit);carsi-record.information = (char *)malloc(imax);fgets(carsi-record.information,imax,file);carsi-record.lable = lable+ ;itoa(carsi-record.number, carsi-record.way, 10);strcat(carsi-record.way,.jpg);if(i=0)carsi-next=head-next;head-next = carsi;carsi-front = head;else if(i) linkinsert(head,carsi);fclose(file);return num;/对车库里的车进行排序carnode* nodesortavailable(carnode *head,int n) carnode *head1,*q,*p,*u;int i=0;head1=(carnode*)malloc(sizeof(carnode);initnode(head1);u= head1-next;if(head-next)p=head-next;q=p;else return head;while(inext;if(p!=null&(q-record.journeyrecord.journey) q=p;if(q-next=null) q-front-next=q-next;else if(q-next)q-front-next=q-next;q-next-front =q-front;linkinsert(head1, q);+i;p=head-next;q=p;q=head;while(q)u=q;q=q-next;free(u);head= head1;free(q);free(p);return head1;/添加车辆int addcar(carnode* head,char*path,char *strnum ,char *name,char *strjourney, char *infor)carnode* node;node=(carnode*)malloc(sizeof(carnode);initnode(node);node-record.name = (char *)malloc(nmax);node-record.information = (char *)malloc(imax);int number = atoi(strnum);int journey = atoi(strjourney);node-record.number= number;node-record.name = name;node-record.journey = journey;node-record.information = infor;if(number =0 |name=n |journey=0|infor =n ) return 1;node-record.rentedtime=0;node-record.repairtime=0;node-record.fee=0;node-record.earn=0;file *fp=fopen(path,w);fprintf(fp,%dn%sn%dn%dn%dn%.2fn%.2fn%sn,node-record.number,node-record.name,node-record.journey,node-record.rentedtime,node-record.repairtime,node-record.fee,node-record.earn,node-record.information);fclose(fp);file *file = fopen(path,rt);fscanf(file,%dn,&node-record.number);fgets(node-record.name,nmax,file);fscanf(file,%dn,&node-record.journey);fscanf(file,%dn,&node-record.rentedtime);fscanf(file,%dn,&node-record.repairtime);fscanf(file,%fn,&node-record.fee);fscanf(file,%fn,&node-record.earn);fgets(node-record.information,imax,file);if(head-next=null)node-next=head-next;head-next =node;node-front = head;else if(head-next!=null) linkinsert(head,node);return 0;/保存导出数据int putinfile(carnode* head, char *path,int n) file *fp=fopen(path,w);carnode* p;p=head-next;fprintf(fp,%dn,n);while(p)fprintf(fp,%dn%s%dn%dn%dn%.2fn%.2fn%.2fn%s, p-record.number,p-record.name,p-record.journey,p-record.rentedtime,p-record.repairtime,p-record.fee,p-record.earn,p-record.benifit,p-record.informatin);p=p-next;fclose(fp);free(p);return 0;/查看收益float benifit(head &head, float &fee, float &earn) carnode* p;float ben;p=head.available-next;if(p)while(p)earn =earn +p-record.earn;fee = fee+ p-record.fee;p=p-next;p=head.rented-next;if(p)while(p)earn =earn +p-record.earn;fee = fee+ p-record.fee;p=p-next;p=head.repair-next;if(p)while(p)earn =earn +p-record.earn;fee = fee+ p-record.fee;p=p-next;ben = earn -fee;return ben;/删除车辆int delcar(head &head,int num) carnode *p;int n=0;p=head.available-next;while(p)if(p-record.number=num)n=num;break;p=p-next;if(n=0)return 1;else if(n!=0)p-front-next = p-next;if(p-next!=null) p-next-front =p-front;head.an-;free(p);return 0;return 0;/初始化对话框bool main_oninitdialog(hwnd hwnd, hwnd hwndfocus, lparam lparam)hwnd hwndcombocars =getdlgitem(hwnd,idc_combocars);hwnd hwndcombosearch =getdlgitem(hwnd,idc_combosearch);combobox_insertstring(hwndcombosearch,-1,车牌);combobox_insertstring(hwndcombosearch,-1,车名);char *patha,*pathre,*pathrep;patha=carsavailable.txt;pathre=carsrented.txt;pathrep=carsrepair.txt;head h;int lable=0;h.available=(carnode*)malloc(sizeof(carnode);initnode(h.available);h.rented=(carnode*)malloc(sizeof(carnode);initnode(h.rented);h.repair=(carnode*)malloc(sizeof(carnode);initnode(h.repair);h.an= loadrecord(patha,h.available,lable);lable = h.an;h.ren= loadrecord(pathre,h.rented,lable);lable = h.an+h.ren;h.repn= loadrecord(pathrep,h.repair,lable);h.available =nodesortavailable(h.available, h.an);h.repair = nodesortrepair(h.repair,h.repn);h.rented=nodesortrented(h.rented,h.ren);carnode* p;p=h.available-next;while(p!=null)combobox_addstring(hwndcombocars,p-record.name);p=p-next;p=h.rented-next;while(p!=null)combobox_addstring(hwndcombocars,p-record.name);p=p-next;p=h.repair-next;while(p!=null)combobox_addstring(hwndcomboc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025广西来宾市忻城县政府投资审计中心招聘见习生2人模拟试卷及完整答案详解1套
- 2025湖南岳阳市平江县事业单位第一批公开选调工作人员考前自测高频考点模拟试题及一套答案详解
- 2025年上半年四川绵阳市游仙区考核招聘教师31人考前自测高频考点模拟试题及1套参考答案详解
- 2025河南商丘市民权县消防救援大队招聘政府专职消防员32人模拟试卷及参考答案详解1套
- 2025海南白沙黎族自治县机关事务服务中心招聘公益性岗位人员2人考前自测高频考点模拟试题附答案详解
- 2025年阜阳颍上县人民医院引进博士研究生2人考前自测高频考点模拟试题附答案详解(完整版)
- 2025年轧钢导卫装置项目合作计划书
- 2025广东中共中山市委政法委员会所属事业单位招聘事业单位人员4人模拟试卷及完整答案详解一套
- 2025内蒙古鄂尔多斯生态环境职业学院人才引进38人考前自测高频考点模拟试题带答案详解
- 2025年福建省龙岩市武平县乡村人才振兴招聘10人模拟试卷及参考答案详解
- 高中化学-金属钠的性质及应用教学设计学情分析教材分析课后反思
- 工程量清单及招标控制价编制方案
- 04S519小型排水构筑物(含隔油池)图集
- 工程施工人员安全教育培训【共55张课件】
- 双碱法脱硫操作专项规程
- 人教版七年级上学期英语第一次月考试卷(含答案解析)
- 仿生机器鱼行业规模分析
- 胸闷病人的护理查房
- β内酰胺类抗菌药物皮肤试验指导原则(2021版)
- 北京猿人头盖骨失踪之谜
- 华中科技大学教学课件-工程传热学1王晓墨
评论
0/150
提交评论