C语言项目--苹果产品管理系统

这是一个使用C语言编写的苹果产品管理系统,包含了登录查询、添加、删除、分类、排序、查询、修改、筛选和以旧换新等功能。通过结构体和链表管理产品信息,用户可以选择不同操作进行交互。系统还提供了图形界面元素,如按钮和图片。
摘要由CSDN通过智能技术生成

小学期的时候老师布置的管理系统作业
真的有认真去写,也用这段代码去参加了学院的C语言比赛 ~(参赛代码含exe代码),但现在展示出来就是可以运行的管理系统的代码!
注:但是想要找到文件要自己新建一个名为f1.exe的文本,然后在里面写入相应的内容嗷!

OK,我们开始吧!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include <graphics.h>
//---------------------------------------(200,500)(400,500)---------------------------------------------------结构体定义
PIMAGE NEW1; //登陆图片
PIMAGE NEW2; //主界面图片
PIMAGE add_recycle; //添加和以旧换新图片
PIMAGE del_choose; //删除和筛选图片
PIMAGE separate_amend; //分类和修改图片
PIMAGE sort_find; // 排序和查询
PIMAGE button1; //按钮1
PIMAGE button2; //按钮2
struct appleproduct{
int num,x;
char bname[50];
char bcolor[20];
char bmemory[10];
float price;
int residue;
struct appleproduct next;
};
struct recycle{
float price;
float newprice;
float difference;
char aname[100];
char cname[100];
struct recycle temp;
};
//----------------------------------------------------------------------------------------变量/子函数声明
int n,m;
struct appleproduct
head; //这个是定义一个头指针
int amend(struct appleproduct head);
void savefile(struct appleproduct head);
struct appleproduct add(struct appleproducthead);
struct appleproduct load();
struct appleproduct bubblesort(struct appleproduct head);
void del(struct appleproduct head);
void find(struct appleproduct
head);
void separate(struct appleproduct head);
void choose(struct appleproduct head);
struct recycle recycle(struct appleproduct head);
void menu();
void menu2();
//-----------------------------------------------------------------------------------------主函数
int main(){
head=load();//调用加载子函数
menu();//调用界面子函数
//--------------------------没有得到退出指令代码不会自动退出,可以一次性执行所有功能
while(1){
if(n==0){
system(“cls”);
printf(“谢谢使用!”);
exit(0);
}
else {
menu2();
}
}
}
//-------------------------------------------------------------------------------------------------------子函数
void menu(){
printf("\n\t\t\t\t\t
欢迎光临***********\n\n");
printf("\t\t\t\t\t\t ----------------\n");
printf("\t\t\t\t\t\t 苹果产品管理\n");
printf("\t\t\t\t\t\t ----------------\n");
printf("\n\t\t\t\t\t*********************************************\n\n");
printf("\n\t\t\t\t\t\t\t1-登录查询\n\n");
printf("\n\t\t\t\t\t\t\t0-退出系统\n\n");
printf("\n\t\t\t\t\t____________________________________________\n\n");
printf("\n\t\t\t\t\t\t\t*请输入您的选择:\n");
scanf("%d",&n);
}

void menu2(){
system(“cls”);
printf("\t\t\t\t\t\t ----------------\n");
printf("\t\t\t\t\t\t 苹果产品管理\n");
printf("\t\t\t\t\t\t ----------------\n");
printf("\n\t\t\t\t\t*********************************************\n\n");
printf("\n");
printf("\n\t\t\t\t\t* 1-添加产品信息*\n");
printf("\n\t\t\t\t\t* 2-删除产品信息*\n");
printf("\n\t\t\t\t\t* 3-产品类型列表*\n");
printf("\n\t\t\t\t\t* 4- 产品排序 \n");
printf("\n\t\t\t\t\t
5- 查询产品 \n");
printf("\n\t\t\t\t\t
6-修改产品信息*\n");
printf("\n\t\t\t\t\t* 7-根据需求筛选*\n");
printf("\n\t\t\t\t\t* 8-以旧换新*\n");
printf("\n\t\t\t\t\t* 9- 返回上一页*\n");
printf("\n");
printf("\n\n\t\t\t\t\t*********************************************\n\n");
scanf("%d",&m);
switch (m){
case 1:system(“cls”),head=add(head),savefile(head);break; //添加
case 2:system(“cls”),del(head);break; //删除
case 3:system(“cls”), separate(head);break; //按电脑和手机来分类
case 4:system(“cls”),head=load(),head=bubblesort(head);break;//排序
case 5:system(“cls”),find(head);break;//查找
case 6:system(“cls”),amend(head);break;//修改
case 7:system(“cls”),choose(head);break;//条件筛选
case 8:system(“cls”),recycle(head);break;
default:system(“cls”),main();break;//这是返回主界面 要是是直接退出系统可以改成default:exit(0);
}
}

struct appleproduct *load/函数名/()
{
FILE *fp;//FILE是变量类型,用于文件 (定义一个文件指针名)
char ch;
struct appleproduct *head,*tail,*p1;//head是头,tail是尾,p1是新建
head=tail=NULL;//头尾节点都相等 都为NULL
if((fp=fopen(“f1.txt”,“r”))==NULL)

//把文件里的信息给fp
{
printf(“没有读到文件”);
exit(0);
}
ch=fgetc(fp);//输入fp文件的信息给ch
if(ch==‘1’){//握手
while(!feof(fp)){//feof(fp)到达文件末尾就返回非零
p1=(struct appleproduct*)malloc(sizeof(struct appleproduct));
//把fp这个文件信息输入到p1
fscanf(fp,"%d %s %s %s %f %d\n",&p1->num,p1->bname,p1->bcolor,p1->bmemory,&p1->price,&p1->residue);/除了地址%s,其他的都需要加&/
if(head==NULL)//指针还没有头
head=p1;//把新建节点当作头
else
tail->next=p1;//让新接进来的指针作为当前指针
tail=p1;
}
tail->next=NULL;
fclose(fp);
return head;
}
else
return NULL;//没握到就返回NULL
}
//----------------------------------------------------------------------添加
struct appleproduct add(struct appleproducthead)
{
struct appleproduct temp,tail,p1;
int num,residue;
char bname[50],bcolor[20],bmemory[10];
float price;
printf("\t\t\t\t\t
*****************************************\n\n\n");
printf("\t\t\t\t\t\t\t添加页面\n\n\n\n");
printf("\t\t\t\t\t1-产品序号\n");
printf("\t\t\t\t\t2-产品名称\n");
printf("\t\t\t\t\t3-颜色\n");
printf("\t\t\t\t\t4-产品内存\n");
printf("\t\t\t\t\t5-产品价格\n");
printf("\t\t\t\t\t6-产品余量\n\n\n");
printf("\t\t\t\t\t********************************************\n\n\n");
Sleep(51000);
system(“cls”);
printf(“请输入您想要添加的产品序号:”);
scanf("%d",&num);
printf(“请输入您想要添加的产品名称:”);
scanf("%s",bname);
getchar();
printf(“请输入您想要添加的产品颜色:”);
scanf("%s",bcolor);
getchar();
printf(“请输入您想要添加的产品内存:”);
scanf("%s",bmemory);
getchar();
printf(“请输入您需要添加的产品价格:”);
scanf("%f",&price);
getchar();
printf(“请输入添加产品的余量:”);
scanf("%d",&residue);
getchar();
printf(“添加成功!”);
system(“pause”);
p1=(struct appleproduct
)malloc(sizeof(struct appleproduct));
//建立p1结点
p1->num=num;
strcpy(p1->bname,bname);
strcpy(p1->bcolor,bcolor);
strcpy(p1->bmemory,bmemory);
p1->price=price;
p1->residue=residue;
//把输入的值赋进来
p1->next=NULL;//新结点加进来要作为尾结点
//--------------------找出还没连接p1的尾结点
temp=head;
while(temp->next!=NULL)
{//next->为空说明是尾结点
temp=temp->next;
}
tail=temp;

tail->next=p1;//找出来之后完成p1的连接。tail是当前尾结点 
return head;

}
//----------------------------------------------------------------- 保存文件信息
void savefile(struct appleproduct head){
FILE fp;//定义文件指针
char ch=‘1’;
struct appleproduct temp;
temp=head;
if((fp=fopen(“f1.txt”,“w”))==NULL){
printf(“打不开文件”);
exit(0) ;
}
fputc(ch,fp);//将字符ch写到文件指针fp所指向的文件的当前写指针的位置(不用的话可能导致下一次的1无法握手)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值