题目内容:
设计学生类,数据成员包括学号、姓名、年龄、成绩;成员函数有构造函数、学生信息输出函数。定义带默认参数值的构造函数,默认值为:2021001,“Lili”,19,89.5。再编写一个普通函数,以学生对象作为函数参数,实现学生信息输出。编写主程序测试代码,定义一个不带参数的对象,调用类成员函数输出学生信息,再调用普通函数输出学生信息,对比两种输出函数形式的区别。
输入格式:
输出格式:
输出学号、姓名、年龄、成绩,在一行显示,逗号分隔
输入样例:
输出样例:
2021001,Lili,19,89.5
2021001,Lili,19,89.5
时间限制:500ms内存限制:32000kb
#include<iostream>
using namespace std;
class student
{
public:
int id;
string name;
int age;
float score;
student(int i = 2021001, string n = "Lili", int a = 19, float s = 89.5)
{
id = i;
name = n;
age = a;
score = s;
}
void printstu()
{
cout << id << "," << name << "," << age << "," << score << endl;
}
};
void printinf(student& s)
{
cout << s.id << "," << s.name << "," << s.age << "," << s.score << endl;
}
int main()
{
student s;
s.printstu();
printinf(s);
return 0;
}