| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 544 人关注过本帖
标题:小的库存系统
只看楼主 加入收藏
jiangchuanze
Rank: 2
等 级:论坛游民
帖 子:8
专家分:13
注 册:2012-1-19
收藏
 问题点数:0 回复次数:5 
小的库存系统
inventory.c文件
/****************************************************************************
*Namc:goods inventory management systerm                                    *
*Purpose:Maitains a parts database --array version /using struct            *
*Author:Bennett                                                             *
*Date written:2/1/2012                                                      *
****************************************************************************/
#include<stdio.h>
#include "read_line.h"
 
#define NAME_LEN 25
#define MAX_PARTS 100
 
struct part{
    int number;
    char name[NAME_LEN+1];
    int on_hand;
}inventory[MAX_PARTS];
 
int num_parts=0; /*number of parts currently stored*/
 
int find_part(int number);
 
/*four fuction in the program*/
void insert(void);
void search(void);
void update(void);
void print(void);
 
 
/*****************************************************************************/
int main(void){
    char code;
   
    for(;;){
        printf("Enter operation code: ");
        scanf(" %c",&code);
        while(getchar()!='\n')  /*skips to the end of line*/
        ;
        switch(code){
 
            case 'i':insert();
                break;
            case 's':search();
                break;
            case 'u':update();
                break;
            case 'p':print();
                break;
            case 'q':return 0;
            default:printf("Illegal code\n");
}
printf("\n");
printf("Enter 'i': insert,'s':search,'u':update,'p':print,'q':exit \n");
}
 
}
 
 
/********************************************************************************
*find_part:Looks up a part number in the inventory array.Returns the array index*
*          if the part number is found;otherwise ,returns -1;                   *
********************************************************************************/
 
 
int find_part(int number){
    int i;
   
    for(i=0;i<num_parts;i++){
        if(inventory[i].number==number)
            return i;
}
return -1;
}
 
 
 
/********************************************************************************
*insert:prompts the user for information about a new part and then inserts the  *
*       part into the database.prints an error message and returns prematurely  *
*       if the part already exists or the database is full                      *
********************************************************************************/
 
 
void insert(void){
int part_number;
 
if(num_parts==MAX_PARTS){
printf("Database is full ;can`t add more parts.\n");
return;
 
}
printf("Enter the part number: ");
scanf("%d",&part_number);
 
if(find_part(part_number)>=0){
printf("Part already exists.\n");
return;
}
inventory[num_parts].number=part_number;
printf("Enter part name: ");
read_line(inventory[num_parts].name,NAME_LEN);
printf("Enter quantity on hand: ");
scanf("%d",&inventory[num_parts].on_hand);
num_parts++;
}
 
 
/*******************************************************************************
*search:prompts the user to enter a  part number ,then looks up the part in the*
*       database.if the part exists ,prints the name and quantity on hand;     *
*       if not ,prints an error message;                                       *
*******************************************************************************/
void search(void){
    int i,number;
 
    printf("Enter the part number: ");
    scanf("%d",&number);
    i=find_part(number);
   
    if(i>=0){
        printf("Part name: %s\n",inventory[i].name);
        printf("Quantity on hand: %d\n",inventory[i].on_hand);
}else
 printf("Part not found.\n");
 
}
 
 
/********************************************************************************
*update:prompts the user to enter a part number .prints and error message if the*
*       part number doesn`t exist;otherwise , prompts the user to enter change  *
*       in quantity on hand and updates the database;                           *
********************************************************************************/
 
 
void update(void){
    int i,number,change;
 
    printf("Enter the part number: ");
    scanf("%d",&number);
   
    i=find_part(number);
   
    if(i>=0){
        printf("Enter the change in quantity on hand: ");
        scanf("%d",&change);
        inventory[i].on_hand+=change;
}else
printf("part not exist.\n");
 
}
 
 
 
/*******************************************************************************
*print:print a listing of all parts in the database,showing the information    *
*******************************************************************************/
 
void print(void){
    int i;
    printf("Part Number        Part Name                       "
                "Quantity On Hand\n");
   
    for(i=0;i<num_parts;i++)
    printf("%7d            %-25s%11d\n",inventory[i].number,inventory[i].name,inventory[i].on_hand);
}
 
/****************************************************************************
*NAMC:read_line.c                                                           *
*purpose:define the read_line function                                      *
*Author:Bennett                                                             *
*Date written:2/1/2012                                                      *
****************************************************************************/
#include<ctype.h>
#include<stdio.h>
#include "read_line.h"
 
read_line.c文件:
int read_line(char str[],int n)
{
    int ch,i=0;
    while(isspace(ch=getchar()))       /*judge the getchar if is a void char */
    ;
    while(ch!='\n'&&ch!=EOF){
        if(i<n)
        str[i++]=ch;
        ch=getchar();
}
    str[i]='\0';
    return i;
}
 
read_line.h文件:
#ifndef READ_LINE_H
#define READ_LINE_H
int read_line(char str[],int n);
#endif
搜索更多相关主题的帖子: written include version database management 
2012-02-02 18:16
weipeng1217
Rank: 5Rank: 5
等 级:职业侠客
帖 子:175
专家分:386
注 册:2012-1-12
收藏
得分:0 
额滴神呐~~这代码能把人看晕~~

C坛友交流群 群号:161091913 ,欢迎经常在线的朋友加入,一起学习,一起进步。。
2012-02-02 23:03
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
发这么长代码要干吗呀?

总有那身价贱的人给作业贴回复完整的代码
2012-02-02 23:17
C_596322153
Rank: 6Rank: 6
来 自:徽州
等 级:侠之大者
帖 子:182
专家分:466
注 册:2012-1-10
收藏
得分:0 
要慢慢看了  ,,,,
2012-02-03 08:16
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:0 
额,这代码我2分钟就看完了

技术问题,请不要以短消息方式提问
2012-02-04 19:25
小赵q1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:492
专家分:777
注 册:2011-8-26
收藏
得分:0 
楼主想让大家从里面分析效果呢,呵呵
2012-02-05 00:20
快速回复:小的库存系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064640 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved