📄 func.c
字号:
#define LEN sizeof(INFO)
int n_num=0;
int n_name=0;
int n_mjr=0;
int n_sch=0;
int n_class=0;
int n_sort=0;
int n_gen=0;
int n_yr=0;
/* Function 018 */
/* This function is designed to search a student's information by name. */
void search_name(INFO *head_sear_name)
{
char name[21];
extern n_name;
INFO *p1;
if(head_sear_name==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the name of the student you want to search:");
scanf("%s",name);
p1=head_sear_name;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(strcmp(name,p1->name)==0) {print_1_info(p1);n_name++;}
p1=p1->next;
}
printf("\n\"%s\" -- Statistic result:\n",name);
if (n_name==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_name);
}
/* Function 019 */
/* This function is designed to search a student's information by student_number. */
void search_num(INFO *head_sear_num)
{
char num[9];
extern n_num;
INFO *p1;
if(head_sear_num==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the number of the student you want to search\n(8-bit number):");
scanf("%s",num);
p1=head_sear_num;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(strcmp(num,p1->number)==0) {print_1_info(p1);n_num++;}
p1=p1->next;
}
printf("\n\"%s\" -- Statistic result:\n",num);
if (n_num==0) printf("Sorry, there is no record that fits your query.\n");
printf("\nThere are %d student(s) found.\n",n_num);
}
/* Function 020 */
/* This function is designed to search a student's information by gender. */
void search_gen(INFO *head_sear_gen)
{
char gen,gen_temp;
extern n_gen;
INFO *p1;
if(head_sear_gen==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the gender of the student you want to search:");
scanf("%*c%c",&gen_temp);
if (gen_temp=='f'||gen_temp=='F') gen='F';
else if (gen_temp=='m'||gen_temp=='M') gen='M';
p1=head_sear_gen;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->gender==gen) {print_1_info(p1);n_gen++;}
p1=p1->next;
}
printf("\n\"%c\" -- Statistic result:\n",gen);
if (n_gen==0) printf("Sorry, there's no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_gen);
}
/* Function 021 */
/* This function is designed to search a student's information by school. */
void search_sch(INFO *head_sear_sch)
{
int sch;
extern n_sch;
INFO *p1;
if(head_sear_sch==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the school code of the student you want to search:");
scanf("%d",&sch);
p1=head_sear_sch;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->school==sch) {print_1_info(p1);n_sch++;}
p1=p1->next;
}
printf("\n\"%d\" -- Statistic result:\n",sch);
if (n_sch==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_sch);
}
/* Function 022 */
/* This function is designed to search a student's information by major. */
void search_mjr(INFO *head_sear_mjr)
{
int mjr;
extern n_mjr;
INFO *p1;
if(head_sear_mjr==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the major code of the student you want to search:");
scanf("%d",&mjr);
p1=head_sear_mjr;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->major==mjr) {print_1_info(p1);n_mjr++;}
p1=p1->next;
}
printf("\n\"%d\" -- Statistic result:\n",mjr);
if (n_mjr==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_mjr);
}
/* Function 023 */
/* This function is designed to search a student's information by sort. */
void search_sort(INFO *head_sear_sort)
{
char sort,sort_temp;
extern n_sort;
INFO *p1;
if(head_sear_sort==NULL)
{printf("\nError! List null!\n");}
printf("Please enter the sort of the student you want to search\n");
printf("('U' for undergraduates, 'S' for graduate students):");
scanf("%*c%c",&sort_temp);
if (sort_temp=='u'||sort_temp=='U') sort='U';
else if (sort_temp=='s'||sort_temp=='S') sort='S';
p1=head_sear_sort;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->sort==sort) {print_1_info(p1);n_sort++;}
p1=p1->next;
}
printf("\n\"%c\" -- Statistic result:\n",sort);
if (n_sort==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_sort);
}
/* Function 024 */
/* This function is designed to search a student's information by class. */
void search_class(INFO *head_sear_class)
{
int classes;
extern n_class;
INFO *p1;
if(head_sear_class==NULL)
{printf("\nError! List null!\n");return;}
printf("Please enter the class code of the student you want to search:");
scanf("%d",&classes);
p1=head_sear_class;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->classes==classes){print_1_info(p1);n_class++;}
p1=p1->next;
}
printf("\n\"%d\" -- Statistic result:\n",classes);
if (n_class==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_class);
}
/* Function 026 */
/* This function is designed to search a student's information by entrance year. */
void search_year(INFO *head_sear_year)
{
int year;
extern n_yr;
INFO *p1;
if(head_sear_year==NULL)
{printf("\nError! List null!\n");return;}
printf("Please enter the entrance year of the student you want to search:");
scanf("%d",&year);
p1=head_sear_year;
printf("\nSearch result:\n");
print_head();
while(p1!=NULL)
{
if(p1->year==year){print_1_info(p1);n_yr++;}
p1=p1->next;
}
printf("\n\"%d\" -- Statistic result:\n",year);
if (n_yr==0) printf("Sorry, there is no record that fits your query.\n");
else printf("\nThere are %d student(s) found.\n",n_yr);
}
/* Function 017 */
/* Sub-menu of searching the record(s) */
void menu_search(void)
{
char choice_search;
extern n_num,n_name,n_mjr,n_sch,n_sort,n_gen,n_class;
extern INFO *data_head;
do
{
clrscr();
printf("\n\t ====== Searchings and Statistics ======\n");
printf("\n Do you want to ...\n");
printf("\n\t 1. Search student record by number.");
printf("\n\t 2. Search student record by name.");
printf("\n\t 3. Search student record by school.");
printf("\n\t 4. Search student record by major.");
printf("\n\t 5. Search student record by class.");
printf("\n\t 6. Search student record by sort.");
printf("\n\t 7. Search student record by gender.");
printf("\n\t 8. Search student record by entrance year.\n");
printf("\n\t X. Quit to previous menu\n");
printf("\n Please choose one item:");
scanf("%*c%c",&choice_search);
switch(choice_search)
{
case 'x':
case 'X': clrscr();break;
case '1': clrscr();search_num(data_head);back_print();break;
case '2': clrscr();search_name(data_head);back_print();break;
case '3': clrscr();search_sch(data_head);back_print();break;
case '4': clrscr();search_mjr(data_head);back_print();break;
case '5': clrscr();search_class(data_head);back_print();break;
case '6': clrscr();search_sort(data_head);back_print();break;
case '7': clrscr();search_gen(data_head);back_print();break;
case '8': clrscr();search_year(data_head);back_print();break;
}
n_num=n_name=n_mjr=n_sch=n_sort=n_gen=n_class=n_yr=0;
}while(choice_search!='x'&&choice_search!='X');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -