C语言-汽车租赁管理系统实习报告书(共30页)_第1页
C语言-汽车租赁管理系统实习报告书(共30页)_第2页
C语言-汽车租赁管理系统实习报告书(共30页)_第3页
C语言-汽车租赁管理系统实习报告书(共30页)_第4页
C语言-汽车租赁管理系统实习报告书(共30页)_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上西北农林科技大学信息工程学院数据结构与C语言综合训练实习报告题 目: 汽车租借公司的管理 学 号姓 名陈金亚专业班级计算机科学与技术102班指导教师蔡骋完成日期2011年7月8日7月17日目 录专心-专注-专业一、综合训练目的与要求本综合训练是软件工程专业重要的实践性环节之一,是在学生学习完算法分析课程后进行的综合练习。本课综合训练的目的和任务:1. 巩固和加深学生对算法分析课程基本知识的理解和掌握;2. 培养利用算法知识解决实际问题的能力;3. 掌握利用程序设计语言进行算法程序的开发、调试、测试的能力;4. 掌握书写算法设计说明文档的能力;5. 提高综合运用算法、程

2、序设计语言、数据结构知识的能力。6. 应用线性数据结构存储信息,并能够应用上面的基本操作实现事务管理。二、综合训练任务描述设计数据结构及算法完成某个汽车租借公司日常工作的组织与管理。该管理系统的基本管理对象为汽车,每台汽车用一个license number进行唯一标识。每个汽车存在三种可能状态:·可以租借(available for rent)·已借(rented)·修理中(in repair)其中在available队列中汽车应该依据汽车行驶过的路程进行排序,行驶路程最少的汽车排在最前面。在rented队列中的汽车应依据其预期返回时间进行排序,排在最前的应是预期

3、最早返回的汽车。三、算法设计(1) 文字描述用三个链表组织三种状态的汽车, 能够实现租借的日常事务:引入新车,租借,收费,修理等。租借收费应根据汽车行驶的路程及借去的时间综合计算得出,路程收费标准如下:低于100Km收费20.00元, 100Km以外的路程枚Km收费0.15元, 汽车根据行驶的路程定期进行维护, 还需实现辅助操作:汽车查询,打印全部信息,计算并打印收入、成本及收益, 主要集中在链表的基本操作上管理系统应有完整地界面(最好是图形化界面)主要集中在链表的基本操作上,主要是链表的插入、删除、排序,文件导入导出。(2) 框图导出文件保存按车牌查找按车名查找开始退出结束初始化导入文件删除

4、成功,链表操作添加成功,链表操作已修成功,链表操作修理成功,链表操作归还成功,链表操作租赁成功,链表操作输入车辆信息输入车辆信息输入车辆信息输入车辆信息输入车辆信息输入车辆信息打印车辆信息打印收益查看车辆选择车辆查找车辆查看收益删除车辆添加车辆已修车辆修理车辆租赁车辆归还车辆(3) 伪代码struct carRecord/ 汽车记录结构体 int Number; char *Name; int Journey; char *Information; int AvailableRent; int RentedTime; int RepairTime; float Fee; float Earn;

5、 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->Nex

6、t = 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 ; i<num; i+)

7、 Carsi->Record.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",&am

8、p;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,fil

9、e);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->

10、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->N

11、ext; 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->

12、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(i<n) while(p) p =p->Next; if(p!=NULL&&(q->Record.Journey<p->Record.Journey) q=p; if(q-&g

13、t;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;/ nodeSortAva

14、ilablecarNode* 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, in

15、t 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(NM

16、AX); 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" )

17、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.Infor

18、mation); 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(sum<=100) charge=20+t*5

19、00; else if(sum>100) 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.

20、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

21、.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; retu

22、rn 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); /

23、 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_DE

24、LCAR: 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()实

25、现,链表的插入有函数linkInsert(),链表的排序通过插入排序,建立一个新的排序链表,然后将旧的未排序链表删除,将新链表赋予原来的表头,通过nodeSort()函数实现,由于三个链表的排序关键字不同,所以设计了nodeSortAvailable(),nodeSortRented (),nodeSortRepair()三个函数,对三个链表进行排序。为了能是操作简单一些,我设计的是双向链表,那么删除是就可以直接删除,减少时间的消耗,删除节点的函数是delCar(),代码部分主要就是对双向链表的常规操作。为了使导入数据方便,数据的导入方式为文件导入,三种状态的车辆信息分别放在CarsAvail

26、able.txt,CarsRented.txt,CarsRepair.txt里面,打开程序后遍自动导入,导入同时进行排序。同时可以在这三个文件里经行修改管理。图形界面为一个简单的对话框模式,初始化对话的为Main_OnInitDialog(),对命令经行响应的是Main_OnCommand()函数,将源代码与图形界面结合后,是程序更人性化,是操作更简单明了。对于图片的展示,由于水平有限,使用windows自带的图片浏览器。五、调试与测试5-1 无图形界面测试(针对代码测试)(堆)调试分为两个部分,第一部分是代码的测试,第二部分是图形界面与代码结合的测试。5-2 图形界面测试5-3 数据文本格式

27、六、实习日志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日,在代码和图形结合时,对代码不完善

28、的地方,和不适用图形的部分进行修改和删减,并可以通过图形进行操作,增加了通过车牌和车名进行查找;7月17日,完善图形界面和代码,撰写实习报告。七、实习总结本次实习总共历时10天,培养学生的动手操作能力和创新能力。我在实习中遇到不少问题,其中不乏很多简单的但是被我忽略的错误,导致一个错误很长时间无法解决,却是因为一个初始化问题。同时由于编译器不同,对代码的严谨程度也不同,Codeblocks对许多错误能够容忍不报错,而VC+ 6.0就不同了,由于初始的代码实在Codeblocks里编写的,所以复制到VC+ 6.0后,修改了很长时间的代码,从中学到不少书本上没有的知识。令人欣慰的是,最终摆脱了黑底

29、白字的命令行,实现图形界面的操作。但是,在学习过程中,并没有真正运用到VC+的特性,只是将代码与图形界面生拉硬拽联系上的,在以后的学习中,还要努力。八、附录:核心代码清单#include "stdafx.h"#include <windows.h>#include <windowsx.h>#include "resource.h"#include "MainDlg.h"#include <commdlg.h>#include "iostream"#include "sh

30、ellapi.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

31、 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(carNo

32、de *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,

33、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);i

34、nt 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-&g

35、t;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->

36、;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 ; i<num; i+)Carsi=(carNode

37、*)malloc(sizeof(carNode);initNode(Carsi);for(i=0 ; i<num; i+)Carsi->Record.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

38、->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->R

39、ecord.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 =

40、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

41、head;while(i<n)while(p)p =p->Next;if(p!=NULL&&(q->Record.Journey<p->Record.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;w

42、hile(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.Infor

43、mation = (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->

44、;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.RepairT

45、ime,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&

46、quot;,&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->N

47、ext;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%.2f

48、n%.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, floa

49、t &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

50、->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-&g

51、t;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

52、,"车牌");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=

53、(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 =nodeSortAvailabl

54、e(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)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论