大多数情况下,把所有数据指定为私有,以实现信息屏蔽,而把函数指定为公用的。
#include <iostream>
using namespace std;
class Student {
private:
int num;
int score;
public:
void setData() {
cin >> num;
cin >> score;
}
void display() {
cout << "num = " << num << endl;
cout << "score =" << score<<endl;
}
};
Student stud1, stud2;
int main() {
stud1.setData();
stud2.setData();
stud1.display();
stud2.display();
return 0;
}
网友评论