#define_CRT_SECURE_NO_WARNINGS\n#include<stdio.h>\n#include<stdlib.h>\n#include<string.h>\n\n#define\ MAX_DEVICES\ 100\ // 最大设备数量\n#define\ MAX_USERS\ 100\ // 最大用户数量\n\n// 设备信息结构体\ntypedef\ struct\ {\n\tchar\ name[50];\n\tchar\ model[50];\n\tchar\ purchase_date[20];\n\tchar\ location[100];\n\tchar\ owner[50];\n\tchar\ borrower[50];\n\tchar\ borrow_date[20];\n\tchar\ return_date[20];\n}\ Device;\n\n// 用户信息结构体\ntypedef\ struct\ {\n\tchar\ username[50];\n\tchar\ password[50];\n}\ User;\n\nDevice\ devices[MAX_DEVICES];\ // 设备数组\nint\ numDevices\ =\ 0;\ // 当前设备数量\n\nUser\ users[MAX_USERS];\ // 用户数组\nint\ numUsers\ =\ 0;\ // 当前用户数量\n\n// 添加设备\nvoid\ addDevice()\ {\n\tif\ (numDevices\ >=\ MAX_DEVICES)\ {\n\t\tprintf("设备数量已达到上限,无法添加新设备。\n");\n\t\treturn;\n\t}\n\n\tDevice\ newDevice;\n\n\tprintf("请输入设备名称:");\n\tscanf("%s",\ newDevice.name);\n\tprintf("请输入设备型号:");\n\tscanf("%s",\ newDevice.model);\n\tprintf("请输入设备采购时间:");\n\tscanf("%s",\ newDevice.purchase_date);\n\tprintf("请输入设备存放位置:");\n\tscanf("%s",\ newDevice.location);\n\tprintf("请输入设备负责人:");\n\tscanf("%s",\ newDevice.owner);\n\n\tdevices[numDevices++]\ =\ newDevice;\n\n\tprintf("设备添加成功。\n");\n}\n\n// 修改设备\nvoid\ modifyDevice()\ {\n\tchar\ name[50];\n\tprintf("请输入要修改的设备名称:");\n\tscanf("%s",\ name);\n\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tif\ (strcmp(devices[i].name,\ name)\ ==\ 0)\ {\n\t\t\tprintf("请输入新的设备名称:");\n\t\t\tscanf("%s",\ devices[i].name);\n\t\t\tprintf("请输入新的设备型号:");\n\t\t\tscanf("%s",\ devices[i].model);\n\t\t\tprintf("请输入新的设备采购时间:");\n\t\t\tscanf("%s",\ devices[i].purchase_date);\n\t\t\tprintf("请输入新的设备存放位置:");\n\t\t\tscanf("%s",\ devices[i].location);\n\t\t\tprintf("请输入新的设备负责人:");\n\t\t\tscanf("%s",\ devices[i].owner);\n\n\t\t\tprintf("设备信息修改成功。\n");\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf("未找到要修改的设备。\n");\n}\n\n// 删除设备\nvoid\ deleteDevice()\ {\n\tchar\ name[50];\n\tprintf("请输入要删除的设备名称:");\n\tscanf("%s",\ name);\n\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tif\ (strcmp(devices[i].name,\ name)\ ==\ 0)\ {\n\t\t\tint\ j;\n\t\t\tfor\ (j\ =\ i;\ j\ <\ numDevices\ -\ 1;\ j++)\ {\n\t\t\t\tdevices[j]\ =\ devices[j\ +\ 1];\n\t\t\t}\n\t\t\tnumDevices--;\n\n\t\t\tprintf("设备删除成功。\n");\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf("未找到要删除的设备。\n");\n}\n\n// 添加用户\nvoid\ addUser()\ {\n\tif\ (numUsers\ >=\ MAX_USERS)\ {\n\t\tprintf("用户数量已达到上限,无法添加新用户。\n");\n\t\treturn;\n\t}\n\n\tUser\ newUser;\n\n\tprintf("请输入用户名:");\n\tscanf("%s",\ newUser.username);\n\tprintf("请输入密码:");\n\tscanf("%s",\ newUser.password);\n\n\tusers[numUsers++]\ =\ newUser;\n\n\tprintf("用户添加成功。\n");\n}\n\n// 删除用户\nvoid\ deleteUser()\ {\n\tchar\ username[50];\n\tprintf("请输入要删除的用户名:");\n\tscanf("%s",\ username);\n\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numUsers;\ i++)\ {\n\t\tif\ (strcmp(users[i].username,\ username)\ ==\ 0)\ {\n\t\t\tint\ j;\n\t\t\tfor\ (j\ =\ i;\ j\ <\ numUsers\ -\ 1;\ j++)\ {\n\t\t\t\tusers[j]\ =\ users[j\ +\ 1];\n\t\t\t}\n\t\t\tnumUsers--;\n\n\t\t\tprintf("用户删除成功。\n");\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf("未找到要删除的用户。\n");\n}\n\n// 查询设备\nvoid\ searchDevice()\ {\n\tchar\ name[50];\n\tprintf("请输入要查询的设备名称:");\n\tscanf("%s",\ name);\n\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tif\ (strcmp(devices[i].name,\ name)\ ==\ 0)\ {\n\t\t\tprintf("设备名称:%s\n",\ devices[i].name);\n\t\t\tprintf("设备型号:%s\n",\ devices[i].model);\n\t\t\tprintf("设备采购时间:%s\n",\ devices[i].purchase_date);\n\t\t\tprintf("设备存放位置:%s\n",\ devices[i].location);\n\t\t\tprintf("设备负责人:%s\n",\ devices[i].owner);\n\t\t\tif\ (strlen(devices[i].borrower)\ >\ 0)\ {\n\t\t\t\tprintf("设备借用人:%s\n",\ devices[i].borrower);\n\t\t\t\tprintf("设备借用时间:%s\n",\ devices[i].borrow_date);\n\t\t\t\tprintf("设备归还时间:%s\n",\ devices[i].return_date);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf("未找到该设备。\n");\n}\n\n// 申请借用设备\nvoid\ borrowDevice()\ {\n\tchar\ name[50];\n\tprintf("请输入要借用的设备名称:");\n\tscanf("%s",\ name);\n\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tif\ (strcmp(devices[i].name,\ name)\ ==\ 0)\ {\n\t\t\tif\ (strlen(devices[i].borrower)\ >\ 0)\ {\n\t\t\t\tprintf("该设备已被借用。\n");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tprintf("请输入借用人姓名:");\n\t\t\tscanf("%s",\ devices[i].borrower);\n\t\t\tprintf("请输入借用日期:");\n\t\t\tscanf("%s",\ devices[i].borrow_date);\n\n\t\t\tprintf("设备借用成功。\n");\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf("未找到该设备。\n");\n}\n\n// 显示所有设备\nvoid\ displayDevices()\ {\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tprintf("设备名称:%s\n",\ devices[i].name);\n\t\tprintf("设备型号:%s\n",\ devices[i].model);\n\t\tprintf("设备采购时间:%s\n",\ devices[i].purchase_date);\n\t\tprintf("设备存放位置:%s\n",\ devices[i].location);\n\t\tprintf("设备负责人:%s\n",\ devices[i].owner);\n\t\tif\ (strlen(devices[i].borrower)\ >\ 0)\ {\n\t\t\tprintf("设备借用人:%s\n",\ devices[i].borrower);\n\t\t\tprintf("设备借用时间:%s\n",\ devices[i].borrow_date);\n\t\t\tprintf("设备归还时间:%s\n",\ devices[i].return_date);\n\t\t}\n\t\tprintf("\n");\n\t}\n}\n\n// 保存用户信息和设备信息到文件\nvoid\ saveToFile()\ {\n\tFILE*\ file\ =\ fopen("C:\Users\额额\Desktop\cvb\789",\ "w");\n\tif\ (file\ ==\ NULL)\ {\n\t\tprintf("无法打开文件。\n");\n\t\treturn;\n\t}\n\n\t// 保存用户信息\n\tint\ i;\n\tfor\ (i\ =\ 0;\ i\ <\ numUsers;\ i++)\ {\n\t\tfprintf(file,\ "%s\ %s\n",\ users[i].username,\ users[i].password);\n\t}\n\n\t// 保存设备信息\n\tfor\ (i\ =\ 0;\ i\ <\ numDevices;\ i++)\ {\n\t\tfprintf(file,\ "%s\ %s\ %s\ %s\ %s\ %s\ %s\ %s\n",\ devices[i].name,\ devices[i].model,\ devices[i].purchase_date,devices[i].location,\ devices[i].owner,\ devices[i].borrower,\ devices[i].borrow_date,\ devices[i].return_date);\n\t}\n\n\tfclose(file);\n}\n\n// 从文件中加载用户信息和设备信息\nvoid\ loadFromFile()\ {\n\tFILE*\ file\ =\ fopen("C:\Users\额额\Desktop\cvb\789",\ "r");\n\tif\ (file\ ==\ NULL)\ {\n\t\tprintf("无法打开文件。\n");\n\t\treturn;\n\t}\n\n\t// 加载用户信息\n\tchar\ line[100];\n\twhile\ (fgets(line,\ sizeof(line),\ file)\ !=\ NULL)\ {\n\t\tsscanf(line,\ "%s\ %s",\ users[numUsers].username,\ users[numUsers].password);\n\t\tnumUsers++;\n\t}\n\n\t// 加载设备信息\n\twhile\ (fgets(line,\ sizeof(line),\ file)\ !=\ NULL)\ {\n\t\tsscanf(line,\ "%s\ %s\ %s\ %s\ %s\ %s\ %s\ %s",\ devices[numDevices].name,\ devices[numDevices].model,\n\t\t\tdevices[numDevices].purchase_date,\ devices[numDevices].location,\ devices[numDevices].owner,\n\t\t\tdevices[numDevices].borrower,\ devices[numDevices].borrow_date,\ devices[numDevices].return_date);\n\t\tnumDevices++;\n\t}\n\n\tfclose(file);\n}\n\nint\ main()\ {\n\tint\ memanu();\n\tint\ admanu();\n\tloadFromFile();\n\tint\ a;\n\tprintf("请输入:\n1.管理者系统\n2.用户系统\n");\n\tscanf("%d",&a);\n\tif(a==1)\n\t\tadmanu();\n\telse\n\t\tmemanu();\n\treturn\ 0;\n}\n\t\n\t\n\tint\ admanu()\ {\n\t\tint\ choice\ =\ 0;\n\t\tdo\ {\n\t\t\tprintf("欢迎使用实验室设备管理系统,请选择操作:\n");\n\t\t\tprintf("1. 添加设备\n");\n\t\t\tprintf("2. 修改设备\n");\n\t\t\tprintf("3. 删除设备\n");\n\t\t\tprintf("4. 添加用户\n");\n\t\t\tprintf("5. 删除用户\n");\n\t\t\tprintf("6. 查询设备\n");\n\t\t\tprintf("7. 申请借用设备\n");\n\t\t\tprintf("8. 显示所有设备\n");\n\t\t\tprintf("0. 退出\n");\n\n\t\t\tscanf("%d",\ &choice);\n\n\t\t\tswitch\ (choice)\ {\n\t\t\tcase\ 1:\n\t\t\t\taddDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 2:\n\t\t\t\tmodifyDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 3:\n\t\t\t\tdeleteDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 4:\n\t\t\t\taddUser();\n\t\t\t\tbreak;\n\t\t\tcase\ 5:\n\t\t\t\tdeleteUser();\n\t\t\t\tbreak;\n\t\t\tcase\ 6:\n\t\t\t\tsearchDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 7:\n\t\t\t\tborrowDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 8:\n\t\t\t\tdisplayDevices();\n\t\t\t\tbreak;\n\t\t\tcase\ 0:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tprintf("无效的选择。\n");\n\t\t\t}\n\t\t} while\ (choice\ !=\ 0);\n\t\tsaveToFile();\n\t\treturn\ 0;\n\t}\n\nint\ memanu()\ {\n\t\tint\ choice\ =\ 0;\n\t\tdo\ {\n\t\t\tprintf("欢迎使用实验室设备管理系统,请选择操作:\n");\n\t\t\tprintf("1. 查询设备\n");\n\t\t\tprintf("2. 申请借用设备\n");\n\t\t\tprintf("3. 显示所有设备\n");\n\t\t\tprintf("0. 退出\n");\n\n\t\t\tscanf("%d",\ &choice);\n\n\t\t\tswitch\ (choice)\ {\n\t\t\tcase\ 1:\n\t\t\t\tsearchDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 2:\n\t\t\t\tborrowDevice();\n\t\t\t\tbreak;\n\t\t\tcase\ 3:\n\t\t\t\tdisplayDevices();\n\t\t\t\tbreak;\n\t\t\tcase\ 0:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tprintf("无效的选择。\n");\n\t\t\t}\n\t\t} while\ (choice\ !=\ 0);\n\t\tsaveToFile();\n\t\treturn\ 0;\n\t

实验室设备管理系统:添加、修改、删除设备,借用设备

原文地址: https://www.cveoy.top/t/topic/ptNM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录