View Code of Problem 95

#include<iostream>
#include<string>
using namespace std;
typedef struct
{
    /* data */
    string name,sex;
    int y,m,d;
} sp;

int main()
{
    string sk;
    sp stu[30];
    int i=0,j;
    while( cin>>sk )
    {   
        if( sk == "add" )
        {
            cin>>stu[i].name>>stu[i].sex>>stu[i].y>>stu[i].m>>stu[i].d;
            i++;
            
        }else if( sk == "name" )
        {
            string na;
            cin>>na;
            for( j=0;j<=i;j++ )
            {
                if( stu[j].name == na )
                cout<<stu[j].name<<" "<<stu[j].sex<<" "
                <<stu[j].y<<"-"<<stu[j].m<<"-"<<stu[j].d<<endl;
            }
        }else if (sk == "sex" )
        {
            /* code */
            string se;
            cin>>se;
            for( j=0;j<=i;j++ )
            {
                if( stu[j].sex == se )
                cout<<stu[j].name<<" "<<stu[j].sex<<" "
                <<stu[j].y<<"-"<<stu[j].m<<"-"<<stu[j].d<<endl;

            }
            
        }else if( sk == "quit" )break;
    }
    

}

Double click to view unformatted code.


Back to problem 95