//用结构体数组存放5个人的信息(姓名、性别、年龄),统计5个人中男女人数并输出,并输出年龄最小和最大者的姓名
#include<iostream>
using namespace std;
struct Person
{
char name[20];
char sex;
int age;
};
int main()
{
Person stu[5];
int i,a=0,b=0;
for(i=0;i<5;i++)
{
cout<<"please enter the information:"<<endl;
cin>>stu[i].name>>stu[i].sex>>stu[i].age;
if(stu[i].sex=='F')
a++;
else
b++;
}
cout<<" there are "<<a<<"girls"<<endl;
cout<<" there are "<<b<<"boys"<<endl;
int j,k=1,h=1;
for(j=2;j<6;j++)
{
if(stu[k].age<stu[j].age)
k=j;
if(stu[h].age>stu[j].age)
用结构体存放学生信息
最新推荐文章于 2024-04-29 00:37:27 发布