Description
学生有属性学号,姓名,性别,三个成员,为私有属性;成员函数setdata负责输入学生的信息。成员函数display负责显示学生的信息。
Input
输入学生学号、姓名、性别
Output
输出学号、姓名、性别
Sample Input
Copy sample input to clipboard
1000
tan
m
Sample Output
1000
tan
代码实现:
#include<iostream>
using namespace std;
class Student{
private:
int number;
char name[10];
char sex;
public:
void setdata()
{
cin >> number >> name >> sex;
}
void display()
{
cout << number << endl;
cout << name << endl;
cout << sex << endl;
}
};
int main()
{
Student stu;
stu.setdata();
stu.display();
return 0;
}