1 #include<iostream> 2 #include<string> 3 #include<algorithm>//sort函数包含的头文件 4 using namespace std; 5 //定义一个学生类型的结构体 6 typedef struct student 7 { 8 string name; //学生姓名 9 int achievement; //学生成绩 10 } student; 11 12 13 14 15 //用来显示学生信息的函数 16 void show(student *stu,int n) 17 { 18 for(int i = 0; i < n; i++) 19 { 20 cout<<"姓名:"<<stu[i].name<<' '<<"成绩:"<<stu[i].achievement<<endl; 21 } 22 } 23 24 int main() 25 { 26 student stu[] = { {"张三",99},{"李四",87},{"王二",100} ,{"麻子",60}}; 27 cout<<"交换前:"<<endl; 28 show(stu,4); 29 swap(stu[0],stu[3]); 30 cout<<"交换后:"<<endl; 31 show(stu,4); 32 return 0; 33 }
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/5707.html