#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Date{
int year;
int month;
int day;
};
struct PersonInfo{
char name[20];
int age;
char firstYesOrNot[2];
struct Date firstDate;
char secondYesOrNot[2];
struct Date secondDate;
};
void inputInfo(struct PersonInfo *personInfo){
printf("请问姓名是:"); scanf("%s",personInfo->name);
printf("请问年龄是:");scanf("%d",&personInfo->age);
printf("请问是否接种过疫苗(Y/N):");
scanf("%s",personInfo->firstYesOrNot);
if(strcmp(personInfo->firstYesOrNot,"Y")){
printf("请出入第一针疫苗接种的日期(yyyy-mm-dd):");scanf("%d-%d-%d",&personInfo->firstDate.year,&personInfo->firstDate.month,&personInfo->firstDate.day);
printf("请问是否接种第二针疫苗(Y/N):");gets(personInfo->secondYesOrNot);
if(strcmp(personInfo->secondYesOrNot,"Y")){
printf("请出入第二针疫苗接种的日期(yyyy-mm-dd):");scanf("%d-%d-%d",&personInfo->secondDate.year,&personInfo->secondDate.month,&personInfo->secondDate.day);
}else if(strcmp(personInfo->secondYesOrNot,"N")){
printf("请尽快接种第二针疫苗!");
exit(1);
}
}else {
printf("请尽快接种过疫苗!");
exit(1);
}
}
void printInfo(struct PersonInfo *personInfo){
printf("姓名:%s,年龄:%d \n",personInfo->name,personInfo->age);
if(strcmp(personInfo->firstYesOrNot,"N")){
printf("未接种疫苗!");
}else if(strcmp(personInfo->firstYesOrNot,"Y")){
printf("第一针疫苗接种日期:%d-%d-%d \n",personInfo->firstDate.year,personInfo->firstDate.month,personInfo->firstDate.day);
if(strcmp(personInfo->secondYesOrNot,"N")){
printf("未接种第二针疫苗!");
}else if(strcmp(personInfo->secondYesOrNot,"Y")){
printf("第二针疫苗接种日期:%d-%d-%d",personInfo->secondDate.year,personInfo->secondDate.month,personInfo->secondDate.day);
}
}
}
int main(void){
struct PersonInfo person1,person2,person3;
inputInfo(&person1);
inputInfo(&person2);
inputInfo(&person3);
printInfo(&person1);
printInfo(&person2);
printInfo(&person3);
return 0;
}
|