结构体指针与结构体数组的结合。。。

//结构体数组与结构体变量的结合。

#include <iostream>
#include <string>                              //字符串变量的事用前提。
using namespace std;


struct student                                //结构体student。
{string name ;
string adress;
double num;
char sex;
double score;
}  stu[6];


int main()                                   //main函数,用于输入与调用。
{void shuchu(student *p);
int i;
student *p=stu;                              //定义结构体指针,并赋予结构体变量的地址。
cout<<"请依次输入姓名,性别,地址,学号,成绩:"<<endl;
for(i=0;i<6;i++)
cin>>(p+i)->name>>(p+i)->sex>>(p+i)->adress>>(p+i)->num>>(p+i)->score;
shuchu(p);
return 0;
}

 

void shuchu(student *p)                        //shuchu函数,用于挑选分数最高与最低然后输出。
{int i,t,m;
for(i=0,t=1;t<6;t++)
if((p+i)->score<(p+t)->score)   i=t;
for(m=0,t=1;t<6;t++)
if((p+m)->score>(p+t)->score)   m=t;
cout<<"first:"<<(p+i)->name<<"\\"<<(p+i)->sex<<"\\"<<(p+i)->adress<<"\\"<<(p+i)->num<<"\\"<<(p+i)->score<<endl;
cout<<"last:"<<(p+m)->name<<"\\"<<(p+m)->sex<<"\\"<<(p+m)->adress<<"\\"<<(p+m)->num<<"\\"<<(p+m)->score<<endl;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值