题目1

【问题描述】

建立一个学生的结构记录,包括学号、姓名和成绩。输入整数n(n<10),再输入n个学生的基本信息,要求计算并输出他们的平均成绩(保留2位小数)

【输入形式】

先输入学生数n(整型,n<10),再依次输入每个学生的学号(整型)姓名(字符串)和成绩(实型)。

【输入输出样例】

(下划线部分表示输入)

Input n:3

Input the number,name,score of the 1 student:1 zhang 70

Input the number,name,score of the 2 student:2 wang 80

Input the number,name,score of the 3 student:3 qian 90

The average score is:80.00

【样例说明】

输出格式为 The average score is:%.2f

标点符号全部为英文:

【代码】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include<iomanip>
using namespace std;
#define N 10
struct student{
int num;
char name[10];
int score;
};
int main()
{
int i,n,sum=0;
double x;
struct student s[N];
cout<<"Input n:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Input the number,name,score of the "<<i+1<<" student:";
cin>>s[i].num>>s[i].name>>s[i].score;
sum+=s[i].score;
}
x=sum/n;
cout<<"The average score is:"<<fixed<<setprecision(2)<<x<<endl;
return 0;
}

题目2

【问题描述】

建立一个通讯录的结构记录,包括姓名、生日、电话号码。输入n(n<10)个朋友的信息,再按他们的年龄从大到小的顺序依次输出其信息

【输入形式】

先输入朋友数n(整型,n<10),再依次输入每个朋友的姓名(字符串)、生日(整型)、和电话号码(字符串)。

【输入输出样例】

(下划线部分表示输入)
Input n:3
Input the name,birthday,number of the 1 friend:zhang 19850403 13912345678
Input the name,birthday,number of the 2 friend:wang 19821020 0571-88018448
Input the name,birthday,number of the 3 friend:qian 19840619 13609876543
wang□19821020□0571-88018448
qian□19840619□13609876543
zhang□19850403□13912345678

【样例说明】

按朋友年龄从大到小的顺序依次输出每位朋友的信息,内容与格式如下
姓名□生日□电话号码
%s□%d□%s
□表示空格

【代码】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
using namespace std;
struct friends
{
char name[10];
char num[20];
int birthday;
};
int main()
{
int i,n,j;
struct friends man[20];
struct friends temp;
cout<<"Input n:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Input the name,birthday,number of the "<<i+1<<" friend:";
cin>>man[i].name>>man[i].birthday>>man[i].num;
}
for(i=0;i<n-1;i++)
{
for(j=i;j<n;j++)
if(man[i].birthday>man[j].birthday)
{
temp=man[i];
man[i]=man[j];
man[j]=temp;
}
}
for(i=0;i<n;i++)
cout<<man[i].name<<" "<<man[i].birthday<<" "<<man[i].num<<endl;

return 0;
}

题目3

【问题描述】

某市青年歌手大赛聘请7名评委打分,下列程序协助进行评分统计。每位歌手用结构体数据类型,函数delmaxmin的功能是对一个选手的得分做以下计算:去掉一个最高分,去掉一个最低分,然后对剩余得分求平均分并保存。函数sort完成对n名选手的得分按平均分从高到低排序。

【输入形式】

请输入比赛选手人数:3
请输入比赛选手的比赛数据:
li 94 97 98 96 100 99 97
zhang 96 97 98 98 100 97 96
zhou 95 100 99 96 97 96 97

【输出形式】

姓名和分数均设置宽度为5

li:    94    97    98    96   100    99    97   97.40

zhang: 96 97 98 98 100 97 96 97.20

zhou: 95 100 99 96 97 96 97 97

【代码】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<string.h>
#include<iomanip>
using namespace std;


struct player
{
char player_name[20];
double score[7],aver;
};

void delmaxmin(player* a)
{
double max = a->score[0];
double min = a->score[0];
double sum = 0;
for (int i = 0; i < 7; i++)
{
if (max <a->score[i]) max = a->score[i];
if (min >a->score[i]) min = a->score[i];
sum = sum + a->score[i];
}
(*a).aver = (sum - max - min) / 5;
}



void sort(player pPlayers[],int pNum)

{
player Temp;
for(int i=0;i<pNum-1;i++)
for(int j=0;j<pNum-1-i;j++)
{
if(pPlayers[j].aver<pPlayers[j+1].aver)
{
Temp=pPlayers[j];
pPlayers[j]=pPlayers[j+1];
pPlayers[j+1]=Temp;
}
}
}



void ShowPlayers(player pPlayers[],int pNum)
{
for(int j=0;j<pNum;j++)
{
cout <<std::right<<setw(5)<< pPlayers[j].player_name ;
for (int i = 0; i < 7; i++)
{
cout <<std::right<<setw(5)<< pPlayers[j].score[i] ;
}
cout <<std::right<<setw(5)<< pPlayers[j].aver << endl;
}
cout<<endl;
}

int main()
{int p;
cout<<"请输入比赛选手人数:"<<endl;
cin>>p;
cout<<"请输入比赛选手的比赛数据:"<<endl;
player person[3]={
{"zhang:",96,97,98,98,100,97,96,0},
{" li:",94,97,98,96,100,99,97,0},
{" zhou:",95,100,99,96,97,96,97,0}
};

for (int i = 0; i < p; i++)

{
delmaxmin(&person[i]);
}
sort(person, p);
ShowPlayers(person,p);
}//注意转换成UTF-8格式

代码可能略有不足,请大佬多多指教