📄 azimpoor.bak
字号:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
//--------------------------------------------------------------------------
class book{
private:
int ID;
char name[20];
char writer[20];
char publisher[20];
int year;
public:
void set(int,char[],char[],char[],int);
int get_ID();
char* get_name();
char* get_writer();
char* get_publisher();
int get_year();
void show();
};
//--------------------------------------------------------------------------
int book::get_ID()
{
return ID;
}
//--------------------------------------------------------------------------
char* book::get_name()
{
return name;
}
//--------------------------------------------------------------------------
char* book::get_writer()
{
return writer;
}
//--------------------------------------------------------------------------
char* book::get_publisher(){
return publisher;
}
//--------------------------------------------------------------------------
int book::get_year()
{
return year;
}
//--------------------------------------------------------------------------
void book::show()
{
cout<<"\n"<<ID<<" "<<name<<" "<<writer<<" "<<publisher<<" "<<year;
}
//--------------------------------------------------------------------------
void book::set(int id,char Name[],char Writer[],char Publisher[],int Year)
{
ID=id;
strcpy(name,Name);
strcpy(writer,Writer);
strcpy(publisher,Publisher);
year=Year;
}
//--------------------------------------------------------------------------
int size=0;
book book1[100];
//-------------------------------MAIN---------------------------------------
int main(){
char menu();
void input();
void report();
char ch;
do{
ch=menu();
switch(ch){
case '1':
input();
break;
case '2':
report();
break;
}
} while(ch!='3');
return 0;
}
//-------------------------------MENU----------------------------------------
char menu()
{
char ch;
clrscr();
cout<<"\n\n\n\t\t1.INPUT DATA";
cout<<"\n\n\n\t\t2.REPORT";
cout<<"\n\n\n\t\t3.EXIT";
cout<<"\n\n\n\t\t\t\t PLEAS CHOOSE A NUMBER:";
cin>>ch;
return ch;
}
//------------------------------INPUT----------------------------------------
void input()
{
void read(int);
clrscr();
char ch;
cout<<"\n\tPleas Enter book properties with 'Enter' or 'Q' for exit:";
ch=getch();
for(int i=0;i<3;i++)
{
clrscr();
if(ch=='q'||ch=='Q')
break;
else
read(i);
}
}
//------------------------------READ-----------------------------------------
void read(int index)
{
int id;
char name[20];
char writer[20];
char publisher[20];
int year;
clrscr();
cout<<"\n\nEnter Book ID:";
cin>>id;
cout<<"Enter Book Name:";
cin>>name;
cout<<"Enter Book Writer:";
cin>>writer;
cout<<"Enter Book Publisher:";
cin>>publisher;
cout<<"Enter Publish Year:";
cin>>year;
book1[index].set(id,name,writer,publisher,year);
size++;
return;
}
//-------------------------------REPORT--------------------------------------
void report()
{
char menu2();
char ch;
void report_by_name();
void report_by_writer();
void report_by_year();
void report_all();
do
{
ch=menu2();
switch(ch){
case '1':
report_by_name();
break;
case '2':
report_by_writer();
break;
case '3':
report_by_year();
break;
case '4':
report_all();
break;
}
} while(ch!='5');
return;
}
//---------------------------------MENU--------------------------------------
char menu2()
{
clrscr();
char ch;
cout<<"\n\n\t\t1.Report By Name.";
cout<<"\n\t\t2.Report By Writer.";
cout<<"\n\t\t3.Report By Year.";
cout<<"\n\t\t4.Report By All.";
cout<<"\n\t\t5.Exit.";
cout<<"\n\t\t\tChoose A Number:";
cin>>ch;
return ch;
}
//--------------------------------REPORT-BY-NAME-----------------------------
void report_by_name()
{
char name[20];
char str[20]={'0'};
clrscr();
cout<<"Enter Name:";
cin>>name;
cout<<"ID"<<" "<<"name"<<" "<<"writer"<<" "<<"publisher"<<" "<<"year";
cout<<"\n*****************************************\n" ;
for(int i=0;i<size;i++)
{
strcpy(str,book1[i].get_name());
if(!(strcmp(str,name)))
book1[i].show();
}
cout<<"\n\n*****************************************\n" ;
cout<<"\n\n\nPress Enter To Exit:";
getch();
return;
}
//--------------------------------REPORT-BY-WRITER---------------------------
void report_by_writer()
{
char writer[20];
char str[20]={'0'};
clrscr();
cout<<"Enter Writer Name:";
cin>>writer;
cout<<"ID"<<" "<<"name"<<" "<<"writer"<<" "<<"publisher"<<" "<<"year";
cout<<"\n*****************************************\n" ;
for(int i=0;i<size;i++)
{
strcpy(str,book1[i].get_writer());
if (!(strcmp(str,writer)))
book1[i].show();
}
cout<<"\n\n*****************************************\n" ;
cout<<"\n\n\nPress Enter To Exit:";
getch();
return;
}
//--------------------------------REPORT-BY-YEAR-----------------------------
void report_by_year()
{
int year;
clrscr();
cout<<"Enter Year:";
cin>>year;
cout<<"ID"<<" "<<"name"<<" "<<"writer"<<" "<<"publisher"<<" "<<"year";
cout<<"\n*****************************************\n" ;
for(int i=0;i<size;i++)
if(book1[i].get_year()==year)
book1[i].show();
cout<<"\n\n*****************************************\n" ;
cout<<"\n\n\nPress Enter To Exit:";
getch();
return;
}
//---------------------------------REPORT-ALL--------------------------------
void report_all()
{
clrscr();
cout<<"ID"<<" "<<"name"<<" "<<"writer"<<" "<<"publisher"<<" "<<"year";
cout<<"\n*****************************************\n" ;
for(int i=0;i<size;i++)
book1[i].show();
cout<<"\n\n*****************************************\n" ;
cout<<"\n\n\nPress Enter To Exit:";
getch();
return;
}
//----------------------------------END-------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -