|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ͼ<><CDBC><EFBFBD>洢<EFBFBD>ṹ
|
|
|
|
|
struct book{
|
|
|
|
|
int id;//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char name[20];//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char author[20];//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
float price;//ͼ<><CDBC><EFBFBD>۸<EFBFBD>
|
|
|
|
|
struct book *next; // ָ<><D6B8><EFBFBD><EFBFBD>һͼ<D2BB><CDBC>
|
|
|
|
|
}*books;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
|
// <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> //
|
|
|
|
|
|
|
|
|
|
// ϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
void init();
|
|
|
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD>˵<EFBFBD>
|
|
|
|
|
void display_menu();
|
|
|
|
|
// ѡ<><D1A1><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĺ<EFBFBD><C4B9>ܺ<EFBFBD><DCBA><EFBFBD>
|
|
|
|
|
void make_choice();
|
|
|
|
|
// ȷ<>ϲ<EFBFBD><CFB2><EFBFBD>
|
|
|
|
|
void confirm();
|
|
|
|
|
// <20>˳<EFBFBD>ϵͳ,<2C>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD>
|
|
|
|
|
void quit();
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
|
// <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ģ<EFBFBD><C4A3> //
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5>ڴ<EFBFBD>
|
|
|
|
|
void read_data();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD>
|
|
|
|
|
void save_data();
|
|
|
|
|
// <20><>ӡͼ<D3A1><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void print_data();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
book *find(int id);
|
|
|
|
|
// <20><>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void query_data();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void add_data();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void update_data();
|
|
|
|
|
// ɾ<><C9BE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void delete_data();
|
|
|
|
|
// <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void sort_data();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void make_chart();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
display_menu();
|
|
|
|
|
make_choice();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> //
|
|
|
|
|
// ϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|
|
|
|
void init()
|
|
|
|
|
{
|
|
|
|
|
read_data();
|
|
|
|
|
}
|
|
|
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD>˵<EFBFBD>
|
|
|
|
|
void display_menu()
|
|
|
|
|
{
|
|
|
|
|
printf("*************************\n");
|
|
|
|
|
printf("***** ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ *****\n");
|
|
|
|
|
printf("*************************\n");
|
|
|
|
|
printf("1. <20><>ӡͼ<D3A1><CDBC><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("2. <20><>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>\n");
|
|
|
|
|
printf("4. <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("5. ɾ<><C9BE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("6. <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("7. <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("0. <20>˳<EFBFBD>ϵͳ\n");
|
|
|
|
|
printf("<22><>ѡ<EFBFBD><D1A1>:");
|
|
|
|
|
}
|
|
|
|
|
// ѡ<><D1A1><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĺ<EFBFBD><C4B9>ܺ<EFBFBD><DCBA><EFBFBD>
|
|
|
|
|
void make_choice()
|
|
|
|
|
{
|
|
|
|
|
int choice;
|
|
|
|
|
scanf("%d", &choice);
|
|
|
|
|
confirm();
|
|
|
|
|
switch(choice)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
print_data(); // <20><>ӡͼ<D3A1><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
query_data(); // <20><>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
add_data(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
update_data();// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
delete_data();// ɾ<><C9BE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
sort_data(); // <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
make_chart(); // <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
quit(); // <20>˳<EFBFBD>ϵͳ
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("<22><>Чѡ<D0A7><D1A1>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>:");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ȷ<>ϲ<EFBFBD><CFB2><EFBFBD>
|
|
|
|
|
void confirm()
|
|
|
|
|
{
|
|
|
|
|
char choice;
|
|
|
|
|
|
|
|
|
|
printf("<22><>ȷ<EFBFBD><C8B7>Ҫִ<D2AA>иò<D0B8><C3B2><EFBFBD><EFBFBD><EFBFBD>?(Y/N):");
|
|
|
|
|
scanf(" %c", &choice);
|
|
|
|
|
|
|
|
|
|
if(choice == 'Y' || choice == 'y')
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>ִ<EFBFBD><D6B4>!\n");
|
|
|
|
|
}
|
|
|
|
|
else if(choice == 'N' || choice == 'n')
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Y/N):");
|
|
|
|
|
confirm(); // <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// <20>˳<EFBFBD>ϵͳ,<2C>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD>
|
|
|
|
|
void quit()
|
|
|
|
|
{
|
|
|
|
|
char choice;
|
|
|
|
|
|
|
|
|
|
printf("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD>˳<EFBFBD>ϵͳ<CFB5><CDB3>?(Y/N):");
|
|
|
|
|
scanf(" %c", &choice);
|
|
|
|
|
|
|
|
|
|
if(choice == 'Y' || choice == 'y')
|
|
|
|
|
{
|
|
|
|
|
save_data(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD>
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><D1B1><EFBFBD>,ϵͳ<CFB5>˳<EFBFBD>!\n");
|
|
|
|
|
exit(0); // <20>˳<EFBFBD>ϵͳ
|
|
|
|
|
}
|
|
|
|
|
else if(choice == 'N' || choice == 'n')
|
|
|
|
|
{
|
|
|
|
|
printf("<22>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Y/N):");
|
|
|
|
|
quit(); // <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ģ<EFBFBD><C4A3>//
|
|
|
|
|
// <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5>ڴ<EFBFBD>
|
|
|
|
|
void read_data()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
struct book *head, *p;
|
|
|
|
|
|
|
|
|
|
if((fp = fopen("books.dat", "rb")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><CAA7>!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
head = NULL;
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
p = (struct book*)malloc(sizeof(struct book));
|
|
|
|
|
fread(p, sizeof(struct book), 1, fp);
|
|
|
|
|
p->next = head;
|
|
|
|
|
head = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp); // <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷָ<CDB7><D6B8><EFBFBD><EFBFBD>Ϊȫ<CEAA>ֱ<EFBFBD><D6B1><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
|
|
|
|
books = head;
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD>
|
|
|
|
|
void save_data()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
if((fp = fopen("books.dat", "wb")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><CAA7>!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = books; // <20><>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ
|
|
|
|
|
while(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
fwrite(p, sizeof(struct book), 1, fp);
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ӡͼ<D3A1><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void print_data()
|
|
|
|
|
{
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
p = books; // <20><>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ
|
|
|
|
|
while(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d\n", p->id);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n", p->name);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n", p->author);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD>۸<EFBFBD>:%.2f\n", p->price);
|
|
|
|
|
printf("----------------------\n");
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
book *find(int id)
|
|
|
|
|
{
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
p = books; // <20><>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ
|
|
|
|
|
while(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(p->id == id)
|
|
|
|
|
return p; // <20><><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>ͼ<EFBFBD><CDBC>ָ<EFBFBD><D6B8>
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
return NULL; // δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ؿ<EFBFBD>ָ<EFBFBD><D6B8> *p;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// <20><>ѯͼ<D1AF><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void query_data()
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ѯ<EFBFBD><D1AF>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
p = find(id); // <20><><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD>Ϊid<69><64>ͼ<EFBFBD><CDBC>
|
|
|
|
|
if(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>:\n");
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d\n", p->id);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n", p->name);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n", p->author);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD>۸<EFBFBD>:%.2f\n", p->price);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ϊ%d<><64>ͼ<EFBFBD><CDBC>!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void add_data()
|
|
|
|
|
{
|
|
|
|
|
struct book *p, *q;
|
|
|
|
|
|
|
|
|
|
p = (struct book*)malloc(sizeof(struct book));
|
|
|
|
|
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ:\n");
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d", &p->id);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s", p->name);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s", p->author);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD>۸<EFBFBD>:");
|
|
|
|
|
scanf("%f", &p->price);
|
|
|
|
|
|
|
|
|
|
q = books;
|
|
|
|
|
while(q != NULL && p->id > q->id)
|
|
|
|
|
q = q->next;
|
|
|
|
|
|
|
|
|
|
p->next = q; // ָ<><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
books = p; // <20>½ڵ<C2BD><DAB5><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ͷ
|
|
|
|
|
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ӳɹ<D3B3>!\n");
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void update_data()
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
struct book *p;
|
|
|
|
|
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ĵ<DEB8>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
p = find(id); // <20><><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD>Ϊid<69><64>ͼ<EFBFBD><CDBC>
|
|
|
|
|
if(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<DEB8><C4BA><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ:\n");
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s", p->name);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s", p->author);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD>۸<EFBFBD>:");
|
|
|
|
|
scanf("%f", &p->price);
|
|
|
|
|
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD>ijɹ<C4B3>!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ϊ%d<><64>ͼ<EFBFBD><CDBC>!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ɾ<><C9BE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void delete_data()
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
struct book *p, *q;
|
|
|
|
|
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
p = books;
|
|
|
|
|
q = NULL;
|
|
|
|
|
while(p != NULL && p->id != id)
|
|
|
|
|
{
|
|
|
|
|
q = p;
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
if(p != NULL) // <20>ҵ<EFBFBD><D2B5>ýڵ<C3BD>
|
|
|
|
|
{
|
|
|
|
|
if(q == NULL) // <20><>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
books = p->next;
|
|
|
|
|
else
|
|
|
|
|
q->next = p->next;
|
|
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD>Ϣɾ<CFA2><C9BE><EFBFBD>ɹ<EFBFBD>!\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ϊ%d<><64>ͼ<EFBFBD><CDBC>!\n", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void sort_data()
|
|
|
|
|
{
|
|
|
|
|
struct book *p, *q; // <20><><EFBFBD>ڵ<EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
struct book temp; // <20><>ʱͼ<CAB1><CDBC><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
|
|
|
|
|
|
|
|
|
p = books;
|
|
|
|
|
while(p != NULL)
|
|
|
|
|
{
|
|
|
|
|
q = p->next;
|
|
|
|
|
while(q != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(p->id > q->id) // <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp = *p;
|
|
|
|
|
*p = *q;
|
|
|
|
|
*q = temp;
|
|
|
|
|
}
|
|
|
|
|
q = q->next;
|
|
|
|
|
}
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
printf("ͼ<><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!\n");
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void make_chart()
|
|
|
|
|
{
|
|
|
|
|
struct book *p;
|
|
|
|
|
char name[20];
|
|
|
|
|
int i, n;
|
|
|
|
|
float price;
|
|
|
|
|
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ɵ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
|
|
|
|
|
for(i=1; i<=n; i++)
|
|
|
|
|
{
|
|
|
|
|
p = (struct book*)malloc(sizeof(struct book));
|
|
|
|
|
|
|
|
|
|
sprintf(name, "ͼ<><CDBC>%d", i); // <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
p->id = i; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
strcpy(p->name, name); // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
strcpy(p->author, "<22><><EFBFBD><EFBFBD>"); // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
price = (i+1)*10.0; // <20>۸<EFBFBD>
|
|
|
|
|
p->price = price; // ͼ<><CDBC><EFBFBD>۸<EFBFBD>
|
|
|
|
|
|
|
|
|
|
p->next = books; // <20>½ڵ<C2BD>ָ<EFBFBD><D6B8>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>ͷ
|
|
|
|
|
books = p; // <20>½ڵ<C2BD><DAB5><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ͷ
|
|
|
|
|
}
|
|
|
|
|
printf("<22><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ɳɹ<C9B3>!\n");
|
|
|
|
|
}
|