其他分享
首页 > 其他分享> > 类的声明

类的声明

作者:互联网

6、小作业:
自己定义一个学生类,将该类的所有成员变量都声明为私有的,并添加一个共有的成员函数,实现从键盘录入该类对象的学生信息。

#include <iostream>
#include <string>
using namespace std;
class CStudent
{
    string s_name;
    string s_sex;
    int i_age;
public:
    void v_set_student_infor()
    {
        cout << "学生姓名 = ";
        cin >> s_name;
        cout << "学生性别 = ";
        cin >> s_sex;
        cout << "学生年龄 = ";
        cin >> i_age;
    }
    void v_get_student_infor()
    {
        cout << s_name << endl;
        cout << s_sex << endl;
        cout << i_age << endl;
    }
};
int main()
{
    CStudent CS_zhangsan;
    CS_zhangsan.v_set_student_infor();
    CS_zhangsan.v_get_student_infor();
    return 0;
}

 

标签:infor,cout,void,sex,student,include,声明
来源: https://www.cnblogs.com/SakuraQAQ/p/14238129.html