这是写了一半的程序,谁知道错在哪儿?求修改
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ctype.h"
#include "conio.h"
#include <fstream.h>
#include"iostream.h"
#include"string.h"
#include<iomanip.h>
#include "windows.h"
struct BOOK
{
char booknum[10]; //图书序号
char bookname[40]; //图书名称
char bookcreat[10]; //图书作者
int turefalse; //是否借出
}book[100];
void gotoxy(int x,int y);
void setcolor(unsigned short ForeColor,unsigned short BackColor);
int zjbook(struct BOOK b[]);//增加图书函数
//int scbook(struct BOOK b[],int n);//删除图书函数
//int xgbook(struct BOOK b[],int n,char *s);//修改图书函数
//void showbook(struct BOOK b);//显示图书信息
void tjbook(struct BOOK b[],int n);//图书统计
//void cxbook();//按书名查询图书函数
//int jbook();//借书函数
//int hbook();//还书函数
//void filesave(struct BOOK b[],int n);
//int FindRecord(struct BOOK b[],int n,char *s);
void main()
{
int i;
//char s[128];
int num;//保存记录数
system("cls");//清屏
while(1)
{system("cls");
cout<<"************欢迎进入中文图书馆管理程序!***********";
cout<<"\n请你选择操作类型:"<<endl;
cout<<"* 1:<增加图书>"<<endl;
cout<<"* 2:<删除图书>"<<endl;
cout<<"* 3:<修改图书>"<<endl;
cout<<"* 4:<所有图书统计>"<<endl;
cout<<"* 5:<按书名查询图书>"<<endl;
cout<<"* 6:<借书>"<<endl;
cout<<"* 7:<还书>"<<endl;
cout<<"* 0:<退出>"<<endl;
do{
cout<<"请输入0——7"<<endl;
cout<<"**************************************************"<<endl;
cin>>i;
}while(i<0||i>7);
switch(i)
{
case 0: exit(0);
case 1: num=zjbook(book);break;
case 2: break;
case 3: break;
case 4: tjbook(book,num);break;
case 5: break;
case 6: break;
case 7: break;
}
}
system("cls");
cout<<"谢谢使用!"<<endl;
}
//增加图书
int zjbook(struct BOOK b[])
{int i,n;
system("cls");
cout<<"---------------------图书基本信息录入--------------------"<<endl;
cout<<" 请输入你想要增加的图书的数目:"<<endl;
cin>>n;
ofstream outfile("book.dat",ios::app);
if(!outfile)
{cerr<<"open error!"<<endl;
exit(1);
}
cout<<" 请输入图书信息:"<<endl;
cout<<" 图书序号 图书名称 图书作者 是否借出"<<endl;
cout<<"———————————————————————————————————"<<endl;
for(i=0;i<n;i++)
{
cin>>b[i].booknum>>b[i].bookname>>b[i].bookcreat>>b[i].turefalse;
outfile<<setw(-12)<<b[i].booknum<<setw(20)<<b[i].bookname<<setw(12)<<b[i].bookcreat<<setw(5)<<b[i].turefalse<<endl;
cout<<"———————————————————————————————————"<<endl;
outfile<<"———————————————————————————————————"<<endl;
}
outfile.close();
cout<<"文件已保存!"<<endl;
return n;
}
void tjbook(struct BOOK b[],int n)
{int i;
char l;
system("cls");
cout<<"\n\n------------------------------图书统计------------------------------------\n"<<endl;
cout<<" 图书序号 图书名称 图书作者 是否借出"<<endl;
cout<<"———————————————————————————————————"<<endl;
ofstream outfile("book.dat",ios::out);
if(!outfile)
{cerr<<"open error!"<<endl;
exit(1);}
for(i=0;i<n;i++)
{outfile<<setw(-12)<<b[i].booknum<<setw(20)<<b[i].bookname<<setw(12)<<b[i].bookcreat<<setw(5)<<b[i].turefalse<<endl;}
for(i=0;i<n;i++)
{cout<<setiosflags(ios::left);
cout<<setw(-12)<<b[i].booknum<<setw(20)<<b[i].bookname<<setw(12)<<b[i].bookcreat<<setw(5)<<b[i].turefalse<<endl;
cout<<"———————————————————————————————————"<<endl;
}
outfile.close();
cout<<endl<<endl<<" 按任意键退出:";
l=getche();main();
}
int scbook(struct BOOK b[],int n)
{char s[20]; //要删除的图书的名称
int i,j;
system("cls");
cout<<" ============ 图书信息删除 ============ "<<endl;
cout<<"请输入图书名称:";//提示信息
cin>>s;//输入姓名
cout<<endl;
ifstream infile("book.dat",ios::in);
if(! infile)
{cerr<<"open error!"<<endl;
exit(1);
}
i=FindRecord(b,n,s);//调用FindRecord函数
if(i>n-1) //如果i>n-1超过了数组的长度
cout<<"没有找到要删除的图书";//显示没找到要删除的记录
else
{
showbook(b[i]); //调用输出函数显示该条记录信息
for(j=i+1;j<n;j++) //删除该记录,实际后续记录前移
{
b[j]=b[j-1];
}
n--; //记录数减1
cout<<"\n该图书已删除!"<<endl;
}
infile.close();
ofstream outfile("book.dat",ios::out);
if(!outfile)
{cerr<<"open error!"<<endl;
exit(1);}
for(i=0;i<n-1;i++)
{outfile<<setw(-12)<<b[i].booknum<<setw(20)<<b[i].bookname<<setw(12)<<b[i].bookcreat<<setw(5)<<b[i].turefalse<<endl;}
outfile.close();
return n;
}
int FindRecord(struct BOOK b[],int n,char *s)
{
int i;
ifstream infile("book.dat",ios::in);
if(! infile)
{cerr<<"open error!"<<endl;
exit(1);}
for(i=0;i<n;i++)
{infile>>b[i].booknum>>b[i].bookname>>b[i].bookcreat>>b[i].turefalse;}
for(i=0;i<n;i++)//从第一条记录开始,直到最后一条
{
if(strcmp(s,b[i].bookname)==0) //记录中的姓名和待比较的姓名是否相等
return i; break;//相等,则返回该记录的下标号,程序提前结结束
}
return i; //返回i值
infile.close ();
}
void showbook(struct BOOK bb)
{
cout<<"———————————————————————————————————"<<endl;
cout<<" 图书序号 图书名称 图书作者 是否借出"<<endl;
ofstream outfile("book.dat",ios::out);
if(!outfile)
{cerr<<"open error!"<<endl;
exit(1);}
outfile<<setw(-12)<<bb.booknum <<setw(20)<<bb.bookname<<setw(12)<<bb.bookcreat<<setw(5)<<bb.turefalse<<endl;
cout<<setw(-12)<<bb.booknum <<setw(20)<<bb.bookname<<setw(12)<<bb.bookcreat<<setw(5)<<bb.turefalse<<endl;
outfile.close ();
cout<<"———————————————————————————————————"<<endl;
}
int xgbook(struct BOOK b,int n,char *s)
{int i;
char s[40];
struct BOOK B;
cout<<"请输入你要修改的图书的名称:"<<endl;
cin>>s;
ofstream outfile("book.dat",ios::in);
if(!outfile)
{cerr<<"open error!"<<endl;
exit(1);}
for(outfile<<)
i=FindRecord(*b[0],n,s);
if(i>n-1) //如果i>n-1超过了数组的长度
cout<<"没有找到要修改的图书";//显示没找到要删除的记录
else
{
showbook(b[i]);
cout<<"请输入你要修改的内容:"<<endl;
cin>>B.booknum>>B.bookname>>B.bookcreat>>B.turefalse;
b[i].booknum=B.booknum ;b[i].bookname=B.bookname ;b[i].bookcreat=B.bookcreat ;b[i].truefalse=B.turefalse ;
showbook[i];
}
}
void setcolor(unsigned short ForeColor,unsigned short BackColor)
// 0--黑 1--暗蓝 2--暗绿 3--暗青 4--暗红 5--暗紫 6--蟹黄 7--暗白
// 8--灰 9--亮蓝 10-亮绿 11-亮青 12-亮红 13-亮紫 14-黄 15-亮白
{ HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,(ForeColor % 16)|(BackColor % 16 * 16));
};
void gotoxy(int x,int y) // 列x: 0~79 行y: 0~24
{ HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen={x,y};
SetConsoleCursorPosition(hConsole,coordScreen);
return;
}
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。