实验设备管理系统(C语言版)_第1页
实验设备管理系统(C语言版)_第2页
实验设备管理系统(C语言版)_第3页
实验设备管理系统(C语言版)_第4页
实验设备管理系统(C语言版)_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

实验设备管理系统(C语言版)功能简介:设备录入、查询、修改、删除、设备借用归还、数据文件持久化保存、菜单交互,适合C语言课程大作业。

编译环境:Dev-C++/VS/GCC均可直接运行c

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#defineMAX_DEVICE100//最大设备数量

#defineFILE_NAME"device.dat"

//设备结构体

typedefstruct{

charid[20];//设备编号

charname[50];//设备名称

chartype[30];//设备型号

charstatus[20];//状态:空闲/借出/维修

charuser[30];//借用人

}Device;

DevicedevList[MAX_DEVICE];

intdevCount=0;//当前设备总数

//函数声明

voidloadData();//从文件加载数据

voidsaveData();//保存数据到文件

voidmenu();//主菜单

voidaddDevice();//添加设备

voidshowAll();//显示所有设备

voidsearchDevice();//查询设备

voidmodifyDevice();//修改设备信息

voiddelDevice();//删除设备

voidborrowDevice();//设备借用

voidreturnDevice();//设备归还

intmain(){

intchoice;

loadData();//程序启动读取文件

while(1){

menu();

printf("请输入功能选择:");

scanf("%d",&choice);

getchar();//吸收换行符

switch(choice){

case1:addDevice();break;

case2:showAll();break;

case3:searchDevice();break;

case4:modifyDevice();break;

case5:delDevice();break;

case6:borrowDevice();break;

case7:returnDevice();break;

case0:

saveData();

printf("数据已保存,系统退出!\n");

system("pause");

return0;

default:

printf("输入错误,请重新选择!\n");

system("pause");

}

system("cls");//Windows清屏,Linux换成system("clear");

}

return0;

}

voidmenu(){

printf("================实验设备管理系统================\n");

printf("1.添加设备\n");

printf("2.查看全部设备\n");

printf("3.查询设备(按编号)\n");

printf("4.修改设备信息\n");

printf("5.删除设备\n");

printf("6.设备借用\n");

printf("7.设备归还\n");

printf("0.退出系统并保存\n");

printf("=================================================\n");

}

//加载文件数据

voidloadData(){

FILE*fp=fopen(FILE_NAME,"rb");

if(fp==NULL){

//文件不存在直接返回

devCount=0;

return;

}

devCount=fread(devList,sizeof(Device),MAX_DEVICE,fp);

fclose(fp);

}

//保存数据

voidsaveData(){

FILE*fp=fopen(FILE_NAME,"wb");

if(fp==NULL){

printf("文件打开失败,保存失败!\n");

return;

}

fwrite(devList,sizeof(Device),devCount,fp);

fclose(fp);

}

//添加设备

voidaddDevice(){

if(devCount>=MAX_DEVICE){

printf("设备数量已达上限!\n");

system("pause");

return;

}

Deviced;

printf("====新增设备====\n");

printf("设备编号:");

scanf("%s",d.id);

getchar();

printf("设备名称:");

gets();

printf("设备型号:");

gets(d.type);

strcpy(d.status,"空闲");

strcpy(d.user,"无");

devList[devCount++]=d;

printf("设备添加成功!\n");

system("pause");

}

//展示所有设备

voidshowAll(){

if(devCount==0){

printf("暂无设备数据!\n");

system("pause");

return;

}

printf("================================================================================\n");

printf("%-12s%-18s%-15s%-12s%-12s\n","设备编号","设备名称","型号","状态","借用人");

printf("================================================================================\n");

for(inti=0;i<devCount;i++){

printf("%-12s%-18s%-15s%-12s%-12s\n",

devList[i].id,

devList[i].name,

devList[i].type,

devList[i].status,

devList[i].user);

}

printf("================================================================================\n");

system("pause");

}

//按编号查询

voidsearchDevice(){

charid[20];

intfind=0;

printf("输入要查询的设备编号:");

scanf("%s",id);

for(inti=0;i<devCount;i++){

if(strcmp(devList[i].id,id)==0){

printf("\n====查询结果====\n");

printf("编号:%s\n名称:%s\n型号:%s\n状态:%s\n借用人:%s\n",

devList[i].id,devList[i].name,devList[i].type,devList[i].status,devList[i].user);

find=1;

break;

}

}

if(!find)printf("未找到该设备!\n");

system("pause");

}

//修改设备信息

voidmodifyDevice(){

charid[20];

inti,find=-1;

printf("输入要修改的设备编号:");

scanf("%s",id);

getchar();

for(i=0;i<devCount;i++){

if(strcmp(devList[i].id,id)==0){

find=i;

break;

}

}

if(find==-1){

printf("未找到设备!\n");

system("pause");

return;

}

printf("输入新设备名称:");

gets(devList[find].name);

printf("输入新设备型号:");

gets(devList[find].type);

printf("设备信息修改成功!\n");

system("pause");

}

//删除设备

voiddelDevice(){

charid[20];

inti,j,find=-1;

printf("输入要删除的设备编号:");

scanf("%s",id);

for(i=0;i<devCount;i++){

if(strcmp(devList[i].id,id)==0){

find=i;

break;

}

}

if(find==-1){

printf("未找到设备!\n");

system("pause");

return;

}

//后续数据前移覆盖

for(j=find;j<devCount-1;j++){

devList[j]=devList[j+1];

}

devCount--;

printf("设备删除成功!\n");

system("pause");

}

//借用设备

voidborrowDevice(){

charid[20],name[30];

inti,find=-1;

printf("输入要借用的设备编号:");

scanf("%s",id);

getchar();

for(i=0;i<devCount;i++){

if(strcmp(devList[i].id,id)==0){

find=i;

break;

}

}

if(find==-1){

printf("未找到设备!\n");

system("pause");

return;

}

if(strcmp(devList[find].status,"借出")==0){

printf("该设备已经被借出,无法再次借用!\n");

system("pause");

return;

}

printf("输入借用人姓名:");

gets(name);

strcpy(devList[find].status,"借出");

strcpy(devList[find].user,name);

printf("设备借用登记成功!\n");

system("pause");

}

//归还设备

voidreturnDevice(){

charid[20];

inti,find=-1;

printf("输入归还设备编号:");

scanf("%s",id);

for(i=0;i<devCount;i++){

if(strcmp(devList[i].id,id)==0){

find=i;

温馨提示

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

评论

0/150

提交评论