您的位置:首页 > 大数据 > 人工智能

定义一个学生类Student,包含三个属性(学号,姓名,成绩)均为私有的,分别给这三个属性定义两个成员函数,一个设置它的值,另一个获得它的值。然后在main函数中通过对象调用成员函数。

2020-03-05 02:30 8715 查看
#include<iostream>
#include <string.h>
using namespace std;
class student
{
public:
void Init()
{
cout << number << " " << score << " " << name;
}
void GetN(int n) { number=n; }
void GetS(int s) { score=s; }
void GetA(char a[]) { strcpy_s(name, a); }

private:
int number, score;
char name[50];
};

int main()
{
char a[9] = { "小红" };
student stu;
stu.GetN(10);
stu.GetS(100);
stu.GetA(a);
stu.Init();
return 0;
}
  • 点赞
  • 收藏
  • 分享
  • 文章举报
Karon_R 发布了5 篇原创文章 · 获赞 0 · 访问量 84 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐