導航:首頁 > 源碼編譯 > vs2005圖書銷售系統源碼

vs2005圖書銷售系統源碼

發布時間:2023-09-02 09:36:40

⑴ 圖書館管理系統代碼

/*****************************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>//輸入/輸出文件流類
using namespace std;
const int Maxr=100;//最多的讀者
const int Maxb=100;//最多的圖書
const int Maxbor=5;//每位讀者最多借五本書
//讀者類,實現對讀者的信息的描述

class Reader
{
private:
int tag; //刪除標記 1:已刪 0:未刪
int no; //讀者編號
char name[10]; //讀者姓名
int borbook[Maxbor];//所借圖書
public:
Reader() {}
char *getname() {return name;} //獲取姓名
int gettag() {return tag;} //獲取刪除標記
int getno() {return no;} //獲取讀者編號
void setname(char na[]) //設置姓名
{
strcpy(name,na);

}
void delbook(){ tag=1; }//設置刪除標記 1:已刪 0:未刪
void addreader(int n,char *na)//增加讀者
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;i<Maxbor;i++)
borbook[i]=0;
}
void borrowbook(int bookid)//借書操作
{
for(int i=0;i<Maxbor;i++)
{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
int retbook(int bookid)//還書操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
void disp()//讀出讀者信息
{
cout << setw(5) << no <<setw(10) << name<<"借書編號:[";
for(int i=0;i<Maxbor;i++)
if(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<<endl;

}
};

//讀者類庫,實現建立讀者的個人資料
class RDatabase
{
private:
int top; //讀者記錄指針
Reader read[Maxr];//讀者記錄
public:
RDatabase() //構造函數,將reader.txt讀到read[]中
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);//打開一個輸入文件
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
file.close(); //關閉 reader.txt
}
void clear()//刪除所有讀者信息
{
top=-1;
}
int addreader(int n,char *na)//添加讀者時先查找是否存在
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
Reader *query(int readerid)//按編號查找
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
void disp() //輸出所有讀者信息
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void readerdata();//讀者庫維護
~RDatabase() //析構函數,將read[]寫到reader.txt文件中
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t讀 者 維 護\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 刪 除\n\n\t\t 4 查 找\n\n\t\t 5 顯 示\n\n\t\t 6 全 刪\n\n\t\t 0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "輸入讀者編號:";
cin >> readerid;
cout << "輸入讀者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "輸入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 該讀者不存在 "<<endl;
break;
}
cout << "輸入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 輸入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 該讀者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "讀入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"該讀者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"輸入錯誤,請從新輸入:";break;
}
}
}

//圖書類,實現對圖書的描述,圖書的編號,書名,借出,還入等
class Book
{
private:
int tag;//刪除標記 1:已刪 0:未刪
int no;//圖書編號
char name[20];//書名
int onshelf;//是否再架 1:再架 2:已借
public:
Book(){}
char *getname() { return name; }//獲取姓名
int getno(){ return no; }//獲取圖書編號
int gettag(){ return tag; }//獲取刪除標記
void setname(char na[])//設置書名
{
strcpy(name,na);
}
void delbook(){ tag=1;}//刪除圖書
void addbook(int n,char *na)//增加圖書
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
int borrowbook()//借書操作
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void retbook()//還書操作
{
onshelf=1;
}
void disp()//輸出圖書
{
cout << setw(6) << no << setw(18) << name << setw(10)
<<(onshelf==1? "在架":"已借") <<endl;
}
};

//圖書庫類,實現對圖書的維護,查找,刪除等
class BDatabase
{
private:
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)//增加圖書
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
Book *query(int bookid)//查找圖書
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
void bookdata();//圖書庫維護
void disp()
{
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()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t圖 書 維 護 "<<endl<<endl;
cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 刪 除\n\t\t4 查 找\n\t\t5 顯 示\n\t\t6 全 刪\n\t\t0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "輸入圖書編號:"<<endl;
cin >> bookid;
cout << "輸入圖書書名:"<<endl;
cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "輸入圖書編號:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 該圖書不存在 "<<endl;
break;
}
cout << "輸入新的書名:"<<endl;
cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 讀入圖書編號:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 該圖書不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 讀入圖書編號:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 該圖書不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"輸入錯誤,請從新輸入:";
}
}
}

//main() 函數的實現,程序的主界面的引導

int main(void)
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <<endl<<endl<<"\t\t\t 圖 書 管 理 系 統\n\n\n";

cout <<"\t\t\t1 借 書\n\n\t\t\t2 還 書 \n\n\t\t\t3 圖 書 維 護\n\n\t\t\t4 讀 者 維 護\n\n\t\t\t0 離 開"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout <<" 借書 讀者編號:";
cin >>readerid;
cout <<" 圖書編號: ";
cin >>bookid;
r=ReaderDB.query(readerid);//按編號查找
if (NULL==r)
{
cout <<" 不存在該讀者,不能借書"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在該圖書,不能借書"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 該圖書已借出,不能借書"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"還書\n 讀者編號:";
cin >>readerid;
cout << " 圖書編號:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在該讀者,不能還書" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在該圖書,不能還書" <<endl;
break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"輸入錯誤,請從新輸入:";

}
}
return 0;
}
希望能解決您的問題。

⑵ 急求用C語言編寫的圖書管理系統源代碼

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0

struct student /*定義學生類型,用於存放借出的書籍*/
{
int carnum;
char lendbook[10];
}student[1000];

struct employ /*定義職工類型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];

struct book /*定義書的類型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用於借書和還書模塊判斷一本書是否借出的條件*/
}book[1000];

struct car /*借書卡的數據類型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];

huanbook() /*還書函數*/
{
FILE *fp,*fp2; /*定義兩個文件指針,fp2用於修改數據時設立臨時文件用,防止數據遭破壞*/
int i,n;
int carnum;
char lendbook[10];
printf("請你輸入你的卡號\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r"); /*讀取卡號記錄*/
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) /*for循環判斷卡號是否存在*/
{
if(car[i].carnum==carnum) /*卡號存在,進入下一循環*/
{
n=i;
fclose(fp);
printf("請輸入你要還的書的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判斷是否借閱了輸入的書*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借閱了該書,進入下一循環,否則出錯顯示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*刪除還掉的書的借書記錄*/
}
fwrite(&student[i],sizeof(struct student),1,fp2); /*寫入原來沒還的書的記錄*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(&student[i],sizeof(struct student),1,fp); /*將借書記錄信息寫回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清臨時文件的記錄*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) /*將書的記錄寫入臨時文件,防止因為修改信息破壞以前的記錄*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(&book[i],sizeof(struct book),1,fp2); /*將還的書的原來狀態設為無人借閱的*/
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp); /*將臨時文件寫回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清臨時文件*/
fclose(fp2);
printf("還書完畢,按任意鍵返回\n");
getch();
return 1;
}
}
printf("你沒有借這樣的書,任意鍵返回\n"); /*出錯提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系統沒這樣的卡,和管理員聯系,按任意鍵返回\n"); /*出錯提示*/
fclose(fp);
getch();
}

findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("請輸入你要查找的書名\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("這本書的詳細資料是:%d %s %s 此書現在無人借閱\n按任意鍵返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("這本書已經有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("沒有你要查詢的書籍\n");
fclose(fp);
return FALSE;
}

findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("請輸入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("這本書的詳細資料是:%d %s %s 此書現在無人借閱\n按任意鍵返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("這本書已經有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("沒有你要查詢的書籍\n");
fclose(fp);
return FALSE;
}

lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡號:%d 借出的書籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本書借出\n",n);
printf("按任意鍵\n");
getch();
return n;
}

chabook()
{
char ch5;
do
{
printf("---------------歡迎進入圖書查詢系統!--------------\n");
printf(" 1:<按書名查找>\n");
printf(" 2:<按作者查找>\n");
printf(" 0:<返回>\n");
printf("請輸入0--2,其他輸入非法!\n");
scanf("%s",&ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("無此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}

lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("請你輸入你的卡號\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("請輸入你要借閱的書的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("對不起,此書有人借出,請借其他書\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(&student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(&book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借書完畢,按任意鍵返回\n");
getch();
return;
}
}
printf("不存在這樣的書,任意鍵返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡號不存在,請申請新卡,按任意鍵返回\n");
fclose(fp);
getch();
}

carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d張卡<卡號:%d 姓名:%s 班級:%d>\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本書\n",n);
printf("按任意鍵\n");
getch();
}

delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("請輸入你要刪除的卡號\n");
printf("如果你輸入的卡號存在,系統自動刪除該信息!如果不存在,系統不做任何改動\n");
scanf("%d",&carnum);
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(&car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要刪除該卡?刪除後該書籍的所有信息將無法恢復《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(&car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意鍵返回\n");
getch();
return;
}
else
{
printf("按任意鍵返回\n");
getch();
return;
}
}

addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("請你輸入卡號\n");
scanf("%d",&car[i].carnum);
printf("請你輸入學生姓名\n");
scanf("%s",car[i].studentname);
printf("請你輸入班級\n");
scanf("%d",&car[i].studentclass);
fwrite(&car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("輸入完畢,任意鍵返回\n");
getch();
}

⑶ 急!vs2005(C#)用戶登錄連接資料庫的源代碼

這是一個實例 有不懂的問我
{
string QuerySql = "select * from tTea where tTea_name ='" + username.Text + "' and tTea_pwd='" + pwd.Text + "'";
bool flag = DB.Query(QuerySql);
if (flag)
{
string ip = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();

string Editsql = "insert into tAdminLog(tAdmin_name,tAdminLog_time,tAdminLog_ip,tAdminLog_zhuangtai) values('" + username.Text + "','" + DateTime.Now + "','" + ip + "','成功')";
bool flag1 = DB.Edit(Editsql);
Session["username"] = username.Text.Trim();
SqlConnection con = DB.CreatConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select * from tTea where tTea_name ='" + username.Text + "'", con);
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sdr.Fill(ds);
Session["xueyuan"] = ds.Tables[0].Rows[0]["tTea_xueyuan"].ToString();
bool fuzheren = (bool)ds.Tables[0].Rows[0]["fuzeren"];
if (fuzheren)
{
Response.Redirect("shangji/Default.aspx");
}
else
{
Response.Redirect("teacher/Default.aspx");
}

}
else
{
string ip = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();

string Editsql = "insert into tAdminLog(tAdmin_name,tAdminLog_time,tAdminLog_ip,tAdminLog_zhuangtai) values('" + username.Text + "','" + DateTime.Now + "','" + ip + "','失敗')";
bool flag1 = DB.Edit(Editsql);
Response.Write("<script>alert('用戶名或密碼錯誤?');location.href('Default.aspx')</script>");
}
}

閱讀全文

與vs2005圖書銷售系統源碼相關的資料

熱點內容
js如何運行時編譯 瀏覽:915
引力app在哪裡下載 瀏覽:607
編寫app如何得到錢 瀏覽:800
吉利汽車軟體放哪個文件夾安裝 瀏覽:223
多文件編譯c 瀏覽:541
頭頂加密後為什麼反而更稀疏 瀏覽:793
離心機壓縮機揚程高 瀏覽:658
xshell連接linux命令 瀏覽:5
把多個文件夾的內容合並在一起 瀏覽:483
基於單片機的澆花系統設計ppt 瀏覽:685
卷積碼編解碼及糾錯性能驗證實驗 瀏覽:354
請在刪除驅動器之前暫停加密什麼意思 瀏覽:787
光催化pdf 瀏覽:98
java字元串包含某字元 瀏覽:528
ssm身份認證源碼 瀏覽:466
預排序遍歷樹演算法 瀏覽:671
加密裝置如何打開ping功能 瀏覽:479
python下載372 瀏覽:902
u盤子文件夾隱藏 瀏覽:296
本地誤刪svn文件夾 瀏覽:687