资源描述
程序设计基础课程设计设计题目:仓库物资管理系统
班级:网络0901班姓名:水土第一
学号:20091221***完成日期:2010-9-9
考前须知:免积分下载,还请亲们给个好评。思密达
void find_l() ;//4. 1void find_2();//4. 2
void find_3();//4. 3void f ind_4();//4. 4
void f ind 5() ; //5. 1void f ind_6 () ; //5. 2
void find_7() ;//5.3void find_8() ;//5.4
void load」();//读 stu_list_l 中的数据void main ()
(
int i, j ;
pr intf (z,what do you want to do?\nplease input the number according to the explaination. \nz,);
for(i=l;i<12;i++)printf(/zif you input %d; then i t will work out the %d. \n/z, i, i);
printf (/zIf you are first use it, please input 1, 2 or 3. \nNow please input the number:\n〃);
scanf&j);
swi tch (j)
(
case l:scan_l();save_l();break;//I
case 2:scan2();save_2();change_l();break;//2
case 3:scan_3();save_3();change_2();break;//3
case 4:find_l();break;//4. 1
case 5:f ind_2();break;//4. 2
case 6:find_3();break;//4. 3
case 7:f ind_4();break;//4. 4
case 8:f ind 5 0;break;//5. 1
case 9:find_6();break;//5. 2
case 10:find_7();break;//5. 3
case 11:find_8();break;//5. 4
defaul t: printf (,,error\n/,);
)}
void scan」()〃输入库存{
int i ;
printf ("'please input the information : \n/z);
for(i=0;i<SIZE;i++)
(
scanf (z,%s%s%s%d%fstu_l [i]. name, stu_l [i]. brand, stu_l [i]. style, & stu_l[i]. num, &stu_l[i].money);
))
void scan_2()〃输入入库信息(
int i ;
printf (〃请输入物资入库信息:\n〃);
for(i=0;i<SIZE;i++)
scanf (,,%s%s%s%d%f%d%d%d%s//, stu 2 [ i ]. name, stu 2 [ i ]. brand, stu 2 [ i ] .style, &stu_2 [ i ]. num, &,stu_2 [ i ]. money, &stu_2 [ i ]. time, year, &stu_2 [ i ]. time, month, &stu_2 [i]. time, day, stu_2 [i]. stuf);)
void scan_3。〃输入出库信息
int i ;
pr intf (〃请输入出库信息:\n〃);
for(i=0;i<SIZE;i++)
(
scanf (,,%s%s%s%d%d%d%d%s,,, stu_3 [ i ]. name, stu_3 [ i ]. brand, stu_3 [ i ]. s tyle, &stu_3 [ i ]. num, &stu_3 [ i ]. time, year, &stu_3 [i]. time, month, &stu_3 [ i]. time, day, stu_3[i].stuf);
)
for(i=0;i<SIZE;i++)
(
if(strcmp(stu_l[i]. name, stu_3[i]. name)==0&&strcmp(stu_l[i].brand ,stu_3[i]. brand)==0&&strcmp(stu_l[i]. style,stu_3[i].style)==0)
if(stu_3[i]. num>stu_l[i].num) (printf (z,the error number, please input again\n〃);
scanf (,,%s%s%s%d%d%d%d%s,,, stu_3 [ i ]. name, stu_3 [ i ]. brand, stu_3 [ i ]. s tyle, &stu_3 [i]. num, &stu_3 [i]. time, year, &stu_3 [i ]. time, month, &stu_3 [ i]. time, day, stu_3[i].stuf);)
})
void save」。//将库存信息保存成文件{
FILE *fp;
int i;
if((fp=fopen(〃stu_ltxt",〃wb〃))二二NULL)printf ("connot open the file\n〃);
return;
)
for(i=0;i<SIZE;i++)
(if(fwrite(&stu_l[i],sizeof (struct goods), 1,fp)! = 1) pr intf (^f i le write error\n,z);
)
fclose(fp);)
void save_2。//将入库信息保存成文件(
FILE *fp;
int i ;
if((fp=fopen(〃stu_list_2.txt”,〃wb〃))二二NULL)
(pr intf ("connot open the f i 1 e\nz,);
return;
}
for(i=0;i<SIZE;i++)
(if(fwrite(&stu2[i], s i zeof(struc t entrance), 1, fp) !=1) printf("file write error'n");
)
fclose (fp);)
void change」。//入库时电器数量增加,并将信息加入库存文件
int i ;
load_l ();
for(i=0;i<SIZE;i++)
(
if(strcmp(stu_l[i]. name, stu_2[i].name)==0&&strcmp(stu_l[i].brand ,stu_2[i]. brand)==0&&strcmp(stu_l[i]. style,stu_2[iL style)==0)(
stu_l[i].num=stu_l[i].num+stu_2[i].num;}
}
save_l ();}
void save_3()〃将出库信息保存成文件{
FILE *fp;
int i;
if((fp=fopen(,,stu _list_3. txt〃,〃wb〃))==NULL)
(pr intf ("connot open the f i 1 e\n,z);
return;
)
for(i=0;i<SIZE;i++)
(if(fwrite(&stu_3[i], sizeof(struct exit), 1, fp)! = 1)
pr intf (*f i le write error\n,/);
}
fclose (fp);void change_2。//出库时电器数量减少,并将信息加入库存文件
int i;
load l ();
for(i=0;i<SIZE;i++)
(
if(strcmp(stu_l[i]. name, stu_3[i]. name)==0&&strcmp(stu_l[i].brand ,stu_3[i].brand)==0&&strcmp (stu_l[i].style, stu_3[i].style)==0)(
stu 1[i].num=stu 1[i].num-stu 3[i].num;)
)
save_l ();)
FILE* open」。//翻开库存记录(
FILE *fp;
if((fp=fopen(^stu_list_l. txt〃,〃rb〃))二二NULL)
(printf (^connot open the file!\n〃);
return NULL;
}
return fp;)
FILE* open_2 ()//翻开入库记录
FILE *fp;
if ((fp=fopen (,zstu_l ist_2. txt”, 〃rb〃))二二NULL)printf ("connot open the file!\n〃); return NULL;
)
return fp;)
FILE* open_3。//翻开出库记录{
FILE *fp;
if((fp=fopen(,,stu list_3. txt", "rb"))二二NULL)
(printf (^connot open the file!\n〃); return NULL;
}
return fp;)
void find 1()〃完成4.1(
FILE *fp=NULL;
int i ;
char name [ 10];
fp=open_l ();
pr intf ("please input the name : \n,z) ; //4. 1
scant("%s”, name);
printf (zzthe information of the good : \nz,);
for(i=0;i<S!ZE;i++)
(在库
在库
if(fread (&stu_l[i],si zeof (struct goods), 1, fp)==1)//4. 1存记录之中查找
i f(strcmp(name,stu_l[i].name)==0)
pr intf (,z%s %s %s %d %. 2f\n,z, stu 1 [i]. name, stu 1 [i]. brand, stu 1 [i].style,stu_l[i].num, stu_l[i]. money);
)}
)
fclose (fp);)
void find_5()//完成5. 1(
FILE *fp二NULL;
int i ;
int sum=0;
char name [10];
fp=open_l ();
pr intf (z/please input the name : \n〃); 〃5. 1
scanf(〃%s〃,name);
pr intf (,/ the information of the good:\n〃);
for(i=0;i<SIZE;i++)
(
if(fread(&stu_l [i], sizeof(struct goods), 1, fp)==l)//5. 1 在库 存记录之中查找if(strcmp(name, stu_l[i].name)==0)
sum=sum+stu_l[i].num;
)
printf(,zthe number of this %s i s %d. name [10], sum);
fclose (fp);}
void find_2O〃完成4. 2{
FILE *fp=NULL;
i n t i;
char brand [10];
pr intf (''please input the brand : \n〃); 〃4. 2 scanf(〃%s〃,brand);
fp=open_l ();
for(i=0;i<SIZE;i++)( if(fread(&stul[i],sizeof(struct goods),1,fp)==1)//4.2
{
i f(strcmp(brand,stu_1[i].brand)==0) (printf (/zthe information of the good : \nz/);
pr i ntf (,z%s %s %s %d %. 2f\n,z, stu 1 [i]. name, stu _1 [i]. brand, stul [i ].style,stu_l[i].num, stu_1[i]. money);)
)
}
fclose (fp);}
void find_3()〃完成4. 3(
int i ;
FILE *fp2=NULL, *fp3=NULL;
int year,month,day;
pr intf (,zplease input year, month, day, then find the exit and entrance:Xn^);//4.3
scanf ("%d%d%d”,&year, &month, &day);
fp2=open_2();
fp3=open 3();
pr intf (zzthe information of entrance is:\n〃);
for (i=0;i<SIZE;i++)
(
if (fread (&stu_2 [i], si zeof (struct entrance), 1, fp2) ==1)//读出入 库信息(
if ((stu_2 [i]. time. year==year) && (stu_2 [i]. time, month==month) && (st u_2 [ i ]. time. day==day)) 〃入库 信息4. 3(
pr intf (//%s %s %s %d %. 2f %d %d %d %s\n/z, stu2[i]. name, stu2[i]. b rand,stu 2[i].style,stu 2[i].num,stu 2[i]. money,stu _2[i].time.year, stu_2[i]. time, month, stu_2[i]. time, day, stu_2[i]. stuf);)
)
}
pr intf (/z the information of exit is:\n〃);课程设计目的和要求2
1.1 课程设计的目的:2
1.2 课程设计的要求:2课程设计任务内容:2
2 详细设计说明3
2.1 功能模块图:3
2.2 数据结构设计:4
2.3 功能模块设计:5软件使用说明:6
3 课程设计心得与体会:6参考文献:7
4 附录:局部程序清单:7
for (i=0;i<SIZE;i++)if (fread (&stu_3 [i], s i zeof (struct exit), 1, fp3) ==1) //读出出库信
息(
if ((stu_3 [i]. time. year==year) && (stu_3 [i]. time. month==month) && (st u_3 [i]. time. day==day))//出库信息4. 3(
pr intf (z/%s %s %s %d %d %d %d %s\nz,, stu 3 [i]. name, stu 3 [i]. brand, stu_3[i]. style, stu_3[i]. num,stu_3[i].time.year,stu_3[i].time.month, stu_3[i]. time, day, stu_3[i]. stuf);)
)
)
fc1ose(fp2);
fclose (fp3);}
void find_4()〃完成4. 4{
int i ;
FILE *fp2=NULL,*fp3=NULL;
char name[10],style[10];
pr intf (z,please i nput the name and style of the goods, then find the entrance and exit: \n,z) ; //4. 3
scanf(〃%s%s〃,name,style);
fp2=open_2 ();
fp3=open_3 0;
pr intf (zzthe entrance information of the good is:\n〃);
for (i=0;i<SIZE;i++)//4. 4
(
if (f read (&stu_2 [i], sizeof (struct entrance), 1, fp2)==l)〃读出入 库信息{
if ((stremp (stu_2 [i]. name, name)) ==0&& (stremp (stu_2 [i]. style, style ))==0)//入库信息4. 4(
pr intf (z,%s %s %s %d %f %d %d %d %s\n,z, stu_2[i]. name, stu_2[i]. bra nd, stu_2[iL style,stu_2[i].num,stu_2[i].money,stu_2[i].time.year,st u_2[i]. time, month, stu_2[i]. time, day, stu_2[i]. stuf);)
)
}
pr intf (z,the ex i t information of the good is:\n〃);
for(i=0;i<SIZE;i++)//4. 4
(
if (fread (&stu_3 [i], s i zeof (struct exit), 1, fp3)==l)//读出出库信 息(
if ((stremp (stu_3 [i]. name, name)) ==0&& (stremp (stu_3 [i]. style, style ))==0)//出库信息4.4
pr intf (/z%s %s %s %d %d %d %d %s\n/z, stu_3[i]. name, stu_3[i]. brand, stu_3 [i]. style, stu_3 [i]. num, stu_3 [i]. time, year, stu_3 [i]. time, month, stu_3[i]. time, day,stu_3[i].stuf);}
)
)
fclose (fp2);
fclose (fp3);)
void find_6O〃完成5. 2(
i n t i;
int sum=0;
FILE *fp=NULL;
char name [10];
pr intf (/zplease input the name of the good, then output the number of its entrance : \ n/z) ; //5. 2
scanf("%s”, name);
fp=open_2 ();
for(i=0;i<SIZE;i++)
(
if (fread (&stu_2 [i], sizeof (struct entrance), l,fp)==l)//读 出入库 信息(
i f ((strcmp (stu 2 [ i ]. name, name)) =0) //入库信息 4. 4(
sum=sum+stu_2[i].num;}
pr intf (zzthe number of the goods, entrance is %d. \n”, sum);
fclose (fp);)
void find_7()//完成5. 3(
int i ;
int sum=0;
int year,month;
FILE *fp=NULL;
printf ("please input year and month,then output the number of exit in this month : \n,z) ; //5. 3
scanf&year,&month);
fp=open_3 ();
pr intf (z/the number of exit good in this month is:〃);
for(i=0;i<SIZE;i++)//5. 3在出库记录文件中统计该月的出库记录次数。
(if((fread(&stu 3[i], sizeof(struct exit), 1, fp)==1))
i f(stu _3[i]. t i me. year==year&&stu _3[i].t i me.month==month)(
sum=sum+1;)
)
printf(〃%d\n〃,sum);
fclose (fp);)
void find_8()〃完成5. 4!
int i,j ;
FILE *fp=NULL;
pr intf (''please input the red number, then output all the informations of the goods:\n");
getchar ();
scanf(〃%d〃,&j);
fp=open 1 ();
for(i=0;i<SIZE;i++)//5. 4输出库存数量小于该警戒值的所有库存电器的 信息( if((frcad(&stu_l[i],sizeof(struct goods),1,fp)==1)) (
i f (s tu 1[i].num<j)(
pr intf the information of the good are : \nz,);
pr intf (,z%s %s %s %d %. 2f\n?z, stu_l [i]. name, stu_l[i]. brand, stu_l[i].style, stu l[i]. num, stu l[i].money);
}}
)
fclose (fp);)
void load」()〃读stu」ist_l中的数据(
FILE *fp=NULL;
fp = open_l ();
fread (stu_l, sizeof (struct goods), SIZE, fp);
fclose (fp);}附录资料:不需要的可以自行删除
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 introducedC语言详解-枚举类型
注:以下全部代码的执行环境为VC++ 6.0在程序中,可能需要为某些整数定义一个别名,我们可以利用预处理指令#define来完成 这项工作,您的代码可能是:
#define MON I#define TUE 2
#define WED 3#define THU4
#define FRI5#define SAT6
#define SUN7在此,我们定义一种新的数据类型,希望它能完成同样的工作。这种新的数据类型叫枚 举型。
I.定义一种新的数据类型-枚举型
以下代码定义了这种新的数据类型一枚举型enum DAY
{
MON=1, TUE, WED, THU, FRI, SAT, SUN);
(I)枚举型是一个集合,集合中的元素•(枚举成员)是一些命名的整型常量,元素之间用逗 号,隔开。
(2) DAY是一个标识符,可以看成这个集合的名字,是一个可•选项,即是可有可无的项。
(3)第一个枚举成员的默认值为整型的0,后续枚举成员的值在前一个成员上加lo(4)可以人为设定枚举成员的值,从而自定义某个范围内的整数。
(5)枚举型是预处理指令#define的替代。
(6)类型定义以分号;结束。
2 .使用枚举类型对变量进行声明新的数据类型定义完成后,它就可以使用了。我们已经见过最基本的数据类型,如:整 型int,单精度浮点型float,双精度浮点型double,字符型char,短整型short等等。用这 些基本数据类型声明变量通常是这样:
char a; 〃变量a的类型均为字符型charcharletter;
intx,y,
z; 〃变量x,y和z的类型均为整型intintnumber;
double m, n;double result; 〃变量result的类型为双精度浮点型double
既然枚举也是一种数据类型,那么它和基本数据类型一样也可以对变量进行声明。
方法一:枚举类型的定义和变量的声明分开cnuin DAY
|
MON=1, TUE, WED, THU, FRI, SAT, SUNI;
enum DAY yesterday;enum DAY today;
enum DAY tomorrow; 〃变量 tomorrow 的类型为枚举型 enum DAYenuin DAY good_day, bad_day;//变量 good_day 和 bad_day 的类型均为枚举型 enum DAY 方法二:类型定义与变量声明同时进行:
enum 〃跟第一个定义不同的是,此处的标号DAY省略,这是允许的。
Saturday, sunday = 0, mo nd ay, tuesday, Wednesday, thursday, friday} workday; 〃变量workday的类型为枚举型enum DAY
enum week { Mon= 1, Tue, Wed, Thu, Fri Sat, Sun } days; 〃变量 days 的类型为枚举型 enum weekenum BOOLEAN { false, true } end_flag, match_flag; 〃定义枚举类型并声明了两个枚举 型变量
方法三:用typedef关键字将枚举类型定义成别名,并利用该别名进行变量声明: typedef enuin workday {Saturday, sunday = 0, mo nd ay, tuesday, Wednesday, thursday, friday
} workday; 〃此处的workday为枚举型enum workday的别名workday today, tomorrow; 〃变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday
enum workday 中的 workday 可以省略:
typedef enum {Saturday, sunday = 0, monday, tuesday, Wednesday, thursday, friday
} workday; 〃此处的workday为枚举型enum workday的别名 workday today, tomorrow; 〃变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday也可以用这种方式:
typedef enum workday
Saturday,
sunday = 0,
mo nd ay,
tuesday,
Wednesday,
thursday,
friday workday today, tomorrow; 〃变量 today 和 tomorrow 的类型为枚举型 workday,也即 enum workday注意:同一个程序中不能定义同名的枚举类型,不同的枚举类型中也不能存在同名的命 名常量。错误例如如下所示:
错误声明一:存在同名的枚举类型typedef enum |
Wednesday, thursday, friday} workday;
typedef enuin WEEK {Saturday, sunday = 0, monday,
} workday;错误声明二:存在同名的枚举成员
typedef enum {
Wednesday,
ihursday,
friday } workday_l;typedef enum WEEK
(
Wednesday,
sunday = 0, monday, } workday_2;.使用枚举类型的变量
2.1 对枚举型的变量赋值。
实例将枚举类型的赋值与基本数据类型的赋值进行了比照:
方法一:先声明变量,再对变量赋值#include<stdio.h>
/*定义枚举类型*/enum DAY { MON=1, TUE, WED, THU, FRI, SAT, SUN };
void main() {
/*使用基本数据类型声明变量,然后对变量赋值*/ int x, y, z;
x = 10;1课程设计目的和要求
1.1 课程设计的目的:
通过一个学年的学习,对《C程序设计》这门课程之中所讲的知识有了一定的 了解。但是作为一名合格的大学生,不仅要认真阅读课本知识,还要通过上机 实践来增强和巩固自己的知识。特别是作为工科类学生,更要注重实践这一环 节。因为只有这样我们才能成为合格的计算机人材。
1.2 课程设计的要求:
在实践过程之中,重要的是独立思考,这样,不仅有利于提高自己对知识的理 解,还更有助于提高自己的实践动手能力。与此同时,还应该注意主动与别人 交流,这样便有利于就业之后与团队进行合作。
2课程设计任务内容:
仓库管理系统是各个大型商店进行管理的重要组成局部,其内容较多,为了满 足工作需求,要求设计的管理系统能够完成以下五种功能:
1 .创立库存记录文件。根据提示输入假设干电器的“电器名称、品牌名称(或 生产厂家)、型号、库存数量、价值”等信息、,并将信息保存至一个文件中。
2 .物资入库管理,创立一个入库记录文件,每次有物资入库,那么按入库记 录要求输入“电器名称、品牌名称、型号、入库数量、单价、入库时间(年. 月.日)、送货人姓名”等信息,并将该次的入库信息添加到文件中,同时修 改相应的库存记录文件。
3 .物资出库管理,创立一个出库记录文件,每次有物资出库,那么按出库记 录要求输入各项信息,并将该次的出库信息添加到文件中,同时修改相应的库 存记录文件。在此过程之中,检查出库数量的合法性(即出库数量必须小于库
y = 20;
z = 30;/*使用枚举类型声明变量,再对枚举型变量赋值*/ enum DAY yesterday, today, tomorrow;
yesterday = MON;
today = TUE;
tomorrow = WED;
printf("%d %d %d \n", yesterday, today, tomorrow);I
方法二:声明变量的同时赋初值#include <stdio.h>
/*定义枚举类型*/enum DAY { MON=1, TUE, WED, THU, FRI, SAT, SUN };
void main()(
/*使用基本数据类型声明变量同时对变量赋初值*/ in( x=10, y=20, z=30;/*使用枚举类型声明变量同时对枚举型变量赋初值*/ enum DAY yesterday = MON,
today = TUE,
tomorrow = WED;
printf("%d %d %d \n'\ yesterday, today, tomorrow);)
方法三:定义类型的同时声明变量,然后对变量赋值。
#includc <stdio.h>/*定义枚举类型,同时声明该类型的三个变量,它们都为全局变量*/
enum 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); 〃输出:10 20 30
printf("%d %d %d \n", yesterday, today, tomorrow); 〃输出:12 3 )方法四:类型定义,变量声明,赋初值同时进行。
#include <stdio.h>/*定义枚举类型,同时声明该类型的三个变量,并赋初值。它们都为全局变量*/ enum DAY
{
MON=1,
TUE,
WED,
THU,
FRI,
SAT,
SUN}
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 3|
1.2 对枚举型的变量赋整数值时,需要进行类型转换。
#include <stdio.h>cnum DAY { MON=1, TUE, WED, THU, FRI, SAT, SUN };
void main()(
enum 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 30 I使用枚举型变量
#include<stdio.h>enum
{
BELL= '\a\
BACKSPACE = '\b',
HTAB='\t',
RETURN= '\r\
NEWLINE = '\n\
VTAB=*\v',
SPACEenum BOOLEAN { FALSE = 0, TRUE } matc
展开阅读全文