~cpp #include <stdio.h> #include <string.h> const int MAX_DATA_SIZE=100; const int HANG_MOK=4; const int MAX_MENU=8; const int QUIT=6; const char menu[MAX_MENU][20]={"insert","modify","delete","undelete","search","list","quit","?"}; const char print_outs[HANG_MOK][5]={"id","name","tel","add"}; const int MAX_BLOCK_SIZE=256; const int FALSE=-1; const int ALL=-1; char datas[MAX_DATA_SIZE+1][HANG_MOK][MAX_BLOCK_SIZE]; int how_many_data=0; int prv_del=-1; int select_menu(); void function_insert();void function_modify();void function_delete();void function_undelete();void function_search();void function_list();void function_quit();void function_help(); int such_data(); void print_list(int); void modify_data(int); void print_cursur(); void main() { void (*functions[MAX_MENU])(void)={function_insert,function_modify,function_delete,function_undelete,function_search,function_list,function_quit,function_help}; while (1) { int selected_number=select_menu(); functions[selected_number](); if (QUIT==selected_number) break; } } int select_menu() { char temp_input[20]; while (1) { print_cursur(); scanf("%s",temp_input); for (register int i=0; i<MAX_MENU; ++i) { if (0==strcmp(temp_input,menu[i])) return i; } printf ("ERROR!! - code:00 - Wrong order!!\n"); } } void function_insert() { if (MAX_DATA_SIZE==how_many_data) printf("ERROR!! - code:03 - data overflow!!\n"); else { modify_data(how_many_data); ++how_many_data; } } void function_modify() { int target=such_data(); if (FALSE!=target) modify_data(target); } void function_delete() { int target=such_data(); if (FALSE!=target) { for (register int i=0; i<HANG_MOK; ++i) strcpy(datas[MAX_DATA_SIZE][i],datas[target][i]); for (register int i=target+1; i<how_many_data; ++i) { for (register int j=0; j<HANG_MOK; ++j) strcpy(datas[i-1][j],datas[i][j]); } --how_many_data; prv_del=target; } } void function_undelete() { if (-1==prv_del) printf("ERROR!! - code:02 - Can't find deleted data!!\n"); else { for (register int i=how_many_data-1; prv_del<=i; --i) { for (register int j=0; j<HANG_MOK; ++j) strcpy(datas[i+1][j],datas[i][j]); } for (register int i=0; i<HANG_MOK; ++i) strcpy(datas[prv_del][i],datas[MAX_DATA_SIZE][i]); ++how_many_data; prv_del=-1; } } void function_search() { int target=such_data(); if (FALSE!=target) print_list(target); } void function_list() { print_list(ALL); } void function_quit() { printf ("Goodbye~\n"); } void function_help() { printf("Menu: "); for (register int i=0; i<MAX_MENU; ++i) printf(" %s ",menu[i]); printf("\n"); } int such_data() { int select_number; char temp_data[MAX_BLOCK_SIZE]; printf("select number : "); for (register int i=0; i<HANG_MOK; ++i) printf("%d. %s\t",i,print_outs[i]); printf("\n"); print_cursur(); scanf("%d",&select_number); printf("content? "); scanf("%s",temp_data); for (register int i=0; i<how_many_data; ++i) { if (0==strcmp(temp_data,datas[i][select_number])) return i; } printf("ERROR!! - code:01 - Can't find!!\n"); return FALSE; } void print_list(int number) { for (register int i=0; i<HANG_MOK; ++i) printf("%s\t",print_outs[i]); printf("\n"); if (ALL==number) { for (register int i=0; i<how_many_data; ++i) { for (register int j=0; j<HANG_MOK; ++j) printf("%s\t",datas[i][j]); printf("\n"); } } else { for (register int j=0; j<HANG_MOK; ++j) printf("%s\t",datas[number][j]); printf("\n"); } } void modify_data(int target) { for (register int i=0; i<HANG_MOK; ++i) { printf("%s? ",print_outs[i]); scanf("%s",datas[target][i]); } } void print_cursur() { printf(">>"); }