链表:01-软件界面控制

实现一个数字选项式的启动界面,程序输入数据为(1-8),参考界面如下:
  1.显示所有商品的信息
  2.修改某个商品的信息
  3.插入某个商品的信息
  4.删除某个商品的信息
  5.查找某个商品的信息
  6.商品存盘并退出系统
  7.对商品价格进行排序
  8.(慎用)删除所有内容

  其他.不存盘并退出系统

程序当输入1-8时,执行相关功能,完成后再次显示菜单让用户选择。当输入其它数值时,程序不存盘并退出系统。

本小题只需实现 main 函数即可,相关结构及函数声明如下:

#define GOODS_FILE_NAME "goodsinfo.txt"

#define MAX_ID_LEN 30

#define MAX_NAME_LEN 30

#define MAX_PRICE_LEN 30

#define MAX_DISCOUNT_LEN 30
typedef struct {
char goods_id[MAX_ID_LEN];
char goods_name[MAX_NAME_LEN];
int goods_price;
char goods_discount[MAX_DISCOUNT_LEN];
int goods_amount;
int goods_remain;
} GoodsInfo;

typedef struct node
{
GoodsInfo data;
struct node *next;
} GoodsList;

GoodsInfo read_goods_info();
void init_list(GoodsList **pL);
void destory_list(GoodsList **pL);
void destory_list_and_file(GoodsList **pL);
int save_to_file(GoodsList *L);
void output_one_item(GoodsList *L);
void output_all_items(GoodsList *L);
bool insert_item(GoodsList *L, GoodsInfo item, int choice);
bool delete_item(GoodsList *L, char* goods_id);
GoodsList* search_item(GoodsList *L, char* goods_id);
bool change_item(GoodsList *L, char* goods_id, GoodsInfo new_info);
void bubble_sort(GoodsList *L);
int read_line(char str[], int n);

该部分声明已包含在 “lab52.h”中。

#include <stdio.h>
#include <stdlib.h>
#include "lab52.h" // 请不要删除本行头文件,否则检查不通过

int main ()
{
    GoodsInfo information;
    read_goods_info(information);
    GoodsList list;
    list.data=information;
    int get_number;
    init_list(&(list.next));
    read_line(information.goods_id,get_number);
    for(;;) {
    printf("1.显示所有商品的信息\n\
2.修改某个商品的信息\n\
3.插入某个商品的信息\n\
4.删除某个商品的信息\n\
5.查找某个商品的信息\n\
6.商品存盘并退出系统\n\
7.对商品价格进行排序\n\
8.(慎用)删除所有内容\n\
其他.不存盘并退出系统 ");
    scanf("%d",&get_number);
    switch (get_number) {
        case 1:output_all_items(list.next);
               break;
        case 2:change_item(list.next,information.goods_id,list.data);
               break;
        case 3:insert_item(list.next,list.data,get_number);
               break;
        case 4:delete_item(list.next,information.goods_id);
               break;
        case 5:search_item(list.next,information.goods_id);
               break;
        case 6:save_to_file(list.next);
               break;
        case 7:bubble_sort(list.next);
               break;
        case 8:destory_list_and_file(&(list.next));
               break;
        default:printf("Illegal number\n");  
               return 0;               
        }
    printf("\n");
    }
}


 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

实名吃香菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值