该程序含有结构体,结构体含有姓名、学号、年龄、身高、和体重等信息
题目:登记学生的学号、姓名、年龄、身高和体重等信息,并输出相关信息。
使用函数引用结构体中的数据时需要使用&来提取,否则乱码
源代码如下
#include<iostream>
using namespace std;
struct student {
int StuID;
string StuName;
string StuSex;
double StuHeight;
double StuWeight;
};
student stu;
void StuIntput(student& stu) {
cout << "请依次输入学生的学号、姓名、年龄、身高和体重等信息" << endl;
cin >> stu.StuID >> stu.StuName >> stu.StuSex >> stu.StuHeight >> stu.StuWeight;
}
void StuOutput(student& stu) {
cout << "学号:" << stu.StuID << "\n姓名:" << stu.StuName << "\n性别:" << stu.StuSex << "\n身高:" << stu.StuHeight << "\n体重:" << stu.StuWeight << endl;
}
int main() {
StuIntput(stu);
StuOutput(stu);
return 0;
}
一名来自北京印刷学院计科的学生