我是靠谱客的博主 虚幻白羊,这篇文章主要介绍习题 6.15 有一个班4个学生,5门课。1.求第一门课的平均分;2.找出有两门以上课程不及格的学生,输出他们的学号,全部课程成绩及平均成绩;3.找出平均成绩在90分以上或全部课程成绩在85分以上的学,现在分享给大家,希望可以做个参考。
C++程序设计(第三版) 谭浩强 习题6.15 个人设计
习题 6.15 有一个班4个学生,5门课。1.求第一门课的平均分;2.找出有两门以上课程不及格的学生,输出他们的学号,全部课程成绩及平均成绩;3.找出平均成绩在90分以上或全部课程成绩在85分以上的学生。分别编3个函数实现以上要求。
代码块:
复制代码
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
#include <iostream>
using namespace std;
float first_average(float (*s)[5], int n);
void two_fail(float (*p)[5], int m[], int n);
void high(float (*s)[5], int m[], int n);
int main()
{
float stu[4][5];;
int i, j, num[4];
for (i=0; i<4; i++){
cout<<"Please enter No."<<i+1<<" student info: ";
cin>>num[i];
for (j=0; j<5; cin>>stu[i][j++]);
}
cout<<"First course average: "<<first_average(stu, 4)<<endl;
two_fail(stu, num, 4);
high(stu, num, 4);
system("pause");
return 0;
}
float first_average(float (*s)[5], int n)
{
float sum, (*p)[5];
for(p=s, sum=0; p<s+n; sum+=**p, p++);
return sum/n;
}
void two_fail(float (*s)[5], int m[], int n)
{
int i, j, stand, t;
float sum, (*p)[5];
for (p=s, i=0; p<s+n; p++, i++){
for (j=0, stand=0, sum=0; j<5; sum+=*(*p+j), j++)
if (*(*p+j)<60) stand++;
if (stand>=2){
cout<<"Two fail result:n"<<m[i]<<' ';
for (t=0; t<5; cout<<*(*p+t++)<<' ');
cout<<sum/5<<endl;
}
}
}
void high(float (*s)[5], int m[], int n)
{
int i, j, cc, t;
float sum, (*p)[5];
for (p=s, i=0; p<s+n; p++, i++){
for (j=0, cc=0, sum=0; j<5; sum+=*(*p+j), j++)
if (*(*p+j)>=85) cc++;
if (cc==5||(sum/5)>=90){
cout<<"Highest score:n"<<m[i]<<' ';
for (t=0; t<5; cout<<*(*p+t++)<<' ');
cout<<endl;
}
}
}
最后
以上就是虚幻白羊最近收集整理的关于习题 6.15 有一个班4个学生,5门课。1.求第一门课的平均分;2.找出有两门以上课程不及格的学生,输出他们的学号,全部课程成绩及平均成绩;3.找出平均成绩在90分以上或全部课程成绩在85分以上的学的全部内容,更多相关习题内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复