View Code of Problem 95

#include <iostream>
#include <string.h>

using namespace std;

typedef struct
{
    char name[20];
    char sex[10];
    int year,month,day;
}student;

int main(){
    char name[20],sex[10];
    student stu[30];
    int n=0;
    while(1){
        char str[20];
        scanf("%s",str);
        if (!strcmp(str,"add"))
        {
            scanf("%s %s %d %d %d",stu[n].name,stu[n].sex,&stu[n].year,&stu[n].month,&stu[n].day);
            n++;
        }
        else if (!strcmp(str,"name"))
        {
            scanf("%s",name);
        }
        else if (!strcmp(str,"sex"))
        {
            scanf("%s",sex);
        }
        else if (!strcmp(str,"quit"))
        {
            break;
        }
    }
        for (int i = 0; i < n; i++)
        {
            if (!strcmp(name,stu[i].name))
            {
                printf("%s %s %d-%d-%d\n",stu[i].name,stu[i].sex,stu[i].year,stu[i].month,stu[i].day);
                break;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(!strcmp(sex,stu[i].sex))
                printf("%s %s %d-%d-%d\n",stu[i].name,stu[i].sex,stu[i].year,stu[i].month,stu[i].day);
        }
    
    
    return 0;
}

Double click to view unformatted code.


Back to problem 95