c语音程序
发布网友
发布时间:2022-09-22 11:39
我来回答
共1个回答
热心网友
时间:2023-12-17 03:48
#include<iostream>
using namespace std;
const int num = 10;
typedef struct studentinfo_
{
int score;
char *name;
}studentinfo;
void sortstudentarray(studentinfo * students, int num)
{
int i, j;
for (i = 1; i < num; i++ )
{
for (j = i; j > 0 && students[j].score > students[j - 1].score; j--)
{
studentinfo tmp;
tmp.score = students[j].score;
tmp.name = students[j].name;
students[j].score = students[j - 1].score;
students[j].name = students[j - 1].name;
students[j - 1].score = tmp.score;
students[j - 1].name = tmp.name;
}
}
}
void output_bujige_student(studentinfo* students, int num)
{
int i;
for (i = 0; i < num; i++)
{
if (students[i].score < 60)
{
cout<<students[i].name<<endl;
}
}
}
void freename(studentinfo * students, int num)
{
int i;
for (i = 0;i < num; i++)
{
free(students[i].name);
}
}
int main()
{
int i;
studentinfo studentarray[num];
cout<<"请输入十个学生的名字和对应分数:"<<endl;
for (i = 0; i < num; i++)
{
studentarray[i].name = new char[20];
cin>>studentarray[i].name;
cin>>studentarray[i].score;
}
cout<<"输入结束"<<endl;
sortstudentarray(studentarray, num);
output_bujige_student(studentarray, num);
freename(studentarray, num);
return 0;
}
//已测试通过