要怎么输出某一个或者全部学生的成绩
struct student{
float english;
float math;
float yuwen;
};
int main(){
struct student st[7];
st[1].math=30.4;
st[1].english=3.4;
st[1].yuwen=88.90;
printf("%d",st[1].yuwen);
}
struct student{
float english;
float math;
float yuwen;
};
int main(){
struct student st[7];
st[1].math=30.4;
st[1].english=3.4;
st[1].yuwen=88.90;
printf("%d",st[1].yuwen);
}
2022-11-18
//练习4:定义一个春夏秋冬四季的枚举类型。 enum sj{ chun, xia, qiu, dong }; //练习3:定义一个学生成绩的结构体,要求可以存放包含小数的数学,英语,语文成绩。 struct student { double math; double englith; double chinese; }; # include<iostream> int main() { std::cout << "练习1:如何将一个数组在初始化的时候,把所有元素都初始化为 0?" << std::endl; int array1[3] = {}; for (int i = 0; i < (sizeof(array1) / sizeof(array1[0])); i++) { std::cout << array1[i] << std::endl; } std::cout << "练习2:如何将一个数组在初始化的时候,把所有元素都初始化为 1?" << std::endl; int array2[5] = {}; for (int i = 0; i < (sizeof(array2) / sizeof(array2[0])); i++) { array2[i] = 1; std::cout << array2[i] << std::endl; } std::cout << "练习3:定义一个学生成绩的结构体,要求可以存放包含小数的数学,英语,语文成绩。" << std::endl; struct student stu[2]; for (int i = 0; i < (sizeof(stu) / sizeof(stu[0])); i++) { std::cout << "请输入第" << i + 1 << "个同学的语文、英语、数学成绩:" << std::endl; std::cin >> stu[i].chinese >> stu[i].englith >> stu[i].math; } for (int i = 0; i < (sizeof(stu) / sizeof(stu[0])); i++) { std::cout << "第" << i + 1 << "个同学的成绩:" << std::endl; std::cout << stu[i].chinese << std::endl; std::cout << stu[i].englith << std::endl; std::cout << stu[i].math << std::endl; } std::cout << "练习4:定义一个春夏秋冬四季的枚举类型。" << std::endl; sj c = chun, x = xia, q = qiu, d = dong; int t; std::cout << "春夏秋冬分别用序号0、1、2、3代表,请输入一个值:"; std::cin >> t; if (t == chun) { std::cout << "春天"; } else if (t == xia) { std::cout << "夏天"; } else if (t == qiu) { std::cout << "秋天"; } else if (t == dong) { std::cout << "冬天"; } return 0; }
#include <iostream> #include <string> struct Person { std::string name; int age; std::string occupation; };
int main() { Person person; person.name = "Alice"; person.age = 25; person.occupation = "Engineer"; std::cout << "Person Details:" << std::endl; std::cout << "Name: " << person.name << std::endl; std::cout << "Age: " << person.age << std::endl; std::cout << "Occupation: " << person.occupation << std::endl; return 0; }
举报