C语言个人信息管理系统
Description:
小张是同学会的负责人,但是复杂的联系信息让他很头痛,请你帮他写一个个人信箱的管理系统(人数小于30人),每个人包含3项信息:
姓名 (小于20个字符) 性别(Female = 女, Male = 男) 生日(年月日)
每个人用一个结构体表示,同时支持以下操作:
add Tim Male 1993 12 22
添加一个名为Tim的男生,出生年月日位1993-12-22
name Tim
返回姓名为Tim的人的所有信息
sex Male
返回所有男生的信息(sex Female返回女生信息)
quit
退出系统
Input:
用户指令
Output:
输出结果
Sample Input:
add Tim Male 1993 12 22 add Britney Female 1992 2 23 add Freddy Male 1989 4 22 name Britney sex Male quit
Sample Output:
Britney Female 1992-2-23 Tim Male 1993-12-22 Freddy Male 1989-4-22
完整代码:
#include <stdio.h>
struct Student{
char name[10];
char sex[10];
int year;
int month;
int day;
} stu[30];
void main()
{
int i=0,j;
char a[10],b[10],c[10];
while(scanf("%s",a) != EOF && strcmp(a,"quit") != 0)
{
if(strcmp(a,"add") == 0)
{
scanf("%s%s%d%d%d",stu[i].name,stu[i].sex,&stu[i].year,&stu[i].month,&stu[i].day);
i++;
}else if(strcmp(a,"name") == 0)
{
scanf("%s",b);
for(j=0;j<30;j++)
{
if(strcmp(stu[j].name,b)==0)
{
printf("%s %s %d-%d-%d\n",stu[j].name,stu[j].sex,stu[j].year,stu[j].month,stu[j].day);
break;
}
}
}else if(strcmp(a,"sex") == 0)
{
scanf("%s",c);
for(j=0;j<30;j++)
{
if(strcmp(stu[j].sex,c)==0)
printf("%s %s %d-%d-%d\n",stu[j].name,stu[j].sex,stu[j].year,stu[j].month,stu[j].day);
}
}
}
}
人的一生像是一把算盘,似乎无时不在计算着什么,却是被别人拨弄的一生
浙公网安备 33010602011771号