示例-结构-简易学生信息管理
问题
构建学生信息数据结构,完成对信息的修改,查询等。 分析
- 定义学生信息内容:学号、姓名、性别、出生日期、院系、专业等
- 输入信息函数
- 输出信息函数
- 查询信息函数
- 依次论推……
代码
#include<stdio.h>
#define MAX 3
typedef struct{
int year;
int month;
int day;
}Date;
typedef struct{
char id[16];
char name[20];
Date birthday;
char department[50];
char major[50];
}Student;
//输入信息函数 void inputStudent(Student []); //输出信息函数 void outputStudent(Student []); //查询信息函数 void searchStudent(Student [],Date); // 输出单一学生信息 void showStudent(Student s)
// 输出单一学生信息
void showStudent(Student s)
{
printf(“\n\nStudentID:%s",s.id);
printf(“\nStudentName:%s",s.name);
printf(“\nBirthDay(year-month-day)”);
printf(“%d ",s.birthday.year);
printf(“-%d ",s.birthday.month);
printf(“-%d ",s.birthday. day);
printf(“\nDepartment:%s",s.department);
printf(“\nMajor:%s",s.major);
}
//输入信息函数
void inputStudent(Student s[])
{
int i;
for(i=0;i< MAX;i++){
printf("\n Enter a student infomation \n");
printf(“\nStudentID:”);
scanf("%s",&s[i].id);
printf(“\nStudentName:”);
scanf("%s",&s[i].name);
printf(“\nBirthDay(year-month-day):”);
scanf("%d-%d-%d",&s[i].birthday.year,&s[i].birthday.month,&s[i].birthday.day);
printf(“\nDepartment:”);
scanf("%s",&s[i].department);
printf(“\nMajor:”);
scanf("%s",&s[i].major);
}
}
//输出信息函数
void outputStudent(Student s[])
{
int i;
printf("\n printf all student infomation");
for(i=0;i< MAX;i++)
{
showStudent(s[i]);
}
}
//查询信息函数
void searchStudent(Student s[], Date date)
{
int i;
printf("\n searched in all student infomation");
for(i=0;i< MAX;i++)
{
if(s[i].birthday.month>date.month)
{
showStudent(s[i]);
continue;
}
if(s[i].birthday.month==date.month && s[i].birthday.day>date.day)
{
showStudent(s[i]);
}
}
printf("\n");
}
//主函数
void main()
{
Student s[MAX];
Date date;
inputStudent(s);
outputStudent(s);
printf("\n Enter a date(month,day) \n");
scanf("%d%d",&date.month,&date.day);
searchStudent(s,date);
}
高级设计
界面操作简单明了。
学生信息管理
- 输入学生信息
- 输出学生信息
- 查询学生信息
- 退出
屏幕输出定义、操作 固定行输入、输出等
|