资源描述
实验设备信息管理系统
题目要求:
实验设备信息包括:设备编号,设备种类(如微机,打印机,扫描仪等),设 备名称,设备价格,设备购入日期,是否报废,报废日期等。试设计一实验 设备信息管理系统,使之能提供以下功能:
1 .能够完成对设备的录入和修改。
2 .对设备进行分类统计。
3 .设备的查询。
需求分析:
实验室设备信息用文件储存,提供文件的输入输出操作;要能够完成设备的录入 和修改工作,需要添加设备的添加和修改操作;实现对设备进行分类统计,需要 提供排序操作;实现对设备的查询需要提供查找操作,设备的查询可根据设备编 号,设备种类,设备名称,设备购入日期等多种方式查询;另外还要提供键盘式 选择菜单以实现选择功能。
总体设计:
试验设备信息添加输入模块,试验设备信息修改模块,实验设备信息统计模块和 试 验 设 备 信 息 杳询 模块。
建立试验近看福息结构体,结构体成员包括设备编号,设备种类,设备名称,设 备价格,设备购入日期,是否报废,报废日期。
我的程序设计如下:
^include <s tdio. h> ^include <s tdlib. h> ^include <s tring. h> ^define N 50 void menu ();void add();
void modify (); void stat();void search (); int load();
struct equipmentchar num[10];
char kind[10];
char name [10];
char money[10];
char num[10];
char kind[10];
char name [10];
char money[10];
/*设备编号*/
/*设备种类*/
/*设备名称*/
/*设备价格*/
char bri thday[10]; /* 设备日期*/
char bf[10];/*是否报废*/
char badday[10];/*报废日期*/
}eup[N], temp;/*返回主函数模块*/ void menu ()
3修改模块流程图
please choice<1-5>:[2]
1001
weiji
we iyi
9999
12.23
shi
12.24
1002
weij i
weier
2222
12.12
shi
12.24
口 003
weiji
weisan
1111
12.12
shi
12.25
1004
we ij i
we iwu
3333
23.22
shi
12.12
1005
jisuan
jier
4444
23.23
shi
12.12
1006
jisuan
jisan
5555
12.12
shi
12.23
1007
jisuan
• • •
J1S1
6666
11.11
shi
12.22
1008
jisuan
jiwu
7777
12.22
shi
12.11
5009
saoniao
saoyi
8888
12.22
shi
12.23
1010
saoniao
saoer
9999
12.23
shi
12.22
2
2
2
2
2
2
2
1
1
1
1
1
1
1
Input the shebei number you want to modify?
The equ numJ)er:1001Find the shebei?
Please input the new infornation:
nun kind name money brithday bf badday修改后程序会弹出如下页面
次查询后可返回杳询模块有可返回主菜单还可退出程序。
-□ X
:\DOCUIE~l\os\桌面\KECHEN~1\新建文~l\kuai,an. exe
Input the shebei number you want to modify?
The equ number:3 sorry neiyou zhaodao! l>.zaici chazhao 2>.fanhui MENU 2]1-tianjia shiyan
2.xiugai3.tongji
4.chaxun5.EXIT
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMplease cho ice<1-5):[41
chazhao yiju:
1〉.shebei number 2〉.kind 3〉.name 4).birthday
1.按编号查找
2 .按种类查找c\ C: \DOCUIE〜l\os\桌面\KECHEN〜1\新建文〜l\kuai・an. exe
The shebei information:
nun
kind name money
brithday
bf
badday
1002
we i j iweier
2222
12.12
shi
12.24
Find
the shebei?
The :
shebei information:
num
kind name money
brithday
bf
badday
1003
we i j iwe is an
1111
12.12
shi
12.25
Find
the shebei?
The :
shebei information:
nun
kind name money
brithday
bf
baddav
1004
we ij i we iwu
3333
23.22
shi
12.12
2>.Back menu []
2>.Back menu []
Successful.A_A.
1>.Search again.按名称查找
QI-OX1004we ij iwe iwu 333323.22 shi 12.12
Successful.A_A. 1).Search again 2).Back menu [1]chazhao yiju:
1).shebei number 2>.kind 3).name 4).birthday [3]print yao chazhao de shebei name? name:jisan
Find the shebei?
The shebei information:
num kind name money brithday bf badday1006 jisuan jisan 555512.12 shi 12.23
Successful.A_A.
1).Search again 2).Back menu []4.按购买日期查找
:\DOCUIE~l\os\桌面\KECHEN~八新建文~l\kuai,an. exe
The shebei information: num kind name money 0,002we i j iweierpind the she加i?
The shebei information: nun kind name money 0.003 we i j i we is an Find the shebei?
The shebei information: num kind name money 1006 jisuan jisanSuccessful.A_A.
1>.Search againbrithday bf
badday
222212.12
shi
12.24
brithday bf
badday
111112.12
shi
12.25
brithday bf
badday
555512.12
shi
12.23
2〉.Back
menu [
]
brithday bf
badday
222212.12
shi
12.24
brithday bf
badday
111112.12
shi
12.25
brithday bf
badday
555512.12
shi
12.23
2〉.Back
menu [
]
每个功能实现后都会有菜单提示,是再次查找还是返回主菜单或是退出系统。
C语言课程设计的心得体会曹肖亮
()21082 班在大二上学期我们学习了 C语言这门课,在上课时,谷淑化老师曾告诉我们C 语言对我们的专业学习有很大的帮助,希望我们能经常上机实习来锻炼实践能 力。C语言是一门实践性比拟强的科目,单纯的理论知识是不行的,所以学校给 了我们这样一次珍贵的实习机会来再次巩固我们的知识。
在这次的学习中我了解到C语言可以写出很多有用的程序,像我们这次所 写的程序可知很多有用的功能都可以用C语言写出来,这说明C语言的用处是 很大的,而且它不仅可以写出有用的程序,还是我们以后学习C++和其他更高级 语言的基础。所以学好C语言对我们每个人是很必要的。
这次学习使我感触最深的就是程序的源代码,明白了为什么新闻上为什么那 么多的人要求某某公司公开某某软件源代码,也明白了为什么那么多的编程天才 热衷于网上编程或完成或完善某某软件源代码。源代码就是一个软件的灵魂,是 一个软件的幕后主角,而且程序与程序之间没有最好,只有最适合;没有最好, 只有更好。
同时.,如果要编写好一个程序,就得必须要有一个良好的架构,即程序的模 版。程序的模版是一个程序好坏的先天条件,我们自己编写程序时,必须得定好 架构然后才去根据流程上的框架,把每一个模版各自编写好。在一个程序的各个 局部都已经完成编写后,就把它们联系起来。但是一个模块可能不是由一个人所 写的,或者是一个简单的程序可以用不同的方法去编写,造成程序的紊乱。于是 需要一个人根据函数的传递关系,把每一个函数串联起来,成为一个程序。
编写一个程序固然重要,但调试程序也有很大的比重,程序的调试也让我在 这一次的实习中用了相当多的时间。用了很多时间直到最后程序调试成功那种愉 悦的心情是让我难以忘记的。
短短几天的实习很快就过完但我想这次实习会给我留下很深的回忆,也让我 了解到了时间的重要性,感谢学校给了我们珍贵的机会,感谢老师对我们的细心 指导,才让我们真正体会到了编程的意思!
附录资料:不需要的可以自行删除Abstract: Based on the comprehensive analysis on the plastic part's structure service requirement, mounding quality and mould menu factoring cost. A corresponding injection mould of internal side core pulling was designed. By adopting the multi-direction and multi-combination core-pulling. A corresponding injection mould of internal side core pulling was designed, the working process of the mould was introduced C语言详解-枚举类型
注:以下全部代码的执行环境为VC++6.0在程序中,可能需要为某些整数定义一个别名,我们可以利用预处埋指令#deHne来完成这 项工作,您的代码可能是:
#define MON I#dcfine TUE 2
#define WED 3#dcfinc THU 4
#define FRI 5#define SAT 6
#define SUN 7在此,我们定义一-种新的数据类型,希望它能完成同样的工作。这种新的数据类型叫枚举型。
1 .定义一种新的数据类型-枚举型
以下代码定义了这种新的数据类型-枚举型enum DAY
{
MON=1, TUE, WED, THU, FRI, SAT, SUN);
(I)枚举型是一个集合,集合中的元素(枚举成员)是一些命名的整型常量,元素之间用逗号, 隔开。
⑵DAY是一个标识符,可以看成这个集合的名字,是一个可选项,即是可有可无的项。
(3)第一个枚举成员的默认值为整型的0,后续枚举成员的值在前一个成员上加I。
(4)可以人为设定枚举成员的值,从而自定义某个范围内的整数。
(5)枚举型是预处理指令#dcfine的替代。
(6)类型定义以分号;结束。
2 .使用枚举类型对变量进行声明新的数据类型定义完成后,它就可以使用了。我们已经见过最基本的数据类型,如:整型皿, 单精度浮点型float,双精度浮点型double,字符型char,短整型short等等。用这些基本数据 类型声明变量通常是这样:
char a; 〃变量a的类型均为字符型charcharletter;
int x,y,
z; 〃变量x,y和z的类型均为整型intini number;
double m. n;double result; 〃变量result的类型为双精度浮点型double
既然枚举也是一种数据类型,那么它和基本数据类型一样也可以对变量进行声明。
方法一:枚举类型的定义和变量的声明分开enum DAY
MON= I, TUE, WED, THU, FRI, SAT, SUN enum DAY yesterday;enum DAY today;
cnum DAY tomorrow; 〃变量 tomorrow 的类型为枚举型 cnum DAYenum DAY good_day, bad_day; 〃变量 good_day 和 bad_day 的类型均为枚举型 enum DAY 方法二:类型定义与变量声明同时进行:
enum〃跟第一个定义不同的是,此处的标号DAY省略,这是允许的。 {Saturday, sunday = 0, monday. tucsday, Wednesday, thursday, Friday
} workday; //变量workday的类型为枚举型enum DAYenum week { Mon=l, Tue, Wed, Thu, Fri Sat, Sun} days; 〃变量 days 的类型为枚举型 enum week
cnum BOOLEAN { false, true } cnd_flag, match_flag; 〃定义枚举类型并声明了两个枚举型变 量方法三:用typedef关键字将枚举类型定义成别名,并利用该别名进行变量声明: (ypedef enum workday {
Saturday, sunday = 0, monday, tuesday, Wednesday, thursday, friday} workday; 〃此处的workday为枚举型enum workday的别名 workday today, tomorrow; //变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday
enum workday 中的 workday 可以省略:
(ypedef enum {Saturday, sunday = 0, monday, tuesday, Wednesday, thursday,
friday} workday; 〃此处的workday为枚举型enum workday的别名
workday today, tomorrow; 〃变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday也可以用这种方式:
(ypedef enum workday {
Saturday,
Sunday = 0,nionday, tuesday, Wednesday, thursday, friday
I;workday today, tomorrow; 〃变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday
注意:同•个程序中不能定义同名的枚举类型,不同的枚举类型中也不能存在同名的命名常 量。错误例如如下所示:
错误声明一:存在同名的枚举类型typedef enum {
Wednesday,
thursday, friday } workday;typedef enum WEEK (
Saturday,
sunday = 0, monday, } workday;错误声明二:存在同名的枚举成员
typedef enum puts11t************************MENU*************************\n\n ” );
puts(^\t\t\t\t 1. tianjia shiyan ");
putsC\t\t\t\t 2. xiugai");
puts (^\t\t\t\t 3. tong Ji ;
puts(^\t\t\t\t 4. chaxun');
puts(^\t\t\t\t 5. EXIT");puts ("\n\n\t\t****************************************************** ****\n^);
printf ("please choice(1-5):[ ]\b\b"); scanf("%d", &n);
swi tch (n)case 1: add (); break;
case 2:modi fy (); break;case 3:stat();break;
case 4: search () ;break;
case 5:exit(0); default: menu ();
)) void main ()/*主函数*/
(
menu ();
getchO ;)
/*追加模块*/void add()
(
int i;
FILE *fp;
fp=fopen(^eup. txt", W);
if ((fp=fopen Ceup. txt * "a")) =NULL)
( , ,printf ("cannot open file \n^);
printf C\nshuru:num | tkind\tname | tmoney | tbrithday | tbf\ tbadday \n ");
Wednesday,thursday, friday
} workday」;(ypedef enum WEEK
{
Wednesday,
sunday = 0, monday, } workday_2;3.使用枚举类型的变量
3.1 对枚举型的变量赋值。
实例将枚举类型的赋值与基本数据类型的赋值进行了比照:
方法一:先声明变量,再对变量赋值#include<stdio.h>
/*定义枚举类型*/cnum DAY { MON=1,TUE, WED, THU, FRI, SAT, SUN };
void main() {
/*使用基本数据类型声明变量,然后对变量赋值*/
int x, y, z;
x= 10;
y = 20;
z = 30;
/*使用枚举类型声明变量,再对枚举型变量赋值*/
enum DAY yesterday, today, tomorrow;
yesterday = MON;
today = TUE;
tomorrow = WED;
printf("%d %d %d \n", yesterday, today, tomorrow);方法二:声明变量的同时赋初值
#include <stdio.h>/*定义枚举类型*/
enum DAY { MON=1,TUE, WED, THU, FRL SAT, SUN };void main()
{
/*使用基本数据类型声明变量同时对变量赋初值*/
int x= 10, y=20, z=30;
/*使用枚举类型声明变量同时对枚举型变量赋初值*/
enum DAY yesterday = MON,
today = TUE, tomorrow = WED;
printf("%d %d %d \n'\ yesterday, today, tomorrow);I
方法三:定义类型的同时声明变量,然后对变量赋值。
#include <stdio.h>/*定义枚举类型,同时声明该类型的三个变量,它们都为全局变量*/
cnum DAY { MON=1, TUE, WED, THU, FRI, SAT, SUN } yesterday, today, tomorrow;/*定义三个具有基本数据类型的变量,它们都为全局变量*/
int x, y, z;void main()
{
/*对基本数据类型的变量赋值*/
x= 10; y = 20; z = 30;
/*对枚举型的变量赋值*/
yesterday = MON;
today = TUE;
tomorrow = WED;
printf("%d %d %d \n", x, y, z); 〃输出:1020 30
printf("%d %d %d \n", yesterday, today, tomorrow); 〃输出:12 31
方法四:类型定义,变量声明,赋初值同时进行。
#include <stdio.h>/*定义枚举类型,同时声明该类型的三个变量,并赋初值。它们都为全局变量*/
cnum DAY{
MON=1,
TUE,
WED,
THU,
FRI,
SAT,
SUN1
yesterday = MON, today = TUE, tomorrow = WED;/*定义三个具有基本数据类型的变量,并赋初值。它们都为全局变量力
int x = 10, y = 20, z = 30;void main()
{
printf("%d %d %d \n'; x, y, z); 〃输出:10 20 30
printf("%d %d %d \n", yesterday, today, tomorrow); 〃输出:1 2 31
3.2 对枚举型的变量赋整数值时,需要进行类型转换。
#include <stdio.h>enum DAY { MON=I,TUE, WED, THU, FRI, SAT, SUN };
void main(){
cnum DAY yesterday, today, tomorrow;
yesterday = TUE;
today = (enum DAY) (yesterday + 1); 〃类型转换
tomorrow = (enum DAY) 30; 〃类型转换
//tomorrow = 3; 〃错误
printf("%d %d %d \n'\ yesterday, today, tomorrow); 〃输出:2 3 301
3.3 使用枚举型变量#include<stdio.h> enum
BELL= '\a',
BACKSPACE = '\b',
HTAB= '\t',
RETURN=V,
NEWLINE = *\n',
VTAB= '\v;
SPACE="I;
enum BOOLEAN { FALSE = 0, TRUE } match_flag;void main()
{
int index = 0;
int count_oflletter = 0;
int count_oCspace = 0;
char str(] = "I'm Ely cfod*';
match_flag = FALSE;
for(; str[index] != 10'; index++)if( SPACE != str[indcxj) count_oUetter++;
else(
match_flag = (enum BOOLEAN) 1; count_of_space++;}
printf("%s %d times %c", match_flag ? "match": "not match", count_oflspace, NEWLINE); printf("count of letters: %d %c%c", count_of_lcttcr, NEWLINE, RETURN);1
输出:
match 2 timescount of letters: 10
Press any key to continue4.枚举类型与sizcof运算符
#inckide <stdio.h> enum escapes
BELL= '\a;
BACKSPACE = '\b',HTAB= '\t',
RETURN = NEWLINE ='\n', VTAB= '\v',
SPACE="I;
enum BOOLEAN { FALSE = 0, TRUE } match_flag;void main() { prin(f("%d bytes \n", sizeof(enum escapes)); //4 bytes printf("%d bytes \n", sizeof(escapes)); //4 bytes
printf("%d bytes \n", sizeof(enum BOOLEAN)); //4 bytes printf("%d bytes \n", sizeof(BOOLEAN)); //4 bytes prinif("%d bytes \n", sizeof(match_nag)); //4 bytes
prin(f("%d bytes \n", sizeof(SPACE)); //4 bytes printf("%d bytes \n", sizeof(NEWLINE)); //4 bytes printf("%d bytes \n", sizcof(FALSE)); //4 bytes prinif("%d bytes \n", sizeof(0)); //4 bytes ) 5.综合举例#include<stdio.h>
enum Season { spring, summcr=100, fali=96, winter 1;lypedef enum {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 1 Weekday;void main()
/* Season */
printf(n%d \n", spring); // 0
printf("%d, %c \n", summer, summer); // 100, d
printf("%d \n", fall+wintcr); // 193
Season myScason=wintcr;
if(winter==my Season)printf("inySeason is winter \nM); // mySeason is winter
int x=100;
if(x==sumrner)printf("x is equal to sununer\n"); // x is equal to summer
prin(f("%d bytes\n'\ sizeof(spring)); // 4 bytes
/* Weekday */
printf("sizeof Weekday is: %d \n", sizeof(Weekday)); //sizeof Weekday is: 4
Weekday today = Saturday;
Weekday tomorrow;
if( today == Monday)tomorrow = Tuesday;
elsetomorrow = (Weekday) (today + 1); //remember to convert from int to Weekday
本文来自CSDN--xiaobai32966博客
scanf("%s 二 temp, num); scanf("%s 1 temp, kind); scanf("%s ”, temp, name); scanf('%s 二 temp, money); scanf('%s ”, temp, bri thday); scanf('%s 二 temp, bf); scanf ("%s”, temp, badday);fprintf(fp, \t%s | t%s | t%s | t%s | t%s | t%s”, temp, num, temp, kind, temp. na me, temp, money, temp, bri thday, temp, bf, temp, badday);
fclose (fp);
printf C\n \n | tSuccessful.[; prin t f (" \ n********************************************************** ********************* \n^);
printf^What do you want to do?\n\n^);
printf(^\ tl. Continue to add\t2, Back to main menu \t3. Exit\n^);print f ( " \ n********************************************************** ********************* \n^);
printf(^\n\nlnput your choice。-3);
scanf("%d", &i);add();
)
if(i==2)
(menu ();
) if(i==3)
(exi t(0);
/*修改模块*/ void modify ()(
FILE *fp;
int n, k=0, b, c, i, e;
char a[10];
n=load();
for(i=0;i<n;i++) prin tf(〃%s \t%s | t%s \t%s | t%s | t%s | t%s \n ”, eup[i]. num, eup[i]. kind, eup[i]. name, eup[i]. money, eup[i]. bri thday, eup[i], bf, eup[i]. badday);
)
printf C\nlnput the shebei number you want to modify! \n \nThe equ number:;
scanf( "%s 二 a);
for (i =0; i <n; i++)
if(strcmp (a, eup[i]. num) ==0)/*查找要修改的设备信息*/
(k=l;
c=i;break;
)
if(k=O)
( , ,printf(^\n \nsorry meiyou zhaodao!");
prin tf C\ tl), zaici chazhao2). fanhui MENU □ \b\b");scanf( &b);
if(b==l) {modi fy ();}if(b==2) {menu() ;}
)
if(k==l)
(printf(^\nFind the shebei! \n^);
printf (^\nPlease input the new information: \n");printf(^\nnum kind name money brithday bf badday\n");
scanf('%s ”, eup[c]. num);scanf("%s ”, eup[c]. kind);
scanf eup[c]. name);scanf('%s ”, eup[c]. money);
scanf("%s”, eup[c], brithday);scanf('%s ”, eup[c]. bf);
scanf (3s Z eup[c]. badday);
)
fp=fopen(^eup. txt",“心;
for (i=0; i <n; i++)
(fprintf (fp, "%s | t%s | t%s | t%s | t%s | t%s | t%s \n”, eup[i]. num, eup[i]. kind, eup
[i]. name, eup[i]. money, eup[i], brithday, eup[i]. bf, eup[i], badday);
)
fclose (fp);
printf("\n \n| tSuccessful. \^\n\n^);printf(^\ n********************************************************** ********************* |/7 );
printf(MWhat do you want to do?\n\n^);
print f('\ tl. Continue to modify 112. Back to main menu 113. Exi t\n^);printf ("\n**********************************************************
*********************\nV ;
printf(^\n \nlnput your choice (1-3);
scanf("%d", &e);
if(e=l)modify ();
if(e=2)menu ();
)
if(e==3)exi t(0);
)}
/*分类统计模块*/void stat ()
(
int n, i;
FILE *fp;
fp=fopen(^eup. txt”, V9;
if ((fp=fopen Ceup. txt * "r")) =NULL) (printf ("cannot open file \n^);
)
while (Ifeof(fp)) fscanf(fp, %s %s %s %s %s %s”, temp, num, temp, kind, temp, name, temp ・ money, temp, bri thday, temp, bf, temp, badday);printf(^\n%s| t%s|t%s| t%s\t%s| t%s| t%s\ temp. num, temp, kind, temp, name, t emp. money, temp, bri thday, temp, bf, temp, badday);
fclose (fp);
menu ();)
/*查找模块*/void search ()
{
int i, n, k=-lf wl, w2, w3;
char c[10];
n=load();
print
展开阅读全文