当前位置:首页 » 编程语言 » c语言程序设计书店存货清单
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言程序设计书店存货清单

发布时间: 2023-08-29 01:12:55

1. c语言程序设计 用链表编写商品库存管理。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
char no[20];//存放编号
char name[40];//存放名称
int reserve;//库存
struct node *next;
}NODE;

typedef struct link{
NODE *front;//头指针
NODE *rear;//尾指针
}LINK;

NODE *create_node(void){
NODE *node = (NODE *)malloc(sizeof(NODE));
printf("请输入货物编号:");
gets(node->no);
printf("请输入货物名称:");
gets(node->name);
printf("请输入货物名称:");
char ch;
while( (ch= getchar()) != '\n');//rewind(stdin);
scanf("%d",&node->reserve);
node->next = NULL;
return node;
}

void init_link(LINK *link){
link->rear = NULL;
link->front = NULL;
}

int link_empty(LINK *link){
return link->front == NULL ? 1: 0;
}

int node_num(LINK *link){
int num = 0;
if( link_empty(link)){
return num;
}
num = 1;
NODE *node = link->front;
while(node != link->rear){
node = node->next;
++num;
}
return num;
}

/*NODE *node_find(LINK *link,const int n){
int num = node_num(link);
if(num < n){
printf("公有节点%d个,无法找到第%d个节点\n",num,n);

}
else{

}
}
*/
void node_push(LINK *link){
NODE *node = create_node();
if(link->front == NULL){
link->front = node;
link->rear = node;
node->next = NULL;
}
else{
link->rear->next = node;
link->rear = node;
node->next = NULL;
}
}

void node_insert(LINK *link,const int n){
int num = 0,i = 1;
NODE *node = link->front;
NODE *new_node = NULL;
if ( link_empty(link) ){
printf("链表为空,将建立链表!\n");
node_push(link);
}
else{
if( n <= 1){
printf("在链表头插入数据\n");
new_node = create_node();
new_node->next = link->front;
link->front = new_node;
}
else if( n>= num = node_num(link) ){
printf("节点数少于%d,将在末尾插入节点.\n",n);
node_push(link);
}
else{
printf("在第n个节点后插入数据\n");
if(num >= n){
while( i != n){
node = node->next;
++i;
}
new_node = create_node();
new_node-next = node->next;
node->next = new_node;
}
}
}

void find_node_insert(LIKNK *link,const char *name){
NODE *node = link->front;
if( link_empty(link) )
node_push(link);
else {
while(strcmp(node->name,name) != 0){
if(node != link->rear)
node = node->next;
else break;

}
if(node != NULL){

NODE *new_node = create_node();
new_node-next = node->next;
node->next = new_node;
}
else {
printf("没有找到相关货物,将在头节点插入数据\n");
intsert(link,0);
}
}

/*由于我不知到你对货物统计具体实现的要求,关于货物数量统计就你自己写了,应该比较简单。*/
/* 代码没有具体运行过,如果你学过C结构体与指针,就这个代码思路应该看得明白,真正的实现你自己实现吧
这样对你会更好写。可能会有错误的地方,请谨慎。 */

2. c语言图书管理系统程序设计

一 程序设计说明书
【设计题目】 图书馆借阅管理
【问题描述】图书馆,适合用C++面向对象的功能来描述。图书馆管理系统分为借书、还书、图书管理和读者服务等四个部分。设计一个读者类Reader,记录每个读者基本信息;读者库类Rdatabase,记录所有读者信息;图书类Book, 记录每本书的基本信息;图书库类Bdatabase, 记录所有图书信息。
【基本要求】
1读者库类RDatabase中,其构造函数中,将read.txt文件中所有读入读者记录rede[]中。处理完毕,在析构函数中将read[]中的所有未删记录写入到read.txt中。
2图书库类BDatabase中,其构造函数中,将book.txt文件中所有读入图书记录book[]中。处理完毕,在析构函数中将book[]中的所有未删记录写入到book.txt中。
3 利用构造函数完成读者和图书数据初始化,完成内存分配。程序结束前,析构函数完成所申请的堆内存空间。
4 编写主函数,对所编写的矩阵类进行全面测试。要求用户界面采用菜单方式。测试中需要读者和图书数据通过I/O流从磁盘文件读入,同时显示在屏幕上。得到的数据通过I/O流写入磁盘文件保存,同时显示在屏幕上。
5 源程序中要有充分的注释,报告中要有详细的流程图和文字材料。
【类的设计】
该程序包含了四个类,如下:
1.Reader类,有读者的基本管理功能,具有以下私有数据:
int tag;//删除标记 1:已删;0:未删
int no;//读者编号
char name[10];//读者姓名
int borbook[Maxbor];//所借图书
2.读者库类Rdatabase, 具有以下私有数据:
int top;//读者记录指针
Reader read[Maxr];//读者记录
3.图书库类Book,有一本图书的基本功能,有以下私有数据:
int tag;//删除标记 1:已删;0:未删
int no;//图书编号
char name[20];//书名
int onshelf;//是否在架 1在架 0已借
4.图书库类BDatabase,有以下私有数据:
int top;//图书记录指针
Book book[Maxb];//图书记录
【特殊函数的设计说明】
构造函数
1.Reader类中构造函数Reader(),初始化函数;
2.读者库类RDatabase中,其构造函数Rdatabase(),将read.txt文件中所有读入读者记录rede[]中。
3.Book类中构造函数Book(),初始化函数;
4.图书库类BDatabase中,其构造函数中,将book.txt文件中所有读入图书记录book[]中。

拷贝构造函数
Reader类中的拷贝构造函数将getname()的返回值读者姓名拷贝到setname()中,Book类中的拷贝构造函数将getname()函数的返回值图书名拷贝到图书名设置函数setname()中。

析构函数
1.读者库类RDatabase中,其析构函数~Rdatabase(),将read[]中的所有未删记录写入到read.txt中;
2.图书库类BDatabase中,其析构函数~Bdatabase(),将book[]中的所有未删记录写入到book.txt中。

运算符重载
重载了“=”,当比较读者编号和图书编号时,重载;重载位运算符“〈〈”和“〉〉”等。

【主要函数算法流程图】

【程序的使用方法】
1.进入操作页面,按提示操作;
2.首先,新增图书和读者信息,之后就可以对以存在的信息进行操作;
3.操作当中,可以随时增加,更改和删除图书或读者信息;
4.当选择退出时,进行清屏。

二 程序上机调试报告
【语法错误及其排除】
1.在敲程序时,有很多拼写错误,例好多处把Readdata()误打Readdate();结束的分号,在不同的输入法状态下输入,这些小错误刚开始很难发现,不过有了经验,就很容易了。
2.创建新的构造函数时,使用出现了错误。重载构造函数要注意函数的访问权限,结果就不会出现错误。
【算法错误及其排除】
1.读者类中借书操作函数中,采用循环语句时判断读者已借图书量时for(int i=0;i<Maxbor;i++)误写为for(int i=1;i<Maxbor;i++),使循环发生错误。
2.指针使用错误,指针b和r混淆,导致编译错误得到“error C2660: 'retbook' : function does not take 1 parameters”错误报告。

3. 用C语言设计一个超市购物打印系统

我自己设计了一个,你试试!操作结束后按Ctrl+z显示清单。使用方面有什么不懂可以问我!
#include "stdio.h"
typedef struct{
char node[100]; /*商品编号*/
char name[100];/*商品名称*/
float price;/*商品价格*/
} datatype;

typedef struct node{
datatype food[100];
int len;/*存放商品总数*/
}SPku;

datatype Input(void)
{datatype x;<br/> scanf("%s %s %f",x.node,x.name,&x.price);<br/>首消 printf("输入完毕!");<br/>return x;<br/>}

void create(SPku *r)
{ int i;
printf("\n输入商品总数:");
scanf("%d",&r->len);
for(i=0;i<r->len;i++)
{printf("\n输入商品编号 名称 价格:"); <br/> r->food[i]=Input();<br/> }
}
int strlen(char s[])
{int i;<br/> for(i=0;i<s[i];i++);<br/> return i;<br/> }
int compare(char y[],char s[])
{int i;<br/>if(strlen(y)!=strlen(s))<br/> return 0;<br/>else<br/>轿脊 for(i=0;i<strlen(y);i++)<br/>者帆知 if(y[i]!=s[i])<br/> return 0;<br/> return 1;<br/>}

void Output(datatype f)
{
printf("\n%s %s %f",f.node,f.name,f.price);
}

int judge(SPku *r,char nd[])
{ int i;
for(i=0;i<r->len;i++)
if(compare(r->food[i].node,nd))
{ Output(r->food[i]) ;
return i;
}
return 1000;
}

main()
{SPku r,n;<br/> char nd[100];<br/> int k,j,i,y=0;<br/> printf("\n开始创建数据库...");<br/> create(&r);<br/> printf("\n*********商品总单*********");<br/> for(i=0;i<r.len;i++)<br/> Output(r.food[i]);<br/> printf("\n**************************");<br/>while((j=getchar())!=EOF)<br/> {<br/> printf("\n扫描输入商品的编号:");<br/> gets(nd);<br/> printf("输入成功!");<br/> k=judge(&r,nd);<br/> if(k==1000) <br/> printf("\n无此商品...");<br/> else<br/> n.food[y++]=r.food[k];<br/> }
printf("\n*********商品清单*********");
n.len=y;
for(i=0;i<n.len;i++)
Output(n.food[i]);
}

4. C语言程序设计;图书信息管理系统;图书信息包括:书号、书名、作者名、出版时间、价格,借阅次数等。

// 图书管理的实验报告

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[30],author[20];
}books[100];
void page_title(char *menu_item)
{
printf("\n- %s -\n\n",menu_item);
}

void book_add(void)
{
int n;
page_title("注册");
for(n=0;n<100;n++)
if(books[n].id==0) break;
printf("序号:");
scanf("%d",&books[n].id);
printf("书名:");
scanf("%s",&books[n].name);
printf("作者:");
scanf("%s",&books[n].author);
printf("数量:");
scanf("%d",&books[n].total);
books[n].store=books[n].total;

}

int search_book(void)
{
int n,i;
page_title("查找");
printf("请输入图书序号:");
scanf("%d",&i);
for(n=0;n<100;n++)
{
if(books[n].id==i)
{
printf("书名:%s\n",books[n].name);
printf("作者:%s\n",books[n].author);
printf("存数:%d\n",books[n].store);
printf("总数:%d\n",books[n].total);
return n;
}
}
printf("\n输入有错或图书序号不存在.\n");
return -1;
}

void book_out(void)
{
int n,s,l,d;
page_title("借书");
if((n=search_book())!=-1&&books[n].store>0)
{
printf("请输入借书证序号:");
scanf("%d",&s);
printf("请输入可借天数:");
scanf("%d",&d);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store--;
}
if(n!=-1&&books[n].store==0) printf("此书已经全部借出.\n");

}
/*借书的函数,首先调用找书函数*/

void book_in(void)
{
int n,s,l;
page_title("还书");
if((n=search_book())!=-1&&books[n].store<books[n].total)
{
printf("借阅者图书证列表:\n");
for(l=0;l<10;l++)
if (books[n].usr[l]!=0)
printf("[%d] - %d天\n",books[n].usr[l],books[n].days[l]);
printf("请输入借书证序号:");
scanf("%d",&s);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1&&books[n].store==books[n].total)
printf("全部入藏.\n");

}

void book_del(void)
{
int n;
page_title("注销");
if((n=search_book())!=-1) books[n].id=0;
printf("该书已注销.\n");

}

void main(void)
{ char n;
page_title("请选择");
printf("1 注册\n2 查找\n");
printf("3 借书\n4 还书\n5 注销书");
printf("\n0 退出\n");
while(n=getchar()){
switch(n)
{
case '1' : book_add();break;
case '2' :search_book();break;
case '3' : book_out();break;
case '4' : book_in();break;
case '5' : book_del();break;
case '0' :exit(0);
}printf("\n\n请选择\n1 注册\n2 查找\n3 借书\n4 还书\n5 注销书\n0 退出\n\n");
getchar();
}
}

5. c语言题目!跪求大佬做!

#include<stdio.h>

main(){
int n1,n2,n3

double x;
printf("输入三种商品购买数量,空格分开:" );
scanf("%d%d%d",&n1,&n2,&n3);
x=n1*2.6;
x+=n2*12*(n2>10,0.8,1);
x+=n*4.8*(n3>20,0.7,1);
printf("总金额:%lf\n",x);

}

6. 用c语言设计一个超市管理系统程序,要求能添加商品,能查询商品,能购买商品,能展示商品。

超市管理系统
*/
#include<stdio.h>
#include<string.h>
//欢迎界面//
void welcome();
//功能浏览//
void mainMenu();
//购物结算//
void saleCalc();
//进货管理//
void addGoods();
//修改信息
void updateGoods();
//显示商品//
void showGoods();
//删除商品//
void deleteGoods();
//查询商品//
int searchGoods();
//购买结算
void saleCalc();
//更新库存//
void updateGoodsNum(int number,char name[50]);
//结构体
struct goods
{
char name[50];//商品名称
int num;//商品数量
float price;//商品价格
};
int count;//商品种类数量
goods list[1000];//声明goods的变量数组
char name[50];
void main()//主函数
{
int num;
welcome();
do{
mainMenu();
printf("请选择功能:");
scanf("%d",&num);
switch(num)
{
case 1:
saleCalc();
break;
case 2:
addGoods();
break;
case 3:
updateGoods();
break;
case 4:
showGoods();
break;
case 5:
deleteGoods();
break;
case 0:
break;
}
}while(num!=0);
}
void welcome()//欢迎界面
{
printf("-------------------------------------------------------------------------\n");
printf("****************欢迎使用超市管理系统*******************\n");
printf("-------------------------------------------------------------------------\n");
}
void mainMenu()//功能浏览界面
{
printf("****1.购物结算****\n");
printf("****2.进货管理****\n");
printf("****3.修改商品****\n");
printf("****4.显示商品****\n");
printf("****5.删除商品****\n");
printf("****0.退出系统****\n");
}
//查询信息
int searchGoods()//查询商品信息
{
printf("请输入您要购买商品的名字:");
scanf("%s",name);
for(int i=0;i<count;i++)
{
if(stricmp(name,list[i].name)==0)
{
return 1;
}
else
{
printf("对不起了,没有找到%c商品\n",name);
return -1;
}
}
}
//购物结算
void saleCalc()//购物结算
{
int number,i,s;
float priceGoods=0,sum=0,money;
char c=' ';
s=searchGoods();
do
{
if(s==-1)
{
s=searchGoods();
}else
{
printf("该商品b存在");
for(i=0;i<count;i++)
{
if(strcmp(name,list[i].name)==0)
{
priceGoods=list[i].price;
break;
}
}
printf("请输入您要购买的数量:");
scanf("%d",&number);
sum=priceGoods*number;
updateGoodsNum(-number,name);
printf("是否继续购买(y/n)");
fflush(stdin);
c=getchar();
}
}while(c=='y'||c=='Y');
printf("本次消费总金额为:%.2f",sum);
printf("请输入您的实际付款金额:");
scanf("%f",&money);
printf("找零:%.2f\n",money-sum);
}
//进货管理
void addGoods() //商品的录入
{
int i=0;
char c=' ';
do
{
printf("请输入商品的名称:");
fflush(stdin);
scanf("%s",list[i].name);
printf("请输入商品的数量:");
scanf("%d",&list[i].num);
printf("请输入商品的单价:");
scanf("%f",&list[i].price);
printf("是否继续(y/n)");
fflush(stdin);
c=getchar();
}while(c=='Y'||c=='y');
}
//更新库存
void updateGoodsNum(int number,char name[50])
{
int i;
for(i=0;i<count;i++)
{
list[i].num+=number;//list[i].num=list[i].num+number
}
}
//显示货物信息
void showGoods()
{
printf("商品名称\t数量\t单价\n");
for(int i=0;i<count;i++)
{
printf("%s\t%d\t%.2f\n",list[i].name,list[i].num,list[i].price);
}
}
//修改商品信息
void updateGoods()
{
int i;
printf("请输入您要修改商品的名字:");
scanf("%s",&name);
for(i=0;i<count;i++)
{
if(strcmp(name,list[i].name)==0)
{
printf("请输入新的商品名字:");
scanf("%s",list[i].name);
printf("请输入您要修改商品的数量:");
scanf("%d",list[i].num);
printf("请输入您要修改商品的单价:");
scanf("%f",list[i].price);
}
else
{
printf("对不起,没有找到该商品信息!");
}
}
}
//删除商品信息
void deleteGoods()
{
int index=-1;
printf("请输入您要删除的商品名字:");
scanf("%s",name);
for(int i=0;i<count;i++)
{
if(strcmp(name,list[i].name)==0)
{
index=i;
}
}if(index==-1)
{
printf("对不起!没有找到您要删除的商品信息!");
}
else{
for(int i=index;i<count;i++)
{
list[i]=list[i+1];
}
}
}