#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {int year;int month;int day;
}date;
typedef struct {int num;char type[15];char name[15];double price;date grrq;//购入日期char baofei;//是否报废date bfrq;//报废日期
}device;
#define LEN sizeof(device)
#define Filename "d:\\123.txt"
device *Dev;//动态数组,就是元素数可变的数组
int count;//动态数组的元素数(设备数)
void loadfile() {//读取文件device d; FILE *fp; int i;count = 0;fp = fopen(Filename, "r+");Dev = (device*)malloc(LEN);//分配内存if (fp == NULL) {fp = fopen(Filename, "w");//如果文件d:\123.txt不存在就创建一个fclose(fp);return;}i = fscanf(fp, "%d %s %s %lf %d %d %d %c %d %d %d", &d.num, d.type, d.name, &d.price, &d.grrq.year, &d.grrq.month, &d.grrq.day, &d.baofei, &d.bfrq.year, &d.bfrq.month, &d.bfrq.day);while (i != -1) {//fscanf读取到最后一行会返回-1Dev[count] = d;count++;Dev = (device*)realloc((void*)Dev, (count + 1)*LEN);//扩展元素数(重新分配内存)i = fscanf(fp, "%d %s %s %lf %d %d %d %c %d %d %d", &d.num, d.type, d.name, &d.price, &d.grrq.year, &d.grrq.month, &d.grrq.day, &d.baofei, &d.bfrq.year, &d.bfrq.month, &d.bfrq.day);}fclose(fp);
}
void search1() {int i, num;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备编号:");scanf("%d", &num);for (i = 0; i<count; i++) {if (Dev[i].num == num) {printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);return;}}printf("\n该设备编号不存在\n\n");
}
void search2() {int i, c = 0, bf = 0; char type[15]; double sum = 0;getchar();//去除scanf后缓冲区留下的回车system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备种类:");scanf("%s", type);for (i = 0; i<count; i++) {if (0 == strcmp(type, Dev[i].type)) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备种类为“%s”的设备\n\n", type);else printf("\n共有%d个设备种类为“%s”的设备,%d个已报废,总价格为%.2lf\n\n", c, type, bf, sum);
}
void search3() {int i, c = 0, bf = 0; char name[15]; double sum = 0;getchar();//去除scanf后缓冲区留下的回车system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备名称:");scanf("%s", name);//gets(name);for (i = 0; i<count; i++) {if (0 == strcmp(name, Dev[i].name)) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备名称为“%s”的设备\n\n", name);else printf("\n共有%d个设备名称为“%s”的设备,%d个已报废,总价格为%.2lf\n\n", c, name, bf, sum);
}
void search41() {int i, c = 0, bf = 0; double price, sum = 0;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备价格:");scanf("%lf", &price);for (i = 0; i<count; i++) {if (Dev[i].price == price) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备价格为%.2lf的设备\n\n", price);else printf("\n共有%d个设备价格为%.2lf的设备,%d个已报废,总价格为%.2lf\n\n", c, price, bf, sum);
}
void search42() {int i, c = 0, bf = 0; double price, sum = 0;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备价格下限:");scanf("%lf", &price);for (i = 0; i<count; i++) {if (Dev[i].price >= price) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备价格高于%.2lf的设备\n\n", price);else printf("\n共有%d个设备价格高于%.2lf的设备,%d个已报废,总价格为%.2lf\n\n", c, price, bf, sum);
}
void search43() {int i, c = 0, bf = 0; double price, sum = 0;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备价格上限:");scanf("%lf", &price);for (i = 0; i<count; i++) {if (Dev[i].price <= price) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备价格低于%.2lf的设备\n\n", price);else printf("\n共有%d个设备价格低于%.2lf的设备,%d个已报废,总价格为%.2lf\n\n", c, price, bf, sum);
}
void search44() {int i, c = 0, bf = 0; double min, max, t, sum = 0;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要查询的设备价格下限:");scanf("%lf", &min);printf("请输入要查询的设备价格上限:");scanf("%lf", &max);if (min>max) { t = min; min = max; max = t; }for (i = 0; i<count; i++) {if (Dev[i].price >= min&&Dev[i].price <= max) {if (c == 0)printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");c++; sum += Dev[i].price; if ('Y' == Dev[i].baofei)bf++;printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}}if (c == 0)printf("\n不存在设备价格高于%.2lf且低于%.2lf的设备\n\n", min, max);else printf("\n共有%d个设备价格高于%.2lf低于%.2lf的设备,%d个已报废,总价格为%.2lf\n\n", c, min, max, bf, sum);
}
void search4() {int i;while (1) {system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("1.查询价格为某一数值的设备\n2.查询价格高于某一数值的设备\n3.查询价格低于某一数值的设备\n4.查询价格在某一区间的设备\n0.返回上一层菜单\n\n");printf("请选择:");scanf("%d", &i);switch (i) {case 1:search41(); system("pause"); break;case 2:search42(); system("pause"); break;case 3:search43(); system("pause"); break;case 4:search44(); system("pause"); break;case 0:return;}}
}
void search() {//查询设备信息子菜单int i;while (1) {system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("1.按设备编号查询\n2.按设备种类查询\n3.按设备名称查询\n4.按设备价格查询\n0.返回主菜单\n\n");printf("请选择:");scanf("%d", &i);switch (i) {case 1:search1(); system("pause"); break;case 2:search2(); system("pause"); break;case 3:search3(); system("pause"); break;case 4:search4(); break;case 0:return;}}
}
void sort() {//对设备编号选择排序(升序)int i, j, k; device t;for (i = 0; i<count - 1; i++) {k = i;for (j = i; j<count; j++)if (Dev[k].num>Dev[j].num)k = j;if (k != i) {t = Dev[k]; Dev[k] = Dev[i]; Dev[i] = t;}}
}
void writefile() {//将数组写入文件FILE *fp; int i;fp = fopen(Filename, "w");for (i = 0; i<count; i++) {fprintf(fp, "%d %s %s %.2lf %d %d %d %c %d %d %d\r\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);}//写进文件换行必须\r\n,只有\n不能换行fclose(fp);
}
void add() {//添加设备信息device d; int i;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("添加设备信息:\n");printf("请输入设备编号:");scanf("%d", &d.num);for (i = 0; i<count; i++) {//检查设备编号是否重复if (d.num == Dev[i].num) {printf("\n该设备编号与已有设备编号重复,请重新输入\n\n");system("pause");return;}}getchar();//去掉scanf后留在缓冲区里的回车printf("请输入设备种类:");scanf("%s", d.type);printf("请输入设备名称:");scanf("%s", d.name);printf("请输入设备价格:");scanf("%lf", &d.price);printf("请输入购入日期(格式为年-月-日):");scanf("%d-%d-%d", &d.grrq.year, &d.grrq.month, &d.grrq.day);getchar();//去掉scanf后留在缓冲区里的回车printf("请输入是否报废(Y=已报废,N=未报废):");scanf("%c", &d.baofei);printf("请输入报废日期(格式为年-月-日):");scanf("%d-%d-%d", &d.bfrq.year, &d.bfrq.month, &d.bfrq.day);Dev = (device*)realloc((void*)Dev, (count + 1)*LEN);//扩展元素数Dev[count] = d;//新增的设备加在数组最后count++;//设备数+1sort();//排序writefile();//写入进文件
}
void modify() {//修改设备信息int i, j, num; device d;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要修改的设备编号:");scanf("%d", &num);for (i = 0; i<count; i++) {if (Dev[i].num == num) {printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);break;//如果找到,拿出来处理,都搁在循环里太乱}}if (i == count) { printf("\n该设备编号不存在\n\n"); system("pause"); return; }printf("请输入修改后的信息:\n");printf("请输入设备编号:");scanf("%d", &d.num);for (j = 0; j<count; j++) {//检查设备编号是否重复if (i != j&&d.num == Dev[j].num) {//如果不修改设备编号,会提示设备编号重复,加入条件i!=j,即不判断修改后设备编号与修改前的是否相同printf("\n该设备编号与已有设备编号重复,请重新输入\n\n");system("pause");return;}}getchar();//去掉scanf后留在缓冲区里的回车printf("请输入设备种类:");scanf("%s", d.type);printf("请输入设备名称:");scanf("%s", d.name);printf("请输入设备价格:");scanf("%lf", &d.price);printf("请输入购入日期(格式为年-月-日):");scanf("%d-%d-%d", &d.grrq.year, &d.grrq.month, &d.grrq.day);getchar();//去掉scanf后留在缓冲区里的回车printf("请输入是否报废(Y=已报废,N=未报废):");scanf("%c", &d.baofei);printf("请输入报废日期(格式为年-月-日):");scanf("%d-%d-%d", &d.bfrq.year, &d.bfrq.month, &d.bfrq.day);Dev[i] = d;sort();//排序writefile();//写入文件
}
void del() {//删除设备int i, num;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("请输入要删除的设备编号:");scanf("%d", &num); getchar();//去除scanf后缓冲区留下的回车for (i = 0; i<count; i++) {if (Dev[i].num == num) {printf("\n设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);break;//如果找到,拿出来处理,都搁在循环里太乱}}if (i == count) { printf("\n该设备编号不存在\n\n"); system("pause"); return; }printf("你确定要删除此设备的信息吗?(输入Y确定,输入其他返回主菜单)");if ('Y' == getchar()) {for (; i<count - 1; i++) {Dev[i] = Dev[i + 1];//i之后的所有设备信息向前移动一个元素(没有下标为count的元素,所以不用循环至count-1)}count--;//设备数-1writefile();//写入文件}
}
void outputall() {//全部列出int i;double pricewbf = 0, pricebf = 0;//未报废总价格,报废总价格system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("全部设备信息:\n\n");printf("设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");for (i = 0; i<count; i++) {printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);if (Dev[i].baofei == 'Y')pricebf += Dev[i].price;//计算总价格else pricewbf += Dev[i].price;}printf("\n共有%d条设备信息\n所有设备总价格  %.2lf\n未报废设备总价格%.2lf\n报废设备总价格  %.2lf\n\n", count, pricewbf + pricebf, pricewbf, pricebf);system("pause");//按任意键继续(不会退出)
}
void outputbf() {//列出报废设备int i, c = 0; double pricebf = 0;system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("报废设备信息:\n\n");printf("设备编号 设备种类       设备名称       设备价格  购入日期   是否报废 报废日期\n");for (i = 0; i<count; i++) {if (Dev[i].baofei == 'Y') {printf("%8d %-14s %-14s %9.2lf %04d-%02d-%02d %c        %04d-%02d-%02d\n", Dev[i].num, Dev[i].type, Dev[i].name, Dev[i].price, Dev[i].grrq.year, Dev[i].grrq.month, Dev[i].grrq.day, Dev[i].baofei, Dev[i].bfrq.year, Dev[i].bfrq.month, Dev[i].bfrq.day);pricebf += Dev[i].price;c++;}}printf("\n共有%d个报废设备\n总价格%.2lf\n\n", c, pricebf);system("pause");//按任意键继续(不会退出)
}
int main() {int i;loadfile();//读取文件while (1) {system("cls");//清屏printf("----------------\n");printf("设备资产管理系统\n");printf("----------------\n\n");printf("1.列出全部设备信息\n2.列出报废设备信息\n3.查询设备信息\n4.添加设备信息\n5.修改设备信息\n6.删除设备信息\n0.退出\n\n");printf("请选择:");scanf("%d", &i);switch (i) {case 1:outputall(); break;case 2:outputbf(); break;case 3:search(); break;case 4:add(); break;case 5:modify(); break;case 6:del(); break;case 0:return 0;}}return 0;
}

C语言:设备管理系统相关推荐

  1. c语言设备管理系统实训答辩,C语言设计(力学实验设备管理系统)1答辩.doc

    <程序设计基础>课程设计 课题名称 力学实验设备管理系统设计 专 业 班 级 姓 名 学 号 指导教师 陈世基 2012年 06 月 12 日 目录 设计目的 ---------.1 总体 ...

  2. c语言课程设计实验设备,C语言课程设计课程设计_力学实验设备管理系统

    --------------------------------------------------正文内容开始-------------------------------------------- ...

  3. c语言实验设备管理系统设计作业,c语言程序设计实验设备管理系统

    c语言程序设计实验设备管理系统 1 苏州市职业大学继续教育学院 课 程 设 计 说 明 书 名称 C 语言程序设计课程设计 2012 年 10 月 31 日至 2012 年 11 月 14 日共 2 ...

  4. C语言课设设备管理系统(大作业)

    一.任务概述 设备管理系统应包含各种设备的全部信息,每台设备为一条记录(同一时间统一部门购买的若干相同设备可作为1条记录),包括设备号,设备名称,领用人,所属部门,数量,购买时间,价格等.能够显示和统 ...

  5. java计算机毕业设计机械生产企业办公设备管理系统MyBatis+系统+LW文档+源码+调试部署

    java计算机毕业设计机械生产企业办公设备管理系统MyBatis+系统+LW文档+源码+调试部署 java计算机毕业设计机械生产企业办公设备管理系统MyBatis+系统+LW文档+源码+调试部署 本源 ...

  6. 高校实验室仪器设备管理系统/实验室管理系统

    摘  要 随着科学技术的飞速发展,社会的方方面面.各行各业都在努力与现代的先进技术接轨,通过科技手段来提高自身的优势,高校实验室仪器设备管理系统当然也不能排除在外.高校实验室仪器设备管理系统是以实际运 ...

  7. 高校实验室仪器设备管理系统/高校设备管理系统

    摘  要 随着科学技术的飞速发展,社会的方方面面.各行各业都在努力与现代的先进技术接轨,通过科技手段来提高自身的优势,高校实验室仪器设备管理系统当然也不能排除在外.高校实验室仪器设备管理系统是以实际运 ...

  8. C#毕业设计——基于C#+asp.net+sqlserver的设备管理系统设计与实现(毕业论文+程序源码)——设备管理系统

    基于C#+asp.net+sqlserver的设备管理系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于C#+asp.net+sqlserver的设备管理系统设计与实现,文章末尾附有本毕 ...

  9. 基于C#+Mysql实现(WinForm)企业的设备管理系统【100010018】

    企业的设备管理系统 1 引言 企业的设备管理在企业的生产制造和管理过程之中意义比较重大,明确企业的设备的产权和维护成本对于企业的成本控制和财务管理之中起到了重要的作用.随着市场竞争的加剧,现代企业所处 ...

  10. 分享2款设备管理系统源码:Springboot医院设备管理+物联网云监控IOT设备管理

    淘源码:国内专业的免费源码下载平台 今天分享两套设备管理系统源码,一套是Springboot医院设备管理系统,另一套是php物联网iot设备管理系统,需要源码学习的小伙伴可私信我. ▶▶▶1:Spri ...

最新文章

  1. “新一代人工智能”研究的三大重点方向
  2. RuntimeError: Found dtype Double but expected Float”
  3. 技术人, 请不要封闭自己
  4. 《JavaScript 标准参考教程》阮一峰
  5. 国产操作系统进入被彻底抛弃的时代
  6. 233. Number of Digit One
  7. 智能家居(工厂模式)
  8. vue for 初始值_vue全套教程(实操)就在这里
  9. 浪潮之巅 第三章 “水果公司”的复兴 (4) 大难不死
  10. idea svn回退版本_mac下使用svn通过终端回退版本到某个版本号 - 博客频道 - CSDN.NET...
  11. C语言全局变量和局部变量的区别详解
  12. 深度学习语音降噪方法对比_一种融合骨振动传感器和麦克风信号的深度学习语音提取和降噪方法与流程...
  13. php表格怎么加粉色,为什么EXCEL算出的数据表格变成粉色-这个粉红色在excel表中怎么设置出来,参数值~...
  14. 日企抛等离子淘汰论 专家称其不敌中国企业
  15. 如何高效地获取、收集和整理信息
  16. Qtum量子链发布QIP-19支持隐私资产技术提案
  17. C#删除word页眉页脚和最后一页
  18. JavaEE——SSM框架整合实现学生信息注册案例
  19. linux 内存 参数,linux free命令参数及用法详解(linux查看内存命令)
  20. 常见问题汇总:FLUENT面数据处理

热门文章

  1. app上架vivo应用商店流程
  2. 2023最新显卡天梯图 2023显卡天梯排行榜 显卡天梯图2023年1月
  3. 智能眼镜的两种显示方式
  4. 人脸识别智能门禁的安全性
  5. 2022年济南市施工员(市政工程)考试练习题及答案
  6. html获取拼音首字母排序,html select按汉字拼音排序
  7. SpringSecurity 403 forbidden
  8. 微信小程序中使用第三方库的方法
  9. Assertion failed: Protocol wrong type for socket [10041] zeromq 4.3.1\src\ip.cpp:417)错误
  10. js之win10计算器