#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#include<conio.h>
#define MAX_LEN 20
#define STU_NUM 200
#define MAX_ADD 20
#define N 30
typedef struct Student
{
long long id;
char name[MAX_LEN];
char sex[8];
int age;
int Class;
char add[MAX_ADD];
long long num;
long long int QQ;
char email[N];
}STU;
STU stu[STU_NUM];
int ch = -1;
int Menu(void);
int n = 0;
int Menu();
void choose(int ch);
void ReadData();
void Searchbyid();
void SortByid();
void Modifydata();
void Deletedatd();
void main()
{
printf("Input student number(n<=200):\n");
scanf("%d", &n);
while (1) {
ch = Menu();
choose(ch);
ch = -1;
}
}
int Menu()
{
int ch;
printf("**********************┍ -----------------------┑ *********************\n");
printf("********************** 欢迎使用学生通信管理系统 *********************\n");
printf("**********************┕------------------------┙ *********************\n");
printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx菜单xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
printf("======================================================================\n");
printf("....... 1.录入信息 ..... 2.查询信息 .......\n");
printf("....... 3.排序功能 ..... 4.删除信息 .......\n");
printf("....... 5.修改数据 ..... 0.退出系统 .......\n");
printf("Please Input your choice:\n");
scanf("%d", &ch);
return ch;
}
void choose(int ch)
{
switch (ch)
{
case 1:
printf("Input id,name,sex,age,Class,num,QQ,email(Pause:0):\n");
ReadData();
break;
case 2:
printf("Input the number you want to search : \n");
Searchbyid();
break;
case 3:
SortByid();
break;
case 4:
Modifydata();
break;
case 5:
Deletedatd();
break;
case 0:
printf("End of program!");
exit(0);
default: printf("Input error!\n");
}
}
void ReadData()
{
int i;
for (i = 0; i < n; i++)
{
printf("id:");
scanf("%lld", &stu[i].id);
if (stu[i].id == 0)break;
getchar();
printf("name:");
gets(stu[i].name);
printf("sex:");
scanf("%s", &stu[i].sex);
getchar();
printf("age:");
scanf("%d", &stu[i].age);
printf("Class:");
scanf("%d", &stu[i].Class);
printf("address:");
scanf("%s", &stu[i].add);
getchar();
printf("num:");
scanf("%lld", &stu[i].num);
printf("QQ:");
scanf("%lld", &stu[i].QQ);
printf("email:");
scanf("%s", &stu[i].email);
getchar();
printf("\n");
}
}
void Searchbyid()
{
long long int term = -1;
int i;
scanf("%lld", &term);
for (i = 0; i < n; i++)
{
if (term == stu[i].id)
{
printf("id:%lld\n", stu[i].id);
printf("name:%s\n", stu[i].name);
printf("sex:%s\n", stu[i].sex);
printf("age:%d\n", stu[i].age);
printf("Class:%d\n", stu[i].Class);
printf("address:%s\n", stu[i].add);
printf("phone number:%lld\n", stu[i].num);
printf("QQ:%lld\n", stu[i].QQ);
printf("email:%s\n", stu[i].email);
term = -2;
}
}
if (term != -2)
{
printf("Not found!\n");
}
getch();
}
void SortByid()
{
STU temp1 = { 0 };
int i, j;
for (i = 0; i < n - 1; i++)
{
if (stu[i].id > stu[i + 1].id)
{
temp1 = stu[i];
stu[i] = stu[i + 1];
stu[i + 1] = temp1;
}
}
for (j = 0; j < n; j++)
{
printf("id:%lld\n", stu[j].id);
printf("name:%s\n", stu[j].name);
printf("sex:%s\n", stu[j].sex);
printf("age:%d\n", stu[j].age);
printf("Class:%d\n", stu[j].Class);
printf("address:%s\n", stu[j].add);
printf("phone number:%lld\n", stu[j].num);
printf("QQ:%lld\n", stu[j].QQ);
printf("email:%s\n", stu[j].email);
printf("\n");
}
getch();
}
void Deletedatd()
{
int i, j, flag = 0;
long long id1;
printf("Please input the id:\n");
scanf("%lld", &id1);
for (i = 0; i < n; i++)
{
if (stu[i].id == id1)
{
flag = 1;
for (j = i; j < n - 1; j++)
{
stu[j] = stu[j + 1];
}
}
}
getch();
}
void Modifydata()
{
int i, item, j = -1;
long long s1;
printf("Please input the id:\n");
scanf("%lld", &s1);
for (i = 0; i < n; i++)
{
if (stu[i].id == s1)
{
j = i;
printf("1.Modify the name:\n");
printf("2.Modify the gender:\n");
printf("3.Modify the age:\n");
printf("4.Modify the class:\n");
printf("5.Modify the address:\n");
printf("6.Modify the phone number:\n");
printf("7.Modify the QQ:\n");
printf("8.Modify the email\n");
printf("0.End of program!\n");
while (1)
{
printf("please choose:");
scanf("%d", &item);
switch (item)
{
case 1:
printf("Please input new name:\n");
scanf("%s", &stu[j].name);
break;
case 2:
printf("Please input gender:\n ");
scanf("%s", &stu[j].sex);
break;
case 3:
printf("Please input new age:\n");
scanf("%d", &stu[j].age);
break;
case 4:
printf("Please input new Class:\n");
scanf("%d", &stu[j].Class);
break;
case 5:
printf("Please input new address:\n");
scanf("%s", &stu[j].add);
break;
case 6:
printf("Please input new phone number:\n");
scanf("%lld", &stu[j].num);
break;
case 7:
printf("Please input new QQ:\n ");
scanf("%lld", &stu[j].QQ);
break;
case 8:
printf("Please input new email:\n");
scanf("%s", &stu[j].email);
break;
default: printf("Input error!\n");
}
if (item == 0)
break;
}
}
}
getch();
}