📄 demo_struct_07.cpp
字号:
//******************************
//** struct_07.cpp **
//******************************
# include <iostream.h>
struct Person
{
char name[20];
unsigned long id;
float salary;
};
void Print(Person& pr) // 参数传递中结构按引用传递
{
cout<<pr.name<<" "
<<pr.id<<" "
<<pr.salary<<endl;
}
Person allone[6]={{"jone",12345,339.0},
{"david",13916,449.0},
{"marit",27519,311.0},
{"jasen",42876,623.0},
{"peter",23987,400.0},
{"yoke",12335,511.0}};
void main()
{
Person temp;
for(int i=1;i<6;i++)
{
for(int j=0;j<=5-i;j++)
{
if(allone[j].salary>allone[j+1].salary)
{
temp=allone[j];
allone[j]=allone[j+1];
allone[j+1]=temp;
}
}
}
for(int k=0;k<6;k++)
{
Print(allone[k]);
}
}
/*
marit 27519 311
jone 12345 339
peter 23987 400
david 13916 449
yoke 12335 511
jasen 42876 623
Press any key to continue
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -