c語言圖書管理系統
【說明及要求】
實現圖書信息(書號、書名、作者、定價、數量)的新增、修改、刪除和查詢功能;實現入庫信息(書號、單價、數量、小計、入庫日期)登記;實現入庫統計(按指定的書號統計入庫的數量和明細)。注意:圖書入庫時相應圖書的數量必須進行修改。
【提示】
(1)定義結構體分別表示圖書信息和入庫信息;
(2)用兩個文件分別存放圖書信息和入庫信息;
(3)分別定義函數實現圖書信息的新增、修改、刪除、查詢、圖書入庫登記,以及按圖書號統計入庫數量和明細的功能;
(5)在main函數中調用上述函數,進行演示。
最佳回答:
這個功能比較少,可能符合你的要求,對於查詢功能,自己可以添加修改結構體,注意數據格式就行了,另外還有一個用類編寫的,功能也多一些,要的話留郵箱
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct stu
{
char name[20];
long int number;
int snum;
char sex[20];
char add[30] ;
char time[20];
char tel[20];
struct stu *next;
}stu,*student;
int init(student &s);
void insert(student &s);
void print(student &s);
int delete(student &s);
void find (student &s);
void findname(student &s);
void findnum(student &s);
void modifay(student &s);
void putfile(student &s);
void getfile(student &s);
void main()
{
student s;
init(s);
cout<<"歡迎使用學生管理系統."<<endl;
cout<<" "<<endl;
cout<<endl;
while(1)
{
int i;
mainint:
cout<<"請選擇相關操作:"<<endl<<"1.建立學生資料文件."<<endl<<"2.浏覽."<<endl<<"3.刪除."<<endl;
cout<<"4.查詢."<<endl<<"5.修改."<<endl<<"6.打開學生文件."<<endl<<"7.退出管理系統." <<endl<<"請選擇:";
cin>>i;
if(i<0||i>7)
{
cout<<"輸入了錯誤的數字,Again!"<<endl<<endl;
goto mainint;
}
switch(i)
{
case 1: insert(s);break;
case 2: print(s);
putfile(s);
break;
case 3: ldelete(s);break;
case 4: find(s);break;
case 5: modifay(s);
break;
case 6: getfile(s);break;
case 7: exit(0);
}
}
}
int init(student &s)
{
s=(student)malloc(sizeof(stu));
if (s)
{
s->next=NULL;
return 0;
}
else return -1;
}
void insert(student &s) //insert
{
cout<<endl;
student p,q;
p=(student)malloc(sizeof(stu));
cout<<"請輸入學生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"學號:";
cin>>p->number;
cout<<endl;
cout<<"性別:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"出生年月:" ;
cin>>p->time;
cout<<endl;
cout<<"宿捨號:";
cin>>p->snum;
cout<<endl;
cout<<"宿捨號碼:";
cin>>p->tel;
q=s;
while(!(q->next==NULL)&&(q->next->number<p->number))
q=q->next;
p->next=q->next;
q->next=p;
//if()p->next=NULL;
//free(p);
}
int ldelete(student &s) //delete
{
cout<<endl;
student p,a;
p=s ;
cout<<"請輸入刪除的學號:";
long int number;
cin>>number;
while(p)
{ if (p->number==number)
{
a->next=p->next;
free(p); return(0);}
else
{ a=p;
p=p->next;} }
cout<<"沒有找到你要刪除的選項!"<<endl<<endl;return(-1);
}
void print(student &s)
{
int a;
a=0;
student p;
p=s->next;
cout<<"姓名 "<<"學號 " <<"性別 "<<"家庭住址 "<<"出生年月 "<<"宿捨號"<<"宿捨號碼"<<endl;
while(p)
{
a++;
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
p=p->next;
}
cout<<endl;
if (a==0)
cout<<"還沒有學生信息!"<<endl<<endl ;
}
void find (student &s) //find
{
findl:
cout<<"請選擇查找方法:"<<endl<<"1.按姓名查找."<<endl<<"2.按學號查找."<<endl;
cout<<"請選擇:";
int k;
cin>>k;
if(k<0||k>3)
{
cout<<"輸了入錯誤數字,Again!"<<endl<<endl;
goto findl;
}
switch(k)
{
case 1: findname(s);break;
case 2: findnum(s);break;
}
}
void findname(student &s) //find by name
{
student p;
p=s->next;
cout<<"請輸入姓名:";
char name[20];
int j;
j=0;
cin>>name;
cout<<"你要查找的資料是:"<<endl;
cout<<"姓名 "<<"學號 " <<"性別 "<<"家庭住址 "<<"出生日期 "<<"宿捨號 "<<"宿捨號碼"<<endl;
while(p)
{
if (strcmp(p->name,name)==0)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"對不起,沒找到你要的信息!"<<endl<<endl ;
}
void findnum(student &s) //find by number
{
student p;
p=s->next;
cout<<"請輸入學號:";
long int number;
int j;
j=0;
cin>>number;
cout<<"你要查找的資料是:"<<endl;
cout<<"姓名 "<<"學號 "<<"性別 "<<"家庭住址 "<<"出生日期 "<<"宿捨號 "<<"宿捨電話"<<endl;
while(p)
{
if (p->number==number)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"對不起,沒找到你要的信息"<<endl<<endl ;
}
void modifay(student &s) //modifay
{
student q,p,l,m;
int j;
j=0;
q=s->next;
l=s;
m=s;
cout<<"請輸入要修改的學號:" ;
long int num;
cin>>num;
cout<<"姓名 "<<"學號 "<<"性別 "<<"家庭住址 "<<"入學時間 "<<"宿捨號 "<<"電話號碼"<<endl;
while(q)
{
if (q->number==num)
{
cout<<"你要修改的信息是:"<<endl;
cout<<q->name<<" "<<q->number<<" "<<q->sex<<" "<<q->add<<" "<<q->time<<" "<<q->snum<<" "<<q->tel<<" "<<endl;
j++;
p=(student)malloc(sizeof(stu));
cout<<"請輸入新的學生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"學號:";
cin>>p->number;
cout<<endl;
cout<<"年齡:";
cin>>p->age;
cout<<endl;
cout<<"性別:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"入學