Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Square{
- private:
- // 資料(變數部分)
- int len;
- public:
- // 操作(函式部分)
- int area(){
- return len * len;
- }
- // 建構式
- Square(){
- len = 0;
- }
- // set函式
- void setLen(int a){
- len = a;
- }
- // get函式
- int getLen(){
- return len;
- }
- };
- int main(){
- Square s1, s2;
- s2.setLen(20);
- cout << s1.area() << endl;
- cout << s2.area() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment