C/C++课程设计 ——货物管理系统

文章目录

    • 1) 货物管理系统1.0
    • 2) 货物管理系统2.0

1) 货物管理系统1.0

#include<stdio.h>
#include<string.h>
#include<stdlib.h>                                         
#include<windows.h>
typedef struct goods//结构体  
{int  num;int  price;char name[100];int  amount;int  kg;struct goods *next;} goods;struct goods *creathead()//建立  {struct goods *head;head=(struct goods *)malloc(sizeof(struct goods ));if(head==NULL){exit(0);}else{head->next==NULL;return head;}
}
void g()//定义函数 
{   system("color 6F"); printf("**************************************\n");printf("********** 1 输入货物信息 ************\n");printf("********** 2 增加货物信息 ************\n");printf("********** 3 删除货物信息 ************\n");printf("********** 4 查询货物信息 ************\n");printf("********** 5 修改货物信息 ************\n");printf("********** 6 显示货物信息 ************\n");printf("***********7 销毁货物信息 ************\n");printf("***********8 货物排序信息 ************\n"); printf("********** 9  退出系统    ************\n");printf("**************************************\n");
}
void fun()//定义函数 
{
system("color 3F");
printf("************************************\n");
printf("************************************\n");
printf("*******欢迎使用货物管理系统*********\n");
printf("************************************\n");
printf("************************************\n");
printf("************************************\n");
printf("********请按Enter键进入下一步*******\n"); 
getchar();
system("cls");
} 
void show(goods*head) //输出 
{goods *p1,*p2;p1=p2=head;printf("请输入货物编号 货物价格 货物名称 货物数量 货物质量 \n");while(1){p1=(struct goods*)malloc(sizeof(struct goods)); if(p1==NULL){printf("输入货物失败\n");exit(-1); }else{scanf("%d %d %s %d %d",&p1->num,&p1->price,&p1->name,&p1->amount,&p1->kg);}p2->next=p1;p2=p1;if(p1->num==0){break;}}p1->next=NULL;
} void addlist(goods *head)//增加 {goods *p1,*p2;p1=p2=head;while(p1->next!=NULL){p1=p1->next;}p2=(goods*)malloc(sizeof(goods));scanf("%5d %5d %5s %5d %5d",&p2->num,&p2->price,&p2->name,&p2->amount,&p2->kg);p2->next=NULL;p1->next=p2;
}void change(goods *head)//修改   {int a; printf("----------请输入你要修改的编号:");scanf("%d",&a);goods *p;p=head->next;while(1){if(p->num==a){break;	}p=p->next;} scanf("%d %d %s %d %d", &p->num,&p->price,&p->name,&p->amount,&p->kg);}void inquiry(goods *head)//查询   {int b; goods *p;p=head;printf("请输入你要查询的货物编号:\n"); scanf("%d",&b);while(p->num!=b){p=p->next;}printf("----------查询结果----------");printf("货物编号%d,货物价格%d,货物名称%s,货物数量%d,货物重量%d:\n",p->num,p->price,p->name,p->amount,p->kg);
}
void deletelist(goods *head)//删除 
{int c;printf("请输入你要删除的货物编号:\n");scanf("%d",&c);goods*p1=head;goods*p2=head;while(p1!=NULL){if(p1->num==c){p1->next=p2->next;free(p1);printf("删除成功!\n");break; }p2=p2->next;p1=p2->next;}	 
}
void print(goods *head)//输出  
{goods *p;p=head->next;while(p->next!=NULL){printf("货物信息:货物编号%5d,货物价格%5d,货物名称%5s,货物数量%5d,货物重量%5d\n",p->num,p->price,p->name,p->amount,p->kg); p=p->next; }
} void destroy(goods*head)//销毁   
{goods *p;p=head;while(p->next!=NULL){p=p->next;free(p);}printf("该货物信息已经被销毁\n"); 
} void QQ()//登录
{ char name[20],sercret[20];printf("请输入你的用户名\n");scanf("%s",&name);printf("请输入你的密码\n"); scanf("%s",&sercret); if(strcmp("1219913130",name)==0&&strcmp("666666",sercret)==0){printf("登录成功"); }else{printf("登录失败");exit(-1); }}
void sort(goods*head)//排序 
{goods *p1,*p2,*p3;int x,i;int t;char name_[20];int num,amount,kg;for(x=0,p3=head->next;p3!=NULL;p3=p3->next){x++;
}
for(i=0;i<x;i++){for(p1=head->next,p2=head->next->next;p1!=NULL,p2!=NULL;p1=p1->next,p2=p2->next){if(p1->price<p2->price){t =p2->price;p2->price=p1->price;p1->price=t;strcpy(name_,p2->name);strcpy(p2->name,p1->name);strcpy(p1->name ,name_);num=p2->num;p2->num=p1->num;p1->num=num;amount=p2->amount;p2->amount=p1->amount;p1->amount=amount; kg=p2->kg;p2->kg=p1->kg;p1->kg=kg; }} }goods *p;p=head->next;while(p->next!=NULL){printf("货物信息:货物编号%5d,货物价格%5d,货物名称%5s,货物数量%5d,货物重量%5d\n",p->num,p->price,p->name,p->amount,p->kg); p=p->next; }
}int main() //调用 
{struct goods*head;head=creathead();QQ();//system("date/t");//system("time/t");while(1){system("date/t");system("time/t");//fun();g();int n;printf("请输入编号1-9\n");scanf("%d",&n);switch(n){case 1:{system("CLS\n");show(head);break;	}case 2:{system("CLS\n");addlist(head);break;}case 3:{system("CLS\n");deletelist(head);break;}case 4:{system("CLS\n");	inquiry(head);break;	}case 5:{system("CLS\n");change(head);break;}case 6:{system("CLS\n");print(head);break;}case 7:{system("CLS\n");destroy(head);break;}case 8:{system("CLS\n");sort(head);break;}case 9:{system("CLS\n");system("color 6F");printf("=============================================================\n");printf("||                                                       ||\n");printf("||                                                       ||\n");printf("||                         谢谢使用                      ||\n");printf("||                                                       ||\n");printf("||                                                       ||\n");printf("=============================================================\n");exit(0);default:printf("输入有误!"); }								} }}

2) 货物管理系统2.0

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
typedef struct storage{int num;int price;char name[20];int quantity;struct storage *next;
}storage;
void add(storage *head){//输入货物信息printf("请选择:1 接着上次输入 2 新建输入\n");int chose;scanf("%d",&chose);switch(chose){case 1:printf("请输入文件名:\n");char filename1[20];scanf("%s",filename1);printf("结束输入请输入0 0 0 0\n");printf("货物编号 货物价格 货物名称 货物数量\n");FILE *fp;fp=fopen(filename1,"a+");if(fp==NULL){printf("无法打开文件!");exit(0); } storage *p1,*p2;p1=p2=head;while(1){p1=(storage*)malloc(sizeof(storage));if(p1==NULL){printf("节点创建失败!");exit(0); }else{scanf("%d %d %s %d",&p1->num,&p1->price,&p1->name,&p1->quantity);fprintf(fp,"%d %d %s %d\n",p1->num,p1->price,p1->name,p1->quantity);p2->next=p1;p2=p1;if(p1->num==0){break;}}}p2->next=NULL;fclose(fp);break;case 2:FILE *fn;printf("请输入文件名:\n");char filename2[20];scanf("%s",filename2);fn=fopen(filename2,"w");printf("结束输入请输入0 0 0 0\n");printf("货物编号 货物价格 货物名称 货物数量\n");if(fn==NULL){printf("无法打开文件!");exit(0); } storage *p3,*p4;p3=p4=head;while(1){p3=(storage*)malloc(sizeof(storage));if(p3==NULL){printf("节点创建失败!");exit(0); }else{scanf("%d %d %s %d",&p3->num,&p3->price,&p3->name,&p3->quantity);fprintf(fn,"%d %d %s %d\n",p3->num,p3->price,p3->name,p3->quantity);p4->next=p3;p4=p3;if(p3->num==0){break;}}}p4->next=NULL;fclose(fn);break;
}
}
void amend(storage *head){//修改货物信息 printf("请输入要想修改的文件名称:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp,*ftn;fp=fopen(filename,"r");ftn=fopen("tmp.txt","w");if(fp==NULL||ftn==NULL){printf("无法打开文件!");exit(0); }printf("请输入要修改的货物编号:");int c;scanf("%d",&c);while(!feof(fp)){fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l);if(i==c){printf("%d %d %s %d\n",i,j,k,l); printf("修改为:"); scanf("%d %d %s %d",&i,&j,k,&l);fprintf(ftn,"%d %d %s %d\n",i,j,k,l);continue;}fprintf(ftn,"%d %d %s %d\n",i,j,k,l);}fclose(fp);fclose(ftn);remove(filename);rename("tmp.txt",filename);
}
void search(storage *head){//查询货物信息 printf("请输入要想修改的文件名称:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp;fp=fopen(filename,"r");printf("请输入要查询的货物编号:");int d;scanf("%d",&d);  while(!feof(fp)){fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l);if(i==d){printf("\n货物编号 货物价格 货物名称 货物数量\n"); printf("%-10d %-10d %-10s %-10d\n",i,j,k,l);break;}}fclose(fp);
}
void deletestorage(storage *head){printf("请输入要想修改的文件名称:\n");char filename[20];scanf("%s",filename);storage *p3;int m,z,l;char k[20];FILE *fp;fp=fopen(filename,"r");while(!feof){fscanf(fp,"%d %d %s %d\n",&m,&z,k,&l);p3->num=m;p3->price=z;strcpy(p3->name,k);p3->quantity=l;p3=p3->next;} p3->next=NULL;printf("请输入要删除的货物编号:");int b;scanf("%d",&b);storage *p1=head->next,*p2=head;while(p1!=NULL){if(p1->num==b){p2->next=p1->next;free(p1);break;}p2=p2->next;p1=p2->next;}storage *p4;p4=head->next;FILE *ftp;ftp=fopen(filename,"w");if(ftp==NULL){printf("无法打开文件!");exit(0); } while(p3->next!=NULL){fprintf(ftp,"%d %d %s %d\n",p4->num,p4->price,p4->name,p4->quantity);p4=p4->next;}fclose(ftp);
}
void paixu(storage *head){printf("请输入要想修改的文件名称:\n");char filename[20];scanf("%s",filename);storage *p3;int m,z,l;char k[20];FILE *fp;fp=fopen(filename,"r");while(!feof){fscanf(fp,"%d %d %s %d\n",&m,&z,k,&l);p3->num=m;p3->price=z;strcpy(p3->name,k);p3->quantity=l;p3=p3->next;} p3->next=NULL;fclose(fp);int n=0,i,j,t1,t2,t3;char t4[20];storage *p1,*p;p=head->next;while(p!=NULL){n++;p=p->next;}for(i=0;i<n-2;i++){p1=head->next;for(j=0;j<n-i-2;j++){if(p1->price>p1->next->price){t1=p1->num;p1->num=p1->next->num;p1->next->num=t1;t2=p1->price;p1->price=p1->next->price;p1->next->price=t2;t3=p1->quantity;p1->quantity=p1->next->quantity;p1->next->quantity=t3;strcpy(t4,p1->name);strcpy(p1->name,p1->next->name);strcpy(p1->next->name,t4);}p1=p1->next;}} p=head->next;printf("货物编号 货物价格 货物名称 货物质量\n"); while(p->num!=0){printf("%-10d %-10d %-10s %-10d\n",p->num,p->price,p->name,p->quantity);p=p->next;}
} 
void print(storage *head){//显示全部货物信息 printf("请输入要想修改的文件名称:\n");char filename[20];scanf("%s",filename);int i,j,l;char k[20];FILE *fp;fp=fopen(filename,"r");if(fp==NULL){printf("无法打开文件!");exit(0); } printf("货物编号 货物价格 货物名称 货物数量\n");while(fscanf(fp,"%d %d %s %d\n",&i,&j,k,&l)!=EOF){if(i==0)continue;printf("%-10d %-10d %-10s %-10d\n",i,j,k,l);}fclose(fp);
}
int main(){system("color 2F");storage *head;head=(storage*)malloc(sizeof(storage));if(head==NULL){printf("头结点创建失败!");exit(0); } head->next=NULL;char usename[10],password[7];while(1){system("date/t");system("time/t");printf("=================================================================\n");printf("\\\\                   欢迎使用仓库货物管理系统                //\n");printf("=================================================================\n");printf("||                                                             ||\n");printf("||                                                             ||\n");printf("||                          请输入账号密码                     ||\n");printf("||                                                             ||\n");printf("||                                                             ||\n");printf("=================================================================\n");printf("账号:");scanf("%s",usename);printf("密码:");scanf("%s",password); if(strcmp("666", usename) == 0&&strcmp("666",password)==0){system("CLS");while(1){int a;system("date/t");system("time/t");printf("=================================================================\n");printf("\\\\                     欢迎使用仓库货物管理系统              //\n");printf("=================================================================\n");printf("||                      【1】输入货物信息                      ||\n");printf("||                      【2】修改货物信息                      ||\n");printf("||                      【3】查询货物信息                      ||\n");printf("||                      【4】显示全部货物信息                  ||\n");printf("||                      【5】删除货物信息                      ||\n");printf("||                      【6】按价格排序                        ||\n");printf("||                      【0】退出系统                          ||\n");printf("=================================================================\n");printf("请选择程序种类:"); scanf("%d",&a);switch(a){case 1:system("CLS");add(head);break;case 2:system("CLS");amend(head);break;case 3:system("CLS");search(head);break;case 4:system("CLS");print(head);break;case 5:system("CLS");deletestorage(head);break;case 6:system("CLS");paixu(head);break;case 0:system("CLS");printf("=============================================================\n");printf("||                                                          ||\n");printf("||                                                          ||\n");printf("||                         谢谢使用                         ||\n");printf("||                                                          ||\n");printf("||                                                          ||\n");printf("=============================================================\n");exit(0);default:printf("输入有误!");}}
}
else{printf("=============================================================\n");printf("||                                                          ||\n");printf("||                                                          ||\n");printf("||                  账号或密码输入错误!                    ||\n");printf("||                  退出系统请输入 0                        ||\n");printf("||                  重新输入请输入 1                        ||\n");printf("||                                                          ||\n");printf("||                                                          ||\n");printf("=============================================================\n");int a;scanf("%d",&a);system("CLS");if(a==0){printf("=============================================================\n");printf("||                                                           ||\n");printf("||                                                           ||\n");printf("||                         谢谢使用                          ||\n");printf("||                                                           ||\n");printf("||                                                           ||\n");printf("=============================================================\n");exit(0);} }
}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/531023.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

IDEA连接mysql报Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' 的错误

IDEA布置好项目后&#xff0c;连接Mysql&#xff0c;提示时区错误&#xff0c;解决方案如下&#xff1a; 在mysql的命令模式下&#xff0c;输入&#xff1a; set global time_zone8:00;如图所示&#xff1a;

JDBC 提示:WARN: Establishing SSL connection without server's identity verification is not recommended.

Java连接Mysql数据库的过程中出现了如下的警告信息: WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45, 5.6.26 and 5.7.6 requirements SSL connection must be established by default if explic…

C/C++课程设计 之学生管理系统(一)

文章目录1) 案例一2) 案例二3) 案例三4) 案例四5) 案例五6) 案例六7) 案例七8) 案例八9) 案例九10&#xff09;案例十11&#xff09;案例十一12&#xff09;案例十二13&#xff09;案例十三14&#xff09;案例十四15&#xff09;案例十五&#xff08;一&#xff09; 新生基本信…

C语言小游戏 ——推箱子

文章目录&#xff08;1&#xff09;内容描述&#xff08;2&#xff09;功能&#xff08;3&#xff09;设计目的&#xff08;4&#xff09;总体设计&#xff08;5&#xff09;明显缺点&#xff08;6&#xff09;个人总结7. 实例实例一实例二实例三实例四实例五&#xff1a;&…

Java GUI 实现登录界面

具体效果图&#xff1a; 详细代码&#xff1a; package java_gui;import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Font; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;imp…

for-each循环的认识、定义、适用对象、举例、局限性

文章目录1. for-each的认识2. for-each的定义3. 哪些类型的对象可以适用For-Each&#xff1f;4. for-each的举例5. for-each的局限性1. for-each的认识 &#xff08;1&#xff09;for-each语句是Java中for-Index的一种加强&#xff0c;是Java 5带来的新语法糖。 &#xff08;2…

C语言 实现登录注册功能

文章目录加载动画实验结果图实验代码加载动画 #include<iostream> #include<windows.h> using namespace std;int main(){cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;cout.widen(65);co…

C语言小游戏 ——俄罗斯方块

#include<stdio.h> #include<stdlib.h> #include<windows.h>//Sleep()函数的头文件 #include<time.h> #include<conio.h> #define MOD 28 #define SIZE_N 19//控制边框的高度 #define SIZE_M 12 //控制边框的宽度 int a[100]{200,30,20};/…

C/C++课程设计 之职工管理系统

文章目录 (一) 题目内容及简介(二) 概要设计(三) 详细设计(四) 实现代码(五) 相关案例案例一案例二案例三案例四案例五案例六案例七案例八案例九案例十案例十一(一) 题目内容及简介 1.课题来源 课题名称和来源,主要介绍为何选择此题目来开展课程设计,此课题的开展能体现面向…

C++ 知识要点

1.类与对象 类是事物的抽象。类的对象就是类的具体化&#xff0c;实际化 2.C三大特性 继承、封装、多态 3.C父类与子类继承过程中&#xff0c;子类的特点&#xff1f; 子类拥有父类的所有属性和行为 子类就是一种特殊的父类 子类对象可以当作父类对象使用 子类中可以添加父类…

C/C++小游戏 ——贪吃蛇

文章目录案例一案例二案例三案例四案例五案例六案例七案例八案例九案例一 #include <stdio.h>#include <windows.h>#include <conio.h>#include <time.h>//游戏窗口#define FrameX 4//游戏窗口左上角的X轴坐标#define FrameY 4//游戏窗口左上角的Y轴坐…

C/C++课程设计 新生入学管理系统(二)

文章目录 案例十六案例十七案例十八案例十九案例二十案例二十一案例二十二案例二十三案例二十四案例二十五案例二十六案例二十七案例二十八案例十六 #include<iostream> #include<cstring> //strcpy,strcmp #

Java类名.方法和变量

文章目录(1) 类名.方法(2) 变量(1) 类名.方法 要是类名直接调用的方法&#xff0c;那这个方法就是静态的(static)方法&#xff0c;是不用new出新对象实例就可以直接调用的方法。看下面例子&#xff1a; class A {public static void Method1(int a, int b) {//方法体}public …

Java小案例(二) 用数组实现增删查改排序

文章目录案例一案例二案例三案例四案例五案例一 Student.Java package curd;public class Student {private String stuid;private String name;private int chinese;private int math;private int english;private int avg;private int sum;public int getAvg() {return avg;…

有趣的一行代码

文章目录爱心曼德勃罗集合打印99乘法表实现快速排序禅语漫画迷宫爱心 print(\n.join([.join([(❤❤❤❤❤❤❤❤❤❤❤❤[(x-y)%12]if((x*0.05)**2(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<0 else )for x in range(-30,30)])for y in range(15,-15,-1)]))效果图&#xff1…

Python练习之 对文件进行创建,然后重命名文件最近进行文件删除

import os os.mkdir("D:\\1815925603") context ("序号&#xff1a;1815925603\n""姓名&#xff1a;阿信\n""班级&#xff1a;18云计算2班\n") with open (D:\\1815925603\\file1.txt,a) as fp:fp.write(context)fp.seek(0, 0) with …

Java接口中的成员变量为什么必须是static ?

接口的含义 接口就是提供一种统一的协议, 而接口中的属性也属于协议中的成员。它们是公共的,静态的,最终的常量。相当于全局常量。 在interface里面的变量都是public static final 的。 public static final int i10;等价于int i10;(可以省略掉一部分) //注意在声明的时候要…

Java函数式编程和面向对象编程

文章目录什么是函数式编程&#xff1f;什么是面向对象编程&#xff1f;函数式编程和面向对象编程的优缺点什么是函数式编程&#xff1f; 函数式编程的核心&#xff1a;在思考问题时&#xff0c;使用不可变对象和函数&#xff0c;函数将一个值经过处理&#xff0c;映射成另一个…

JDBC实现图书管理小案例

文章目录项目文件结构项目运行效果项目详细代码项目文件下载相关案例案例一案例二案例三案例四案例五案例六案例七案例八项目文件结构 项目运行效果 项目详细代码 JDBCUtils.java package jdbc;import java.sql.*; import com.mysql.jdbc.Driver;public class JDBCUtils {pri…

Java实现多线程售票

文章目录Synchronized和Lock的区别是什么&#xff1f;案例一方法一 继承Thread类方法二 实现Runnable接口案例二方法一 继承Thread类方法二 实现Runnable接口案例三方法一 继承Thread类方法二 实现Runnable接口案例四方法一 继承Thread类方法二 实现Runnable接口案例五方法一 继…