#include<iostream>
#include<fstream>
#include<string>
#include <stdlib.h>
#include<vector>
using namespace std;
class sub
{
public:
char id[20];
char name[20];
char sex[10];
char addr[20];
char tel[20];
char magzid[20];
int numbook;
char deadline[20];
sub(){}
sub(char *name,char *id,char *sex,char *addr,char*tel,char *magzid,int numbook){}
void display(){ cout<<id<<"\t"<<name<<"\t"<<sex<<"\t"<<addr<<"\t"<<tel<<"\t"<<endl;}
int insert();
void check();
void total();
void alter();
void del();
int look();
void check();
};
sub user;
int main()
{
int ch;
char ch1;
cout<<"********************************************************************************"<<endl;
cout<<" 欢迎使用杂志订阅管理软件 "<<endl;
cout<<"********************************************************************************"<<endl;
cout<<" 按回车键进入主菜单! "<<endl;
getchar();
system("cls"); //清屏
do
{
cout<<"********************************************************************************"<<endl;
cout<<" 欢迎使用杂志订阅管理软件 "<<endl;
cout<<"********************************************************************************"<<endl;
cout<<" 1键增加新订户 "<<endl;
cout<<" 2键删除到期用户 "<<endl;
cout<<" 3键统计订户数 "<<endl;
cout<<" 4键修改订户信息 "<<endl;
cout<<" 5键查看所有订户信息 "<<endl;
cout<<" 6查询功能 "<<endl;
cout<<" 0键退出程序 "<<endl;
cout<<(" 请选择您需要的功能: ");
cin>>ch;
getchar();
switch(ch)
{
case 1:user.insert();break;
case 2:user.del();break;
case 3:user.total();break;
case 4:user.alter();break;
case 5:user.look();break;
case 6:user.check();break;
bb: case 0:
system("cls");
cout<<"********************************************************************************"<<endl;
cout<<endl;
cout<<" 谢谢您的使用! "<<endl;
cout<<" 请按任意键退出! "<<endl;
cout<<endl;
cout<<"********************************************************************************"<<endl;
exit(0);
default:cout<<("输入有误,请重新输入!\n");break;
}
cout<<("是否继续其他操作(Y/N)?");
cin>>ch1;
if (ch1=='n'||ch1=='N')
{
goto bb;
}
system("cls");
}while(ch1=='y'||ch1=='Y');
return 0;
}
/*---------------------------------------------------------------增订新订户------------------------------------------------*/
int sub::insert()
{ char sr;//输入
ofstream outfile("C:\\C++ks.dat");
char id[20],name[20],sex[20],addr[20],tel[20],magzid[20]; int numbook;
cout<<"-----------请输入订户信息-----------"<<endl<<endl;
do{
cout<<"订户编号: "; cin>>id;
cout<<"订户姓名: "; cin>>name;
cout<<"性别: "; cin>>sex;
cout<<"地址: "; cin>>addr;
cout<<"电话号码: "; cin>>tel;
cout<<"订阅杂志编号:"; cin>>magzid;
cout<<"订阅数: "; cin>>numbook;
cout<<"订阅期限: ";cin>>deadline;
sub s1(id,name,sex,addr,tel,magzid,numbook);
outfile<<id<<" "<<name<<" "<<sex<<" "<<addr<<" "<<tel<<" "<<magzid<<" "<<numbook<<" "<<deadline<<endl;
//out.write((char*)&s1,sizeof(s1));
cout<<"Enter another sub(y/n)?"<<endl; cin>>sr;
}while(sr=='y');
outfile.close();
return(sr);
}
/*-----------------------------------------------------------查看所有订户------------------------------------------------*/
int sub::look()
{
ifstream infile("C:\\C++kS.dat",ios::in|ios::binary);
//char id[20], name[20],sex[20],addr[20],tel[20],magzid[20];
//int numbook
//cout<<"订户编号\t"<<"订户姓名\t"<<"性别\t"<<"地址\t"<<"电话号码\t"<<"杂志订阅编号\t"<<"订阅数\t"<<endl<<endl;
infile>>id;
while(!infile.eof())
{
infile>>name>>sex>>addr>>tel>>magzid>>numbook;
//cout<<id<<"\t"<<name<<"\t"<<sex<<"\t"<<addr<<"\t"<<tel<<"\t"<<magzid<<"\t"<<numbook<<endl;
cout<<"订户编号:"<<id<<endl; //订户编号 订户姓名 性别 地址 电话号码 杂志订阅编号 订阅数
cout<<"订户姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"地址:"<<addr<<endl;
cout<<"电话号码:"<<tel<<endl;
cout<<"杂志订阅编号:"<<magzid<<endl;
cout<<"订阅数:"<<numbook<<endl<<endl;
infile>>id;
}
infile.close();
return 0;
}
/*---------------------------------------------查询功能------------------------------------------------*/
/* void sub::check ()
{
int a;
system("cls");
cout<<"****************************************************"<<endl;
cout<<" 1键-按订户编号查找 "<<endl;
cout<<" 2键-按订户姓名查找 "<<endl;
cout<<(" 请选择您需要的功能: ");
cin>>a;
getchar();
switch(a){
case 1:{
cout<<"输入客户姓名"<<endl;
cin>>name;
ifstream open("C:\\C++kS.dat",ios::in|ios::binary);
if(name==user.name)
{
cout<<"订户编号:"<<endl;
cout<<"订户姓名:"<<endl;
cout<<"性别:"<<endl;
cout<<"地址:"<<endl;
cout<<"电话号码:"<<endl;
cout<<"杂志订阅编号:"<<endl;
cout<<"订阅数:"<<endl<<endl;
}
else
{
cout<<"此订户不存在!"<<endl;
}
}
case 2:user.check_subbyname();break;
}
}*/
void sub::check()
{
int i,n,w=0,num[M],a[M];char ch;
string searchname,id[M],name[M],sex[M],addr[M],tel[M],magzid[M],numbook[M],deadline[M];
cout<<"a.按订户编号查找 b.按订户姓名查找"<<endl;
ifstream infile("C:\\C++kS.dat",ios::in);a
(!infile)
{
cout<<" open error"<<endl;
exit(1);
}
for(i=0;i<N;i++)
{
infile>>id[i];a[i]=id[i];
infile>>name[i];b[i][0]=name[i];
infile>>sex[i];b[i][1]=sex[i];
infile>>addr[i];b[i][2]=addr[i];
infile>>tel[i];b[i][3]=tel[i];
infile>>magzid[i];b[i][4]=magzid[i];
inflie>>numbook[i];b[i][5]=numbook[i];
inflie>>deadline[i];b[i][6]=deadline[i];
}
cout<<"请输入a或者b!"<<endl;
cin>>ch;
if(ch=='a')
{
cout<<"请输入订户编号!"<<endl;
cin>>n;
for(i=0;i<N;i++)
if(a[i]==n)
{
w=1;
cout<<" 订户编号 订户姓名 性别 地址 电话号码 杂志订阅编号 订阅数"<<endl;
cout<<" ";
cout<<setw(9)<<a[i];
cout<<setw(9)<<b[i][0];
cout<<setw(9)<<b[i][1];
cout<<setw(9)<<b[i][2];
cout<<setw(9)<<b[i][3];
cout<<setw(9)<<b[i][4];
cout<<setw(9)<<b[i][5];
cout<<setw(9)<<b[i][6]<<endl; }
if(w==0)
cout<<"无此人信息!"<<endl;
}
else if(ch=='b')
{
cout<<"请输入订户姓名!"<<endl;
cin>>searchname;
for(i=0;i<N;i++)
if(name[i]==searchname)
{
w=1;
cout<<" 订户编号 订户姓名 性别 地址 电话号码 杂志订阅编号 订阅数 "<<endl;
cout<<" ";
cout<<setw(9)<<a[i];
cout<<setw(9)<<b[i][0];
cout<<setw(9)<<b[i][1];
cout<<setw(9)<<b[i][2];
cout<<setw(9)<<b[i][3];
cout<<setw(9)<<b[i][4];
cout<<setw(9)<<b[i][5];
cout<<setw(9)<<b[i][6]<<endl; }
if(w==0)
cout<<"无此人信息!"<<endl;
}
else cout<<"没有此选项!"<<endl;
}
/*------