📄 bookdisp.cpp
字号:
//*******************************
// 报表模块
//*******************************
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
#include<windows.h>
#include"book.h"
void showtime();
void showbook(book p[],int n ); //书库列表
void show_by_date(book p[],int n ); //按进书日期列表
void show_by_volumn(book p[],int n); //按库存量列表
void show_by_wholesale(book p[],int n); //按批发价列表
void show_by_retail(book p[],int n ); //按零售价列表
void show_by_price(book p[],int n); //按价值额列表
//假设书库中书的种类数不超过100种
void bookdisp()
{
char ch='0';
fstream file("book.dat",ios::in|ios::binary);
if(!file)
{
cout<<"\n\n打开文件失败!"<<endl;
system("pause");
exit(1);
}
book p[100];
int n=0; //n用于记录书库中书的实际种类数
int i=0,j=0;
file.read((char*)&p[i],sizeof(p[0]));
while(!file.eof())
{
i++;
file.read((char*)&p[i],sizeof(p[0]));
}
file.close();
if(i==0)
{
cout<<"\n\t\t\t书库为空!"<<endl;
system("pause");
return;
}
n=i; //n用于记录书库中书的实际种类数
while(true)
{
system("cls");
showtime();
cout<<"\n\t\t\t 报表模块"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<" 1: 书库列表 "<<endl;
cout<<" 2: 按进书日期列表 "<<endl;
cout<<" 3: 按库存量列表 "<<endl;
cout<<" 4: 按批发价列表 "<<endl;
cout<<" 5: 按零售价列表 "<<endl;
cout<<" 6: 按价值额列表 "<<endl;
cout<<" 7: 返回上一菜单 "<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t请输入选择:";
cin>>ch;
cin.ignore();
cout<<endl;
switch(ch)
{
case '1':
showbook(p,n); //书库列表
break;
case '2':
show_by_date(p,n); //按进书日期列表
break;
case '3':
show_by_volumn(p,n); //按库存量列表
break;
case '4':
show_by_wholesale(p,n); //按批发价列表
break;
case '5':
show_by_retail(p,n); //按零售价列表
break;
case '6':
show_by_price(p,n); //按价值额列表
break;
case '7':
return ;
default:
break;
}
}
}
//*******************************
// 书库列表
//*******************************
void showbook(book p[],int n)
{
for(int i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<"作 者:"<<setw(10)<<p[i].getauthor()<<endl;
}
system("pause");
}
//*******************************
// 按进书日期列表
//*******************************
void show_by_date(book p[],int n)
{
book temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(strcmp(p[i].getdateadd(),p[j].getdateadd())<0)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
for(i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<" "<<"进书日期: "<<setw(15)<<p[i].getdateadd()<<endl;
}
system("pause");
}
//*******************************
// 按库存量列表
//*******************************
void show_by_volumn(book p[],int n)
{
book temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(p[i].getvolumn()<p[j].getvolumn())
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
for(i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<" "<<"库存量: "<<setw(15)<<p[i].getvolumn()<<"本"<<endl;
}
system("pause");
}
//*******************************
// 按批发价列表
//*******************************
void show_by_wholesale(book p[],int n)
{
book temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(p[i].getwholesale()<p[j].getwholesale())
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
for(i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<" "<<"批发价: "<<setw(15)<<p[i].getwholesale()<<"元"<<endl;
}
system("pause");
}
//*******************************
// 按零售价列表
//*******************************
void show_by_retail(book p[],int n)
{
book temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(p[i].getretail()<p[j].getretail())
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
for(i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<" "<<"零售价: "<<setw(15)<<p[i].getretail()<<"元"<<endl;
}
system("pause");
}
//*******************************
// 按价值额列表
//*******************************
void show_by_price(book p[],int n)
{
book temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(p[i].getvolumn()*p[i].getretail()<p[j].getvolumn()*p[j].getretail())
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
for(i=0;i<n;i++)
{
cout.setf(ios::left);
cout<<i+1<<". "<<setw(30)<<p[i].getbookname()<<" "<<"价值额: "<<setw(15)<<p[i].getvolumn()*p[i].getretail()<<"元"<<endl;
}
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -