早教吧 育儿知识 作业答案 考试题库 百科 知识分享

c++结构体1.定义一个学生成绩结构体类型,包含"学号"、"姓名"、"性别"、"年龄"、"班级"、"英语"、"数学"、"物理"、"总分"、"名次"等信息。编写6个函数分别用于:(1)使用结构体数组,输

题目详情
c++结构体
1.定义一个学生成绩结构体类型,包含"学号"、"姓名"、"性别"、"年龄"、"班级"、"英语"、"数学"、"物理"、"总分"、"名次"等信息。编写6个函数分别用于:
(1) 使用结构体数组,输入全班10名学生的上述信息;
(2) 计算每一个学生的总分、平均分;
(3) 计算每一门课程的平均分;
(4)查找成绩有不及格的学生信息;
(5)按学生成绩总分降序排序;
(6)输出全班学生的学号、总分及名次。
▼优质解答
答案和解析
#include
struct student
{
// int xuehao;
char name[10];
// char sex;
// int age;
// char cla[20];
int english;
int math;
int physic;
int all;
// int place;
};
struct student input(struct student stu[],int y)
{
int i;
cout< for (i = 0; i < y; i++)
{
cin>>stu[i].name>>stu[i].english>>stu[i].math>>stu[i].physic;
}
return stu[y];
}
void output(struct student stu[], int y)
{
int i;
for (i = 0; i < y; i++)
{
cout< }
}
struct student setall(struct student stu[], int y)
{
int i;
for (i = 0; i < y; i++)
{
stu[i].all = stu[i].english + stu[i].math + stu[i].physic;
}
return stu[y];
}
int main(void)
{
struct student stu[1];
input(stu, 1);
stu[1] = setall(stu, 1);
output(stu, 1);
return 1;
}
这个程序并不符合你的要求,我只是,把在这里大概要使用的函数样式演示了一下,你可以对照进行函数参数传递和程序的完善,我想这样对你学习c++才有更大的帮助,这样可以帮你熟悉这些结构体使用的技巧。