當前位置:編程學習大全網 - 源碼下載 - 圖書管理系統 c++源代碼 急急急

圖書管理系統 c++源代碼 急急急

void AddRecord(CList &TelList)

{ system("cls");

CNode *pNode;

CTelRecord *pTel;

char szName[20],szNumber[20], kind[20], writer[20];

cout<<"\n\t\t ◇請輸入書名(輸入0結束) :";

cin.getline (szName,20);

while(strcmp(szName,"0"))

{

cout<<"\t\t ◇請輸入書的編號 :";

cin.getline(szNumber,20);

cout<<"\t\t ◇請輸入書的種類(社科,自科,文學,工具書,其他):";

cin.getline(kind,20);

cout<<"\t\t ◇請輸入作者的姓名 :";

cin.getline(writer,20);

pTel=new CTelRecord;

pTel->SetRecord(szName,szNumber,kind,writer);

pNode=new CNode;

pNode->InputData(pTel);

TelList.AddNode(pNode);

system("cls");

cout<<"\n\t\t ☆請輸入書名(輸入0結束):";

cin.getline(szName,20);

}

cout<<endl<<endl;

}

void DisplayRecord(CList &TelList)

{ system("cls");

cout<<endl<<setw(15)<<" ☆ 書名 ☆ "<<setw(15)<<"\t☆ 書的編號 ☆"<<setw(15)<<"\t ☆ 書的種類 ☆"<<setw(15)<<"\t ☆ 作者☆ \n"<<endl;

TelList.ShowList();

cout<<endl<<endl;

}

void LookUpRecord(CList &TelList)

{ system("cls");

CNode *pLook;

char szName[20];

cout<<"\n\t\t ☆請輸入您想要查找的書名(輸入0結束)";

cin.getline(szName,20);

while(strcmp(szName,"0"))

{

CTelRecord tele(szName,"0","0","0");

pLook=TelList.LookUp(tele);

if(pLook)

{

cout<<endl<<"\t\t ※在裏面找到的紀錄 "<<szName <<",內容是:\n"<<endl;

cout<<endl<<setw(15)<<" ☆ 書名 ☆ "<<setw(15)<<"\t☆ 書的編號 ☆"<<setw(15)<<"\t ☆ 書的種類 ☆"<<setw(15)<<"\t ☆ 作者☆ \n"<<endl;

pLook->ShowNode();

}

else

cout<<"\n\t\t !!!在裏面找不到 "<<szName<<" ."<<endl;

system("pause");

system("cls");

cout<<"\n\t\t ☆請輸入您想要查找的書名(輸入0結束)";

cin.getline(szName,20);

}

cout<<endl<<endl;

}

void DeleteRecord(CList &TelList)

{ system("cls");

CNode *pLook;

char szName[20];

cout<<"\n\t\t△請輸入您想要刪除的書名(輸入0結束)";

cin.getline(szName,20);

while (strcmp(szName,"0"))

{

CTelRecord tele (szName,"0","0","0");

pLook=TelList.LookUp(tele);

if(pLook)

{

cout<<"\n\t\t☆在裏面找到的紀錄 "<<szName <<",內容是:\n"<<endl;

cout<<endl<<setw(15)<<" ☆ 書名 ☆ "<<setw(15)<<"\t☆ 書的編號 ☆"<<setw(15)<<"\t ☆ 書的種類 ☆"<<setw(15)<<"\t ☆ 作者☆ \n"<<endl;

pLook->ShowNode();

TelList.DeleteNode(pLook);

cout<<"\n\t\t◎"<<szName<<"的資料已刪除"<<endl;

}

else

cout<<"\n\t\t▲對不起, 在裏面找不到 "<<szName<<" ."<<endl;

system("pause");

system("cls");

cout<<"\n\t\t△請輸入您想要刪除的書名(輸入0結束)";

cin.getline(szName ,20);

}

cout<<endl<<endl;

}

void StoreFile(CList &TelList)

{

ofstream outfile("BOOK.dat",ios::binary);

if(!outfile)

{

cout<<"\t\t\t !!! 數據文件打開錯誤,無法儲存數據";

return;

}

CNode *pnode;

CTelRecord *pTel;

string strName,strNumber;

pnode=TelList.GetListHead();

while(pnode)

{

pTel=(CTelRecord *)pnode->GetData();

outfile.write((char *)pTel,sizeof(CTelRecord));

pnode=TelList.GetListNextNode(pnode); }

outfile.close();

}

void Operate(string &strChoice,CList &TelList)

{ void TongJi(CList &TelList);

if(strChoice=="1")

AddRecord(TelList);

else if(strChoice=="2")

DisplayRecord(TelList);

else if(strChoice=="3")

LookUpRecord(TelList);

else if(strChoice=="4")

DeleteRecord(TelList);

else if(strChoice=="5")

TongJi(TelList);

else if(strChoice=="0")

StoreFile(TelList);

else

cout<<"\n\t\t\t !!!輸入錯誤,請重新輸入您的選擇."<<endl;

}

void LoadFile(CList &TelList)

{

ifstream infile("BOOK.dat",ios::binary);

if(!infile)

{

cout<<"\n\t\t !!!對不起,沒有找到數據文件,無法導入數據.";

return;

}

CNode*pNode;

CTelRecord*pTel;

while(!infile.eof())

{

pTel=new CTelRecord;

infile.read((char *)pTel,sizeof(CTelRecord));

pNode=new CNode;

pNode->InputData(pTel);

TelList.AddNode(pNode);

}

TelList.DeleteNode(pNode);

infile.close();

}

void TongJi(CList &TelList)

{ system("cls");

int a,b,i,j,k, d,e,f,g,m,n;

CTelRecord sk("0","0","社科","0");

CTelRecord zk("0","0","自科","0");

CTelRecord wx("0","0","文學","0");

CTelRecord gj("0","0","工具書","0");

CTelRecord qt("0","0","其他","0");

a=TelList.tongji(sk);

b=TelList.tongji(zk);

i=TelList.tongji(wx);

j=TelList.tongji(gj);

k=TelList.tongji(qt);

cout<<'\t'<<"↑"<<endl;

for(d=20;d>0;d--)cout<<d+50<<'\t'<<"│"<<endl;

for(d=50,e=50,f=50,g=50,m=50,n=50;e>0;d--,e--,f--,g--,m--,n--)

{ cout<<d<<'\t'<<"│";

if(e>a)cout<<" ";else cout<<"■";

cout<<'\t';

if(f>b)cout<<" ";else cout<<"■";

cout<<'\t';

if(g>i)cout<<" ";else cout<<"■";

cout<<'\t';

if(m>j)cout<<" ";else cout<<"■";

cout<<'\t';

if(n>k)cout<<" ";else cout<<"■";

cout<<endl;

}

cout<<" ————————————————————————→"<<endl;

cout<<'\t'<<a<<" "<<'\t'<<b<<" "<<'\t'<<i<<" "<<'\t'<<j<<" "<<'\t'<<k<<" "<<endl;

cout<<" "<<"社科"<<" "<<"自科"<<" "<<"文學"<<" "<<"工具書"<<" "<<"其他"<<endl;

}

int main()

{

CList TelList;

system("cls");

cout<<endl<<"\t\t\t☆☆☆ 歡迎進入圖書管理系統☆☆☆\n";

LoadFile(TelList);

string strChoice;

do

{

cout<<endl<<"\n\t\t\t ※ 1. 添加圖書紀錄\n"<<endl;

cout<<"\t\t\t ※ 2. 顯示圖書信息 \n"<<endl;

cout<<"\t\t\t ※ 3. 根據書名查找圖書信息\n"<<endl;

cout<<"\t\t\t ※ 4. 根據書名刪除圖書信息\n"<<endl;

cout<<"\t\t\t ※ 5. 打印圖書信息圖表\n"<<endl;

cout<<"\t\t\t ※ 0. 退出系統"<<endl<<endl;

cout<<"\t\t\t ★ 請輸入您的選擇 :";

cin>>strChoice;

cin.ignore();

Operate(strChoice,TelList);

} while (strChoice!="0");

cout<<" \n\n\t\t\t※※※歡迎再次使用圖書管理系統※※※\n\n";

return 0;

}

上面是各個部分的代碼,妳自己整理壹下

  • 上一篇:我想在ecshop page_header.lbi裏面添加廣告!!但是不能加模版文件!!
  • 下一篇:學習編程 ,從哪學起,我想自己學學
  • copyright 2024編程學習大全網