为了账号安全,请及时绑定邮箱和手机立即绑定

MSB600 "CL.exe"已退出,代码2

#include <string>
#include <iostream>
#include <stdlib.h>

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;
 }
 int initScore()
 {
  m_iScore = 0;
 }
 int study(int _score)
 {
  m_iScore = _score + m_iScore;
 }
private:
 string m_strName;
 string m_strGender;
 int m_iScore = 0;
};

int main()
{
 Student stu;
 stu.initScore();
 stu.setName("zhangsan");
 stu.setGender("female");
 stu.study(6);
 stu.study(5);

 cout << stu.getName() << " " << stu.getGender() << " " << stu.getScore() << endl;

 system("pause");
 return 0;

}

正在回答

1 回答

zhangsan female 11

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C++远征之封装篇(上)
  • 参与学习       103431    人
  • 解答问题       701    个

封装--面向对象的基石,本教程力求帮助小伙伴们即学即会

进入课程

MSB600 "CL.exe"已退出,代码2

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信