Compare commits

..

No commits in common. '766392f500f7e05c061e931a26c4c6f5ef17b5e2' and '303301885b49b5833e7151004cd71ac772991c89' have entirely different histories.

@ -1,49 +1,4 @@
# 零件库存管理系统
2023/5/21
杨腾泽,孙英皓,刘彩月,李聪颖
## 项目简介
本系统是程序设计与问题求解课程设计项目,实现了库存零件 CSV 格式数据文件的读取和保存以及数据的增删改查CRUD、排序和图表显示等功能。项目采用 C 语言编程实现,在 VS Code 集成开发环境IDE中用 GCC 进行编译。系统采用模块化设计,程序结构清晰,采用菜单驱动的命令行界面,操作便捷,能够用 CSV 格式读取和保存数据,通用性强,能够用图表展示数据,直观清楚。
下载地址https://gitee.com/sjandsy/parts-management.git
项目开发过程中采用 Kanban看板进行任务管理和分工协作并使用 Git 对程序代码和文档进行版本管理。任务分工情况如下:
| 任务 | 设计 | 开发 | 测试 | 文档 |
| ---- | ---- | ---- | ---- | ---- |
| C1-C3 菜单驱动的用户界面 | | | | |
|C4 添加库存记录 | | | | |
|C5 查询库存记录 | | | | |
|C6 打印库存列表 | | | | |
|C7 修改库存记录 | | | | |
|C8 删除库存记录 | | | | |
|C9 库存记录排序 | | | | |
|C10 读取库存文件 | | | | |
|C11 将库存保存到文件 | | | | |
每个成员的工作量(百分比):
| | | | |
|--------|-------|---------|-------|
| | | | |
## 关于零件库存管理系统
设计一个库存零件管理系统,要求采用命令行菜单界面进行交互,具备读取、保存、打印、查询、修改、插入、删除和排序等基本功能,能够以表格和图表形式展示数据,采用 CSV 格式保存数据。
系统的功能性需求:
- 数据的读取、保存、打印、查询、修改、插入、删除、排序和图表展示。
系统的非功能性需求:
- 菜单驱动的命令行交互界面。
## 需求分析
分析系统的功能需求和界面需求,编制用户手册如下。
# a
#### C1: 启动程序
@ -73,53 +28,4 @@
请输入想要操作的选项*-*0
确定要退出吗?(Y/N): y
程序退出
```
#### C4: 添加库存记录
选择菜单命令 `5`,提示输入零件编号,若该零件不存在,则继续输入零件名称、库存数量,添加零件,并提示完成;若零件编号已存在,则提示零件已存在,并结束。
```
请输入想要操作的选项*-*5
请输入id101
请输入商品名:电脑
请输入商品数量20
商品 101 已添加成功
1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加
6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出
```
#### C5: 查询库存记录
选择菜单命令 `4`,提示输入零件编号,若该零件存在,则输出零件信息;否则提示零件不存在并结束。
```
请输入想要操作的选项*-*4
请输入需要查找的商品id101
商品的id101
商品的名称:电脑
商品的数量20
1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加
6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出
请输入想要操作的选项*-*4
请输入需要查找的商品id100
输入的商品信息无效!!!
```
#### C6: 打印库存列表
选择菜单命令 `3`,打印
```
请输入想要操作的选项*-*3
商品的id101
商品的名称:电脑
商品的数量20
```
```

@ -1,45 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "void.c"
int main ()
{
LIST *pList = NULL;
pList = creation ( );
readData2 ( pList );
while ( 1 )
{
int choice = menu ( );
int c1;
getchar();
switch ( choice )
{
case 1:
c1= menu1();
if(c1==1) readData1 ( pList );
if(c1==2) saveData(pList);
if(c1==3) show_goods(pList);
if(c1==4) find_goods(pList);
if(c1==5) insert(pList);
if(c1==6) increase_count(pList);
if(c1==7) delete_from_list(pList);
if(c1==8) sort(pList);
if(c1==9) Show(pList);
if(c1==0) {saveData(pList); printf("感谢使用");}
break;
case 2:
saveData ( pList );
printf("感谢使用");
return 0;
break;
default:
printf ("输入的信息有误,请重新输入!!!\r\n");
break;
}
}
return 0;
}

@ -1,418 +0,0 @@
//sjandy sjandsy sjandsy
#include <bits/stdc++.h>
#define Rl 1000
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
//常量定义
#define SIZE 20
enum judge
{
ERROR = -1,
OK,
};
//类型定义
struct goods
{ int id;
char name [SIZE];
int count;
};
typedef struct goods dataType;
typedef struct list
{
dataType data;
struct list *pNext;
}LIST;
LIST lis;
LIST * creation ( )
{
LIST *pList = NULL;
pList = ( LIST * ) malloc ( sizeof ( LIST ) );
if ( NULL == pList )
{
return NULL;
}
memset ( pList, 0, sizeof ( LIST ) );
return pList;
}
bool add_goods(int id,char name[],int count,LIST *p){
if ( NULL == p )
{
return false;
}
//赋值
strcpy(p->data.name,name);
p->data.count = count;
p->data.id=id;
return true;
}
int insert ( LIST * pList )
{
//判断链表是否存在
if ( NULL == pList )
{
return ERROR;
}
LIST *p = creation ( );
char name[20];
int count=0;
int id=0;
printf("请输入id:\n");
scanf("%d",&id);
printf("请输入商品名:\n");
scanf("%s",&name);
printf("请输入商品数量:\n");
scanf("%d",&count);
if(add_goods(id,name,count,p)){
//头插法插入节点
p->pNext = pList->pNext;
pList->pNext = p;
printf ( "商品 %s 已经添加成功\r\n", p->data.name );
return OK;
}
}
int delete_from_list ( LIST * pList )
{
//判断链表是否存在,是否为空
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需要删除的商品id\r\n" );
scanf ( "%d", s );
LIST *p = pList->pNext;
LIST *q = pList;
while ( NULL != p )
{
if ( p->data.id == s[0] )
{
q->pNext = p->pNext;
free ( p );
p = NULL;
printf ( "商品 %s 信息已被删除!!\r\n", s );
return OK;
}
p = p->pNext;
q = q->pNext;
}
printf ( "您输入的商品名称没有找到!!\r\n" );
return ERROR;
}
int find_goods ( LIST *pList )
{
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需要查找的商品id\r\n" );
scanf ( "%d", s );
//定义指针变量
LIST *p = pList->pNext;
while ( NULL != p )
{
if ( p->data.id==s[0] )
{ printf ("商品的id:%d\r\n ",p->data.id);
printf ( "商品的名称:%s\r\n", p->data.name );
printf ( "商品的数量:%d\r\n", p->data.count );
return OK;
}
p = p->pNext;
}
printf ( "输入的商品信息无效!!!\r\n" );
return ERROR;
}
int increase_count ( LIST *pList )
{
//判断链表是否存在,是否为空
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需修改的商品id\r\n" );
scanf ( "%d", s );
LIST *p = pList->pNext;
while ( NULL != p )
{
if ( p->data.id==s[0] )
{
printf ( "原商品的数量:%d\r\n", p->data.count );
printf ( "请输入修改的商品数量\r\n" );
int xiugai;
scanf ( "%d", &xiugai );
p->data.count+=xiugai;
printf ( "商品数量修改成功 *_* \r\n" );
return OK;
}
p = p->pNext;
}
printf ( "您输入的商品名称没有找到!!\r\n");
return ERROR;
}
int menu ( )
{
printf ( " ==欢迎来到商品管理系统===\r\n" );
printf("1.功能菜单 | 2.退出 \n");
printf ( "请输入想要操作的选项*-*\r\n" );
int choice = 0;
scanf ( "%d", &choice );
return choice;
}
int menu1 ( )
{
printf ( " ==欢迎来到商品管理系统===\r\n" );
printf ( "1.读取 | 2. 保存 | 3. 打印 | 4. 查询 | 5. 添加\n"
"6.修改 | 7.删除 | 8.排序 | 9.图表 | 0.退出\n\n");
//输入选项
printf ( "请输入想要操作的选项*-*\r\n" );
int choice = 0;
scanf ( "%d", &choice );
return choice;
}
int show_goods ( LIST *pList )
{
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您的数据库内没有商品!\r\n" );
return ERROR;
}
int count = 0;
LIST *p = pList->pNext;
while ( NULL != p )
{
count++;
printf ( "商品的id: %d\r\n",p->data.id);
printf ( "商品的名称:%s\r\n", p->data.name );
printf ( "商品的数量:%d\r\n", p->data.count );
//printf ( "商品的价格:%f\r\n", p->data.price );
printf ( "\r\n" );
p = p->pNext;
}
printf ( "商品的种类为 %d \r\n", count );
return count;
}
void saveData ( LIST *pList )
{
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您没有商品信息不用保存\r\n" );
return ;
}
FILE *fp =NULL;
fp = fopen ( "ck.csv", "w+" );
if ( NULL == fp )
{
printf( "文件打开失败\r\n" );
return ;
}
LIST *p = NULL;
int count = 0;
while ( NULL != pList->pNext )
{
p = pList->pNext;
pList->pNext = p->pNext;
fwrite(&p->data,sizeof(p->data),1,fp);
free (p);
p = NULL;
count++;
}
free ( pList );
pList = NULL;
fclose ( fp );
printf ( "已经保存 %d 种商品信息\r\n" , count );
return;
}
void readData ( LIST *pList )
{
//判断
if ( NULL == pList )
{
printf ( "读取数据失败!\r\n" );
return ;
}
FILE *fp = fopen ( "ck.csv", "rb" );
if ( NULL == fp )
{
printf( "注意:您的数据库内没有商品信息\r\n" );
return ;
}
int count = 0;
int tmp = 1;
LIST *p = NULL;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
while ( !feof(fp) )
{
//头插法插入节点
p->pNext = pList->pNext;
pList->pNext = p;
count++;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
}
printf ( "数据库中有 %d 种商品信息\r\n", count );
fclose ( fp );
return;
}
int Show( LIST *pList )
{printf("ID | NAME Amount\n");
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您的数据库内没有商品!\r\n" );
return ERROR;
}
int count = 0;
LIST *p = pList->pNext;
while ( NULL != p )
{
count++;
printf ( "%d ",p->data.id);
printf ( " %s ", p->data.name );
printf ( " %d ", p->data.count );
printf ( "\r\n" );
p = p->pNext;
}
}
void sort(LIST *pList)
{
int i ,count = 0, num;
LIST *p, *q, *tail;
p = pList;
while(p->pNext != NULL)
{
count++;
p = p->pNext;
}
for(i = 0; i < count - 1; i++)
{
num = count - i - 1;
q = pList->pNext;
p = q->pNext;
tail = pList;
while(num--)
{
if(q->data.id > p->data.id)
{
q->pNext = p->pNext;
p->pNext = q;
tail->pNext = p;
}
tail = tail->pNext;
q = tail->pNext;
p = q->pNext;
}
}
}
int main ( )
{
LIST *pList = NULL;
pList = creation ( );
readData ( pList );
while ( 1 )
{
int choice = menu ( );
int c1;
getchar();
switch ( choice )
{
case 1:
c1= menu1();
if(c1==1) readData ( pList );
if(c1==2) saveData(pList);
if(c1==3) show_goods(pList);
if(c1==4) find_goods(pList);
if(c1==5) insert(pList);
if(c1==6) increase_count(pList);
if(c1==7) delete_from_list(pList);
if(c1==8) sort(pList);
if(c1==9) Show(pList);
if(c1==0) {saveData(pList); printf("感谢使用");}
break;
case 2:
saveData ( pList );
printf("感谢使用");
return 0;
break;
default:
printf ("输入的信息有误,请重新输入!!!\r\n");
break;
}
}
return 0;
}

@ -1,413 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
//常量定义
#define SIZE 20
enum judge
{
ERROR = -1,
OK,
};
//类型定义
struct goods
{ int id;
char name [SIZE];
int count;
};
typedef struct goods dataType;
typedef struct list
{
dataType data;
struct list *pNext;
}LIST;
LIST lis;
LIST * creation ( )
{
LIST *pList = NULL;
pList = ( LIST * ) malloc ( sizeof ( LIST ) );
if ( NULL == pList )
{
return NULL;
}
memset ( pList, 0, sizeof ( LIST ) );
return pList;
}
bool add_goods(int id,char name[],int count,LIST *p){
if ( NULL == p )
{
return false;
}
//赋值
strcpy(p->data.name,name);
p->data.count = count;
p->data.id=id;
return true;
}
int insert ( LIST * pList )
{
//判断链表是否存在
if ( NULL == pList )
{
return ERROR;
}
LIST *p = creation ( );
char name[20];
int count=0;
int id=0;
printf("请输入id:\n");
scanf("%d",&id);
printf("请输入商品名:\n");
scanf("%s",&name);
printf("请输入商品数量:\n");
scanf("%d",&count);
if(add_goods(id,name,count,p)){
//头插法插入节点
p->pNext = pList->pNext;
pList->pNext = p;
printf ( "商品 %s 已经添加成功\r\n", p->data.name );
return OK;
}
}
int delete_from_list ( LIST * pList )
{
//判断链表是否存在,是否为空
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需要删除的商品id\r\n" );
scanf ( "%d", s );
LIST *p = pList->pNext;
LIST *q = pList;
while ( NULL != p )
{
if ( p->data.id == s[0] )
{
q->pNext = p->pNext;
free ( p );
p = NULL;
printf ( "商品 %s 信息已被删除!!\r\n", s );
return OK;
}
p = p->pNext;
q = q->pNext;
}
printf ( "您输入的商品名称没有找到!!\r\n" );
return ERROR;
}
int find_goods ( LIST *pList )
{
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需要查找的商品id\r\n" );
scanf ( "%d", s );
//定义指针变量
LIST *p = pList->pNext;
while ( NULL != p )
{
if ( p->data.id==s[0] )
{ printf ("商品的id:%d\r\n ",p->data.id);
printf ( "商品的名称:%s\r\n", p->data.name );
printf ( "商品的数量:%d\r\n", p->data.count );
return OK;
}
p = p->pNext;
}
printf ( "输入的商品信息无效!!!\r\n" );
return ERROR;
}
int increase_count ( LIST *pList )
{
//判断链表是否存在,是否为空
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "数据库数据为空,请先添加商品信息\r\n" );
return ERROR;
}
int s[SIZE] = {0};
printf( "请输入需修改的商品id\r\n" );
scanf ( "%d", s );
LIST *p = pList->pNext;
while ( NULL != p )
{
if ( p->data.id==s[0] )
{
printf ( "原商品的数量:%d\r\n", p->data.count );
printf ( "请输入修改的商品数量\r\n" );
int xiugai;
scanf ( "%d", &xiugai );
p->data.count+=xiugai;
printf ( "商品数量修改成功 *_* \r\n" );
return OK;
}
p = p->pNext;
}
printf ( "您输入的商品名称没有找到!!\r\n");
return ERROR;
}
int menu ( )
{
printf ( " ==欢迎来到商品管理系统===\r\n" );
printf("1.功能菜单 | 2.退出 \n");
printf ( "请输入想要操作的选项*-*\r\n" );
int choice = 0;
scanf ( "%d", &choice );
return choice;
}
int menu1 ( )
{
printf ( " ==欢迎来到商品管理系统===\r\n" );
printf ( "1.读取 | 2. 保存 | 3. 打印 | 4. 查询 | 5. 添加\n"
"6.修改 | 7.删除 | 8.排序 | 9.图表 | 0.退出\n\n");
//输入选项
printf ( "请输入想要操作的选项*-*\r\n" );
int choice = 0;
scanf ( "%d", &choice );
return choice;
}
int show_goods ( LIST *pList )
{
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您的数据库内没有商品!\r\n" );
return ERROR;
}
int count = 0;
LIST *p = pList->pNext;
while ( NULL != p )
{
count++;
printf ( "商品的id: %d\r\n",p->data.id);
printf ( "商品的名称:%s\r\n", p->data.name );
printf ( "商品的数量:%d\r\n", p->data.count );
//printf ( "商品的价格:%f\r\n", p->data.price );
printf ( "\r\n" );
p = p->pNext;
}
printf ( "商品的种类为 %d \r\n", count );
return count;
}
void saveData ( LIST *pList )
{
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您没有商品信息不用保存\r\n" );
return ;
}
printf("输入文件名称: ");
char str=getchar();
FILE *fp =NULL;
fp = fopen ( "data2.csv", "w+" );
if ( NULL == fp )
{
printf( "文件打开失败\r\n" );
return ;
}
LIST *p = NULL;
int count = 0;
while ( NULL != pList->pNext )
{
p = pList->pNext;
pList->pNext = p->pNext;
fwrite(&p->data,sizeof(p->data),1,fp);
free (p);
p = NULL;
count++;
}
free ( pList );
pList = NULL;
fclose ( fp );
printf ( "已经保存 %d 种商品信息\r\n" , count );
return;
}
void readData1 ( LIST *pList )
{
//判断
if ( NULL == pList )
{
printf ( "读取数据失败!\r\n" );
return ;
}
FILE *fp = fopen ( "data1.csv", "rb" );
if ( NULL == fp )
{
printf( "注意:您的数据库内没有商品信息\r\n" );
return ;
}
int count = 0;
int tmp = 1;
LIST *p = NULL;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
while ( !feof(fp) )
{
//头插法插入节点
p->pNext = pList->pNext;
pList->pNext = p;
count++;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
}
printf ( "数据库中有 %d 种商品信息\r\n", count );
fclose ( fp );
return;
}
void readData2 ( LIST *pList )
{
//判断
if ( NULL == pList )
{
printf ( "读取数据失败!\r\n" );
return ;
}
printf("输入文件名称: ");
char str=getchar();
FILE *fp = fopen ( "data2.csv", "rb" );
if ( NULL == fp )
{
printf( "注意:您的数据库内没有商品信息\r\n" );
return ;
}
int count = 0;
int tmp = 1;
LIST *p = NULL;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
while ( !feof(fp) )
{
//头插法插入节点
p->pNext = pList->pNext;
pList->pNext = p;
count++;
p = creation ( );
fread(&p->data,sizeof(p->data),1,fp);
}
printf ( "数据库中有 %d 种商品信息\r\n", count );
fclose ( fp );
return;
}
int Show( LIST *pList )
{printf("ID | NAME Amount\n");
//判断
if ( NULL == pList
|| NULL == pList->pNext )
{
printf ( "您的数据库内没有商品!\r\n" );
return ERROR;
}
int count = 0;
LIST *p = pList->pNext;
while ( NULL != p )
{
count++;
printf ( "%d ",p->data.id);
printf ( " %s ", p->data.name );
printf ( " %d ", p->data.count );
printf ( "\r\n" );
p = p->pNext;
}
}
void sort(LIST *pList)
{
int i ,count = 0, num;
LIST *p, *q, *tail;
p = pList;
while(p->pNext != NULL)
{
count++;
p = p->pNext;
}
for(i = 0; i < count - 1; i++)
{
num = count - i - 1;
q = pList->pNext;
p = q->pNext;
tail = pList;
while(num--)
{
if(q->data.id > p->data.id)
{
q->pNext = p->pNext;
p->pNext = q;
tail->pNext = p;
}
tail = tail->pNext;
q = tail->pNext;
p = q->pNext;
}
}
}
Loading…
Cancel
Save