💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` #include <iostream> #include <stdlib.h> using namespace std; /** * 数据的封装 * 定义一个Student类,含有如下信息: * 1.姓名:name * 2.性别:gender * 3.学分(只读):score * 4.学习:study * @return */ class Student{ public: //设置名字 void setName(string _name){ str_name=_name; } //获取名字 string getName(){ return str_name; } //设置性别 void setGender(string _gender){ str_gender=_gender; } //获取性别 string getGender(){ return str_gender; } //获取分数 int getScore(){ return int_score; } //初始化分数 void initScore(){ int_score=0; } void study(int _score){ int_score+=_score;//分数相加 } private: string str_name; string str_gender; int int_score; }; int main(){ Student stu; stu.initScore(); stu.setName("zhangsan"); stu.setGender("女"); stu.study(50); stu.study(40); cout<<stu.getName()<<endl; cout<<stu.getGender()<<endl; cout<<stu.getScore()<<endl; return 0; } ```