/*学生信息系统DOS*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct student
{
char st_name[20];
char st_num[20];
char st_sex;
struct student * next;
}record;
struct student * current=NULL,* head=NULL,* build=NULL;
void main(void)
{
int menu();
void add();
void del();
void search();
clrscr();
while (1)
{
switch (menu())
{
case 1 : add(); continue;
case 2 : del(); continue;
case 3 : search(); continue;
case 4 : printf("/n It's wet!!!/n/n"); continue;
case 5 : exit(0);
default: continue;
}
}
printf("/n Thank you !!!/n/n");
}
int menu()
{
char c[10];
int choice;
printf("/n 1.Add a new record");
printf("/n 2.Delete a record");
printf("/n 3.Search a record");
printf("/n 4.Help");
printf("/n 5.Quit");
printf("/n/n Please input:");
gets(c);
choice=atoi(c);
return (choice);
}
void add()
{
clrscr();
if (head==NULL)
{
build=(struct student *)malloc(sizeof(record));
head=build,current=build;
}
else
{
build=(struct student *)malloc(sizeof(record));
current->next=build;
current=build;
}
printf("->Input name:");
gets(current->st_name);
printf("->Input number:");
gets(current->st_num);
printf("->Input sex:");
current->st_sex=getchar();
current->next=NULL;
}
void del()
{
char num[20];
struct student *temp,*del;
clrscr();
printf("->Input a student's number who you want to delete it!/n");
printf("->Input a number:");
gets(num);
del=head,temp=head;
while (1)
{
if (!strcmp(head->st_num,num))
{
head=head->next;
free(del);
printf("->Delete Success!/n/n");
break;
}
del=del->next;
if (!strcmp(del->st_num,num))
{
if (del->next==NULL)
{
temp->next=NULL;
free(del);
printf("->Delete Success!/n/n");
break;
}
else
{
temp->next=del->next;
free(del);
printf("->Delete Success!/n/n");
break;
}
}
else
{
if (del->next==NULL)
{
printf("->No student have been deleted, maybe you imputed a wrong number./n/n");
break;
}
}
temp=del;
}
}
void search()
{
char num[20];
clrscr();
printf("->Input a student's number who you want to find it!/n");
printf("->Input a number:");
gets(num);
build=head;
while (1)
{
if (!strcmp(build->st_num,num))
{
printf("/n%5s",build->st_name);
printf("/n%5s",build->st_num);
printf("/n%5c",build->st_sex);
break;
}
else
{
if (build->next==NULL)
{
printf("->No student have been found./n/n");
break;
}
build=build->next;
}
}
}