一道C++编程题,求高手解决下~

2024-12-14 07:07:26
推荐回答(4个)
回答1:

完全符合你的要求,哪不懂随时hi我~ok?
#include
#include
using namespace std;
#define NUM 12
struct Ath
{
int no;//名次
char s[3];//编号
float perf;//成绩
}ath[NUM];

void seque(Ath a[NUM])//冒泡排序函数
{
Ath tmp;
int n=12;
for(int k=0;k<12;k++)//计数用
{

for(int j=0;j<11-k;j++)
if(a[j].perf>a[j+1].perf)
{
tmp=a[j+1];
a[j+1]=a[j];
a[j]=tmp;
}
a[n-1].no=n;//给每个运动员排定名次
n--;
}
//return a[NUM];
}

void main()
{
for(int i=0;i<12;i++)//输入运动员信息
{
cout<<"请输入第"< cin>>ath[i].s>>ath[i].perf;
}
seque(ath);
cout<<"名次\t"<<"编号\t"<<"成绩\t"< for(int m=0;m<12;m++)
cout<}

回答2:

#include
#include
using namespace std;

struct Players
{
int num;
float score;
};

int main()
{
Players member[12] = {{001, 13.6}, {002, 14.8},
{010, 12.0}, {011, 12.7},
{023, 15.6}, {025, 13.4},
{031, 14.9}, {036, 12.6},
{037, 13.4}, {102, 12.5},
{325, 15.3}, {438, 12.7}
};
int temp_N;
float temp_S;

//Bubble Sort
for(int i=0; i<12; ++i)
{
for(int j=0; j<12-i; ++j)
{
if(member[j].score > member[j+1].score)
{
temp_N = member[j+1].num;
temp_S = member[j+1].score;
member[j+1].num = member[j].num;
member[j+1].score = member[j].score;
member[j].num = temp_N;
member[j].score = temp_S;
}
}
}

cout << setiosflags(ios::left) << setw(6) << "名次" << setw(6) << "号码" << setw(6) << "成绩" << endl;
for(int i=0; i<12; ++i)
{
cout << setiosflags(ios::left) << setiosflags(ios::fixed) << setprecision(1)
<< setw(6) << setw(6) << i+1 << setw(6) << member[i].num << setw(6) << member[i].score << endl;
}
}

回答3:

class Sporter
{
friend class Comption;
public:
int number;
float sorce;

Comption(int num,float sor)
{

}
};
class Comption
{
public:
Sporter spo[12];
Sporter temp;

void Init()
{
spo[0].Comption(001,13.6);
spo[1].Comption(002,14.8);
spo[2].Comption(010,12.0);
spo[3].Comption(011,12.7);
spo[4].Comption(023,15.6);
spo[5].Comption(025,13.4);
spo[6].Comption(031,14.9);
spo[7].Comption(036,12.6);
spo[8].Comption(037,13.4);
spo[9].Comption(102,12.5);
spo[10].Comption(325,15.3);
spo[11].Comption(438,12.7);

}

void Swap(Sporter &sp1,Spoter &sp2)
{
temp.number=sp1.number;
temp.sorce=sp1.sorce;

sp1.number=sp2.number;
sp1.sorce=sp2.sorce;

sp2.number=temp.number;
sp2.sorce=sp2.sorce;
}

void PaiXu()
{
for(int i=0;i<12;i++)
{
for(int j=i+1;j<12;j++)
{
if(spo[i]>spo[j])
this.Swap(spo[i],spo[j])
}
}
};

void Show()
{
for(int i=0;i<12;i++)
{
cout>>"NO.">>i+1>>"\tNumbers:">>spo[i].number>>"\tTime:">>spo[i].sorce>>end;
}
}

};

void main()
{
Competion com;
com.Init();
com.PaiXu();
com.Show();
}

//正在安装VS2008
//在记事本里面打的 所以没有调试
//但是逻辑应该没有问题

回答4:

#include
#include
struct Player
{
string num ;
float score;
};

void Sort(Player a[]);

int main()
{
Player stud[6]; //定义结构体数组stud,有12个元素;

for(int i=0;i<6;++i) //给数组元素赋值
{
cout<<" \n运动员号:";
cin>>stud[i].num;
cout<<" \n成绩:";
cin>>stud[i].score;

}

Sort(stud);
int i=6 ;
for(int j=0;j<6;++j)
{
cout<<"\n第"< i--;
}

return 0;
}

void Sort(Player a[])
{
Player temp;
int i,j;
for(i=0;i<6;i++)
for(j=0;j<6;++j)
{ if(a[j].score {
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}

}