建立一个Student 类,含有以下信息:
1、姓名:name
2、性别:gender
3、学分(只读):score
4、学习:study
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
class Student
{
public:
void setName(string _name)
{
m_strName = _name;
}
string getName()
{
return m_strName;
}
void setGender(string _gender)
{
m_strGender= _gender;
}
string getGender()
{
return m_strGender;
}
int getScore()
{
return m_iScore;
}
void initScore()
{
m_iScore=0;
}
void study(int _score)
{
m_iScore += _score;
}
private:
string m_strName;//姓名
string m_strGender;//性别
int m_iScore;//学分只读
};
int main(void)
{
Student stu;
stu.initScore();//初始化
stu.setName("ly");//设置姓名赋值
stu.setGender("male男");//设置性别赋值
stu.study(5);
stu.study(3);
cout<<stu.getName()<<" "<<stu.getGender() <<" "<<stu.getScore()<<endl;
return 0;
}