當前位置:首頁 » 編程語言 » c語言更改庫存信息的代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言更改庫存信息的代碼

發布時間: 2022-10-07 19:01:45

c語言圖書信息管理系統加一個功能:顯示出不同圖書的庫存量。代碼怎麼改急!

資料庫或者文件里加一個變數用於存儲就行了

Ⅱ 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結構體與指針,就這個代碼思路應該看得明白,真正的實現你自己實現吧
這樣對你會更好寫。可能會有錯誤的地方,請謹慎。 */

Ⅲ 誰知道用c語言向資料庫做增刪改查嗎

我曾經寫過C語言的資料庫系統..
給你部分代碼(一個銷售函數)以作參考...
void
book_out()
//銷售函數
{
char
temp;
EXEC
SQL
BEGIN
DECLARE
SECTION;
/*主變數定義開始.*/
int
Hout_shuliang;
int
Hshuliang;///////////
char
Hbook_id[11];
EXEC
SQL
END
DECLARE
SECTION;
/*主變數定義結束*/
lab3:
printf("請輸入圖書編號:");
scanf("%s",&Hbook_id);
printf("請輸入賣出本數:");
scanf("%d",&Hout_shuliang);
//先將庫存量取出到主變數
EXEC
SQL
select
book_shuliang
into
:Hshuliang
from
book_kucun
where
book_id=:Hbook_id;
if(Hshuliang<Hout_shuliang)
//假如庫存不足,銷售不成功.
{
printf("輸入有誤.沒那麼多庫存,請重新輸入.\n");
goto
lab3;
}
//將銷售記錄插入到book_out(銷售表)數據表.
EXEC
SQL
insert
into
book_out
values(:Hbook_id,:Hout_shuliang,GETDATE());
EXEC
SQL
COMMIT
TRANSACTION;
/*事務提交*/
printf("售出成功,輸入Y繼續輸入其他要售出的書.其他鍵返回主菜單:");
getchar();//////////////////////////
scanf("%c",&temp);
if(temp=='y'||temp=='Y')
goto
lab3;
}

Ⅳ c語言倉庫管理系統源代碼

學籍管理的程序,你自己改改吧
#include<stdio.h>
#include<windows.h>
#include<conio.h>
int add();
int amend();
int remove();
int show_student();
int show_class();
struct info //定義結構體info,用於存儲學生信息
{
char name[20]; //姓名
char sex[20]; //性別
char idcard[20]; //身份證號碼
char stuid[10]; //學號
char academe[20]; //學院
char specialty[20]; //專業
char classid[20]; //班級
char home[20]; //生源地
}stu[100];
int j=0;
int main(void) //主函數
{
/*登陸界面設計*/
char gongnengxuanzhe;
int flag=1;
system("cls");
printf("\n");
printf("\t\t\t\t 歡迎\n");
printf("\n\n\t尊敬的用戶, 非常感謝您使用本系統 , 您的完美體驗將是我們前進的方向 !\n\n\n");
printf("\t系統功能簡介:\n\n\n");
printf("\t\t①:通過鍵盤輸入某位學生的學生證信息。\n\n");
printf("\t\t②:給定學號,顯示某位學生的學生證信息。\n\n");
printf("\t\t③:給定某個班級的班號,顯示該班所有學生的學生證信息。\n\n");
printf("\t\t④:給定某位學生的學號,修改該學生的學生證信息。\n\n");
printf("\t\t⑤:給定某位學生的學號,刪除該學生的學生證信息。\n\n");
printf("\t\t⑥:按出生日期對全班學生的信息進行排序。\n\n\n");
printf("\t按任意鍵進入系統......");
getch();
do
{
system("cls");
printf("\n\n\n");
printf(" 尊敬的用戶 ,歡迎您使用本系統 !\n");
printf("\n\n\n");
printf(" 1.增加學生信息\n\n");
printf(" 2.修改學生信息\n\n");
printf(" 3.刪除學生信息\n\n");
printf(" 4.顯示單個學生信息\n\n");
printf(" 5.顯示整個班級學生信息\n\n");
printf(" 0.退出系統\n\n\n\n");
printf(" 請選擇您需要使用的功能:");
gongnengxuanzhe=getch();
switch(gongnengxuanzhe)
{
case '1':add();break;
case '2':amend();break;
case '3':remove();break;
case '4':show_student();break;
case '5':show_class();break;
case '0':flag=0;break;
default:
{
printf("\n\n 您的輸入有誤,請仔細閱讀使用說明!");
printf("\n 任意鍵繼續...");
getch();
}

}
}while(flag==1);
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t尊敬的用戶,非常感謝您的使用,您對於完美的追求是我們唯一的動力!");
printf("\n\n\t\t\t 按任意鍵退出系統......");
getch();
return 0;
}
int add() //增加學生信息函數
{
char flag='1';
do
{
system("cls");
printf("\n\t姓名:");
scanf("%s",&stu[j].name);
printf("\n\n\t性別:");
scanf("%s",&stu[j].sex);
printf("\n\n\t身份證號:");
scanf("%s",&stu[j].idcard);
printf("\n\n\t學院:");
scanf("%s",&stu[j].academe);
printf("\n\n\t專業:");
scanf("%s",&stu[j].specialty);
printf("\n\n\t班級:");
scanf("%s",&stu[j].classid);
printf("\n\n\t學號:");
scanf("%s",&stu[j].stuid);
printf("\n\n\t生源地:");
scanf("%s",&stu[j].home);
j++;
printf("\n\t繼續增加請鍵入1,返回請鍵入其他任意鍵:");
getchar();
flag=getchar();
}while(flag=='1');
return 0;
}
int amend() //修改學生信息函數
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系統無任何可以修改的記錄,請先行輸入數據!");
printf("\n\n\t\t\t 按任意鍵返回......");
getch();
return 0;
}
char a[20];
int z;
int flag=0;
do
{
system("cls");
printf("\n\t需要修改的學生學號:");
scanf("%s",a);
for(z=0;z<j;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
break; //break退出後,z++不會執行
}
}
if(flag==0)
{
printf("\t對不起,你請求學生信息不存在,請核實後重試!\n");
printf("\t按任意鍵繼續......");
getch();
}
}while(flag==0);
system("cls");
printf("\n\t姓名:");
scanf("%s",&stu[z].name);
printf("\n\n\t性別:");
scanf("%s",&stu[z].sex);
printf("\n\n\t身份證號:");
scanf("%s",&stu[z].idcard);
printf("\n\n\t學院:");
scanf("%s",&stu[z].academe);
printf("\n\n\t專業:");
scanf("%s",&stu[z].specialty);
printf("\n\n\t班級:");
scanf("%s",&stu[z].classid);
printf("\n\n\t學號:");
scanf("%s",&stu[z].stuid);
printf("\n\n\t生源地:");
scanf("%s",&stu[z].home);
return 0;
}
int remove() //刪除學生信息函數
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系統無任何可以刪除的記錄,請先行輸入數據!");
printf("\n\n\t\t\t 按任意鍵返回......");
getch();
return 0;
}
char a[20];
int z;
int x;
int flag=0;
do
{
system("cls");
printf("\n\t需要刪除的學生學號:");
scanf("%s",a);
for(z=0;z<j;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
for(x=z;x<j;x++)
{
strcpy(stu[x].name,stu[x+1].name);
strcpy(stu[x].sex,stu[x+1].sex);
strcpy(stu[x].idcard,stu[x+1].idcard);
strcpy(stu[x].academe,stu[x+1].academe);
strcpy(stu[x].specialty,stu[x+1].specialty);
strcpy(stu[x].classid,stu[x+1].classid);
strcpy(stu[x].stuid,stu[x+1].stuid);
strcpy(stu[x].stuid,stu[x+1].stuid);
}
j--;
printf("\n\t刪除成功!");
printf("\n\t按任意鍵返回上級菜單......");
getch();
}
}
if(flag==0)
{
printf("\t對不起,你請求學生信息不存在,請核實後重試!\n");
printf("\t按任意鍵繼續......");
getch();
}
}while(flag==0);
return 0;
}
int show_student() //單個顯示學生信息函數
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系統無任何可以顯示的記錄,請先行輸入數據!");
printf("\n\n\t\t\t 按任意鍵返回......");
getch();
return 0;
}
char a[20];
int z;
int flag=0;
do
{
system("cls");
printf("\n\t需要顯示的學生學號:");
scanf("%s",a);
for(z=0;z<j;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
system("cls");
printf("\n\t姓名:%s",stu[z].name);
printf("\n\n\t性別:%s",stu[z].sex);
printf("\n\n\t身份證號:%s",stu[z].idcard);
printf("\n\n\t學院:%s",stu[z].academe);
printf("\n\n\t專業:%s",stu[z].specialty);
printf("\n\n\t班級:%s",stu[z].classid);
printf("\n\n\t學號:%s",stu[z].stuid);
printf("\n\n\t生源地:%s",stu[z].home);
printf("\n\n\t按任意鍵返回上級菜單......");
getch();
}
}
if(flag==0)
{
printf("\t對不起,你請求顯示的學生信息不存在,請核實後重試!\n");
printf("\t按任意鍵繼續......");
getch();
}
}while(flag==0);
return 0;
}
int show_class() //顯示整個班級學生信息函數
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系統無任何可以顯示的記錄,請先行輸入數據!");
printf("\n\n\t\t\t 按任意鍵返回......");
getch();
return 0;
}
char a[20];
int z;
int x;
int flag=0;
do
{
system("cls");
printf("\n\t需要顯示的班級號碼:");
scanf("%s",a);
for(z=0;z<j;z++)
{
if(strcmp(stu[z].classid,a)==0)
{
flag=1;
system("cls");
printf("\t%s %s 基本信息\n",stu[z].specialty,stu[z].classid);
for(x=0;x<j;x++)
{
if(strcmp(stu[x].classid,a)==0)
{
printf("\n\n\t姓名:%s",stu[z].name);
printf("\n\t性別:%s",stu[z].sex);
printf("\n\t身份證號:%s",stu[z].idcard);
printf("\n\t學院:%s",stu[z].academe);
printf("\n\t專業:%s",stu[z].specialty);
printf("\n\t班級:%s",stu[z].classid);
printf("\n\t學號:%s",stu[z].stuid);
printf("\n\t生源地:%s",stu[z].home);
}
}
printf("\n\n\t按任意鍵返回上級菜單......");
getch();
}
}
if(flag==0)
{
printf("\t對不起,你請求顯示的班級信息不存在,請核實後重試!\n");
printf("\t按任意鍵繼續......");
getch();
}
}while(flag==0);
return 0;
}
有疑問聯系我,[email protected]
請採納。

Ⅳ .求用c語言寫的源代碼。。。圖書管理系統 系統功能主要是管理圖書的庫存信息、圖書的借閱信息以及借閱

額額,你這個程序夠復雜的啊
這樣的程序,一般都是定製寫的
網上很少有完全符合要求的啊
所以,我做程序編程的,主要做C語言的,可以搞定的啊哈
只不過哈,無利不起早啊
嘎嘎

Ⅵ c語言圖書庫存管理系統

#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<vector>#include<queue>#include<stack>#include<map>#include<string>#include<climits>#include<cmath>#define N 1000010#define LL long longusing namespace std;#include<iostream>#include<iomanip>#include<string>#include<fstream>#include<stdio.h>using namespace std;const int Maxb=10000; //最多的圖書class Book//圖書類{int tag; //刪除標記:已刪0:未刪int number; //ISBN書號char name[20]; //書名char author[10]; //主編char number2[10];//版次char position[20];//出版社char time[20];//出版年int price;//定價int onshelf; //是否在架1:在架0:已借public:Book() {}char *getname() { return name; } //獲取姓名int getnumber() { return number; } //獲取ISBN書號int gettag() { return tag; } //獲取刪除標記char *getauthor() {return author;} //獲取主編char *getnumber2() {return number2;} //獲取版次char *getposition() {return position;} //獲取出版社char *gettime() {return time;} //獲取出版年char getprice() {return price;} //獲取圖書定價void delbook() { tag=1; } //刪除圖書void addbook(int n,char *na,char *au,char *n2,char *da,char *ti,int pr) //增加圖書{tag=0;number=n;price=pr;strcpy(name,na);strcpy(author,au);strcpy(number2,n2);strcpy(position,da);strcpy(time,ti);onshelf=1;} void disp() //輸出圖書{cout << setw(10) << number << setw(10) << name << setw(10)<< setw(10)<<author<<setw(10)<<number2<<setw(10)<<position<<setw(10)<<time<<setw(10)<<price<<endl;}}; class BDatabase //圖書庫類{int top; //圖書記錄指針Book book[Maxb]; //圖書記錄public:BDatabase() //構造函數,將book.txt讀到book[]中{Book b;top=-1;fstream file("book.txt",ios::in);while (1){file.read((char *)&b,sizeof(b));if (!file) break;top++;book[top]=b;}file.close();} void clear() //全刪{top=-1;} int addbook(int n,char *na,char *au, char *n2, char *da,char *ti,int pr) //增加圖書{Book *p=search1(n);if (p==NULL){top++;book[top].addbook(n,na,au,n2,da,ti,pr);return 1;}return 0;} Book *search1(int bookid) //查找圖書{for (int i=0;i<=top;i++)if (book[i].getnumber()==bookid &&book[i].gettag()==0)return &book[i];return NULL;} Book *search2(int bookid,char *name) //按書名查找圖書{ for(int i=0;i<=top;i++) if(strcmp(book[i].getname(),name)==0) {bookid=book[i].getnumber(); return &book[i]; } return NULL;} Book *search3(int bookid,char *author) //按主編查找圖書{ for(int i=0;i<=top;i++) if(strcmp(book[i].getauthor(),author)==0) {bookid=book[i].getnumber(); return &book[i]; } return NULL;} void bookdata(); //圖書庫維護 void disp(){ cout<<setw(10)<<"圖書書號"<<setw(10)<<"圖書名字"<<setw(10)<<"圖書主編"<<setw(10)<<"版次"<<setw(10)<<"出版社"<<setw(10)<<"出版年"<<setw(10)<<"價格"<<endl<<endl<<endl<<endl;for (int i=0;i<=top;i++)if (book[i].gettag()==0)book[i].disp();}~BDatabase() //析構函數,將book[]寫入book.txt文件中{fstream file("book.txt",ios::out);for (int i=0;i<=top;i++)if (book[i].gettag()==0)file.write((char *)&book[i],sizeof(book[i]));file.close();}}; void BDatabase::bookdata(){int choice=1;int choice2=1;int choice3=1;int choice4;char bname[40];char editor[40];char banci[40];char position[40];char year[40];int value;int bookid;Book *b;while (choice!=0){ cout<<endl<<endl;cout<<" **************************** "<<endl;cout<<" **** 1添加圖書 **** "<<endl;cout<<" **** 3 刪除圖書 **** "<<endl;cout<<" **** 4 圖書查詢 **** "<<endl;cout<<" **** 5 顯示圖書 **** "<<endl;cout<<" **** 6 全部刪除 **** "<<endl;cout<<" **** 7 借書 **** "<<endl;cout<<" **** 8 還書 **** "<<endl;cout<<" **** 0 退出 **** "<<endl;cout<<" ****************************"<<endl<<endl;cout<<endl<<"請按鍵選擇您需要的操作:";cin>>choice;while(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=5&&choice!=6&&choice!=0){ cout<<endl<<" ** 您輸入的編號在菜單里不存在,請重新輸入 **"<<'\a'<<endl<<endl; cout<<" 請選擇您需要的操作:"; cin>>choice;} switch (choice){case 1:cout <<"輸入ISBN書號(一定為數字否則會異常):";cin >> bookid; cout <<"輸入書名:";cin >> bname; cout <<"輸入主編:";cin >>editor;cout <<"輸入版次(一定為數字否則會異常):";cin>>banci;cout<<"輸入出版社:";cin>>position;cout<<"輸入出版年(一定為數字否則會異常):"; cin>>year;cout<<"輸入價格(一定為數字否則會異常):";cin>>value;addbook(bookid,bname,editor,banci,position,year,value);cout<<"ISBN書號"<<bookid<<"添加成功,如需返回主菜單請按1,退出系統請按0(一定要輸入數字)";cin>>choice4;while (choice4!=0&&choice4!=1){ cout<<"輸入錯誤請重新輸入"<<endl; cin>>choice4;}switch (choice4){case 1:choice=1;break;case 0: choice=0; break;}break; case 3:cout << " 輸入ISBN書號:";cin >> bookid;b=search1(bookid);if (b==NULL){cout << " 該圖書不存在" << endl;break;}b->delbook();break;case 4: cout<<"查找方式:"<<endl<<"1按ISBN書號查詢 2按書名查詢 3按主編查詢 0退出:"; cin>>choice3;switch(choice3){case 1: {cout << " 輸入ISBN書號:"; //按ISBN書號查詢cin >> bookid;b=search1(bookid);if (b==NULL){cout << " 該圖書不存在" << endl;break;}b->disp();}break;case 2:{ cout<<"請輸入書名:"; cin>>bname; b=search2(bookid,bname); if(b==NULL) { cout<<"該圖書不存在啊!"<<endl; break; } b->disp();} break;case 3: { cout<<"請輸入主編:"; cin>>editor; b=search3(bookid,editor); if(b==NULL) { cout<<"該主編不存在!"<<endl; break; } b->disp();} break;}break;case 5:disp();break;case 6:clear();break;}}cout<<endl<<" ****** 慢走 ******"<<endl<<endl<<endl;}; int main(){BDatabase BookDB;cout<<endl<<endl<<endl;cout<<" Welcome to the library of SCU "<<endl;cout<<" 歡 迎 來 到XXXX 大 學 圖 書 館 "<<endl;cout<<endl<<endl<<"請輸入0進入圖書館"<<endl;int w;cin>>w;if(w==0)BookDB.bookdata();system("pause");return 0;}

Ⅶ c語言圖書信息管理系統 在不影響原本功能的前提下,顯示出不同書的庫存量,這代碼該怎麼改急急急!

那要看你怎麼儲存了圖書信息,要把代碼貼出來。

Ⅷ 用C語言編寫大學圖書庫存管理系統 若答案合適 可再給100分

好了,希望能夠幫到您。

如果你真的要純c的話,只需要改一下輸入輸出就可。

即:cin,cout改為scanf,printf。

//MemoryTime
//1347K0MS
//by:Snarl_jsb
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<climits>
#include<cmath>
#defineN1000010
#defineLLlonglong
usingnamespacestd;
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<stdio.h>
usingnamespacestd;
constintMaxb=10000;//最多的圖書
classBook//圖書類
{
inttag;//刪除標記1:已刪0:未刪
intnumber;//ISBN書號
charname[20];//書名
charauthor[10];//主編
charnumber2[10];//版次
charposition[20];//出版社
chartime[20];//出版年
intprice;//定價
intonshelf;//是否在架1:在架0:已借
public:
Book(){}
char*getname(){returnname;}//獲取姓名
intgetnumber(){returnnumber;}//獲取ISBN書號
intgettag(){returntag;}//獲取刪除標記
char*getauthor(){returnauthor;}//獲取主編
char*getnumber2(){returnnumber2;}//獲取版次
char*getposition(){returnposition;}//獲取出版社
char*gettime(){returntime;}//獲取出版年
chargetprice(){returnprice;}//獲取圖書定價
voiddelbook(){tag=1;}//刪除圖書
voidaddbook(intn,char*na,char*au,char*n2,char*da,char*ti,intpr)//增加圖書
{
tag=0;
number=n;
price=pr;
strcpy(name,na);
strcpy(author,au);
strcpy(number2,n2);
strcpy(position,da);
strcpy(time,ti);
onshelf=1;
}voiddisp()//輸出圖書
{
cout<<setw(10)<<number<<setw(10)<<name<<setw(10)
<<setw(10)<<author<<setw(10)<<number2<<setw(10)<<position<<setw(10)<<time<<setw(10)<<price<<endl;
}
};

classBDatabase//圖書庫類
{
inttop;//圖書記錄指針
Bookbook[Maxb];//圖書記錄
public:
BDatabase()//構造函數,將book.txt讀到book[]中
{
Bookb;
top=-1;
fstreamfile("book.txt",ios::in);
while(1)
{
file.read((char*)&b,sizeof(b));
if(!file)break;
top++;
book[top]=b;
}
file.close();
}


voidclear()//全刪
{
top=-1;
}


intaddbook(intn,char*na,char*au,char*n2,char*da,char*ti,intpr)//增加圖書
{
Book*p=search1(n);
if(p==NULL)
{
top++;
book[top].addbook(n,na,au,n2,da,ti,pr);
return1;
}
return0;
}


Book*search1(intbookid)//查找圖書
{
for(inti=0;i<=top;i++)
if(book[i].getnumber()==bookid&&
book[i].gettag()==0)
return&book[i];
returnNULL;
}


Book*search2(intbookid,char*name)//按書名查找圖書
{
for(inti=0;i<=top;i++)
if(strcmp(book[i].getname(),name)==0)
{bookid=book[i].getnumber();
return&book[i];
}

returnNULL;
}

Book*search3(intbookid,char*author)//按主編查找圖書
{
for(inti=0;i<=top;i++)
if(strcmp(book[i].getauthor(),author)==0)
{bookid=book[i].getnumber();
return&book[i];
}

returnNULL;
}

voidbookdata();//圖書庫維護

voiddisp()
{
cout<<setw(10)<<"圖書書號"<<setw(10)<<"圖書名字"<<setw(10)<<"圖書主編"<<setw(10)<<"版次"<<setw(10)<<"出版社"<<setw(10)<<"出版年"<<setw(10)<<"價格"<<endl<<endl<<endl<<endl;
for(inti=0;i<=top;i++)
if(book[i].gettag()==0)
book[i].disp();
}
~BDatabase()//析構函數,將book[]寫入book.txt文件中
{
fstreamfile("book.txt",ios::out);
for(inti=0;i<=top;i++)
if(book[i].gettag()==0)
file.write((char*)&book[i],sizeof(book[i]));
file.close();
}
};

voidBDatabase::bookdata()
{
intchoice=1;
intchoice2=1;
intchoice3=1;
intchoice4;
charbname[40];
chareditor[40];
charbanci[40];
charposition[40];
charyear[40];
intvalue;
intbookid;
Book*b;
while(choice!=0)
{
cout<<endl<<endl;
cout<<"****************************"<<endl;
cout<<"****1添加圖書****"<<endl;
cout<<"****3刪除圖書****"<<endl;
cout<<"****4圖書查詢****"<<endl;
cout<<"****5顯示圖書****"<<endl;
cout<<"****6全部刪除****"<<endl;
cout<<"****7借書****"<<endl;
cout<<"****8還書****"<<endl;
cout<<"****0退出****"<<endl;
cout<<"****************************"<<endl<<endl;
cout<<endl<<"請按鍵選擇您需要的操作:";
cin>>choice;
while(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=5&&choice!=6&&choice!=0){
cout<<endl<<"**您輸入的編號在菜單里不存在,請重新輸入**"<<'a'<<endl<<endl;
cout<<"請選擇您需要的操作:";
cin>>choice;
}

switch(choice)
{
case1:
cout<<"輸入ISBN書號(一定為數字否則會異常):";
cin>>bookid;
cout<<"輸入書名:";
cin>>bname;
cout<<"輸入主編:";
cin>>editor;
cout<<"輸入版次(一定為數字否則會異常):";
cin>>banci;
cout<<"輸入出版社:";
cin>>position;
cout<<"輸入出版年(一定為數字否則會異常):";
cin>>year;
cout<<"輸入價格(一定為數字否則會異常):";
cin>>value;
addbook(bookid,bname,editor,banci,position,year,value);
cout<<"ISBN書號"<<bookid<<"添加成功,如需返回主菜單請按1,退出系統請按0(一定要輸入數字)";
cin>>choice4;
while(choice4!=0&&choice4!=1)
{
cout<<"輸入錯誤請重新輸入"<<endl;
cin>>choice4;}
switch(choice4)
{
case1:
choice=1;
break;
case0:
choice=0;
break;}
break;


case3:
cout<<"輸入ISBN書號:";
cin>>bookid;
b=search1(bookid);
if(b==NULL)
{
cout<<"該圖書不存在"<<endl;
break;
}
b->delbook();
break;
case4:
cout<<"查找方式:"<<endl<<"1按ISBN書號查詢2按書名查詢3按主編查詢0退出:";
cin>>choice3;
switch(choice3)
{
case1:
{cout<<"輸入ISBN書號:";//按ISBN書號查詢
cin>>bookid;
b=search1(bookid);
if(b==NULL)
{
cout<<"該圖書不存在"<<endl;
break;
}
b->disp();
}
break;
case2:
{
cout<<"請輸入書名:";
cin>>bname;
b=search2(bookid,bname);
if(b==NULL)
{
cout<<"該圖書不存在啊!"<<endl;
break;
}
b->disp();
}

break;
case3:
{
cout<<"請輸入主編:";
cin>>editor;
b=search3(bookid,editor);
if(b==NULL)
{
cout<<"該主編不存在!"<<endl;
break;
}
b->disp();
}
break;
}
break;
case5:
disp();
break;
case6:
clear();
break;
}
}
cout<<endl<<"******慢走******"<<endl<<endl<<endl;
};

intmain()
{
BDatabaseBookDB;
cout<<endl<<endl<<endl;
cout<<"WelcometothelibraryofSCU"<<endl;
cout<<"歡迎來到四川大學圖書館"<<endl;
cout<<endl<<endl<<"請輸入0進入圖書館"<<endl;
intw;
cin>>w;
if(w==0)
BookDB.bookdata();
system("pause");
return0;
}

Ⅸ 商品庫存管理系統的c語言源代碼

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

struct BOOK
{
int id,usr[10],total,store,days[10];
char name[31],author[21];
}books[100];
/*上面是結構體的定義,用於存放書籍及借書的信息。*/

void page_title(char *menu_item)
{
clrscr();
printf(">>> 圖 書 管 理 系 統 <<<\n\n- %s -\n\n",menu_item);
}
/*上面是列印頁眉的函數,同時通過參數menu_item,可以顯示當前的狀態。*/

void return_confirm(void)
{
printf("\n按任意鍵返回……\n");
getch();
}
/*上面是返回前請求確認的函數,以便在返回前觀察結果*/

int search_book(void)
{
int n,i;
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 of ",books[n].store);
printf("%d\n",books[n].total);
return n;
}
}
printf("\n輸入錯誤或無效圖書序號.\n");
return -1;
}
/*上面的函數是在數組中找到圖書號匹配的記錄,顯示其信息並返
回數組下標,如果找不到相應記錄則提示錯誤並返回-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");
return_confirm();
}
/*上面是借書的函數,首先調用找書函數*/

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");
return_confirm();
}

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);

Ⅹ c語言設計實現一個簡單庫存管理程序編程

我有一個學生管理系統程序,你可以把學生量改成庫存量。
希望對你能有幫助。http://..com/question/2202293700663164948.html?oldq=1