AP2_(1).cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <string> using namespace std; class Person { int id; double weight; string name; public: Person() { id = 1; weight = 20.5; name = "Grace"; } Person(int id, string name) { this->id = id; this->name = name; weight = 20.5; } Person(int id, string name, double weight) { this->id = id; this->name = name; this->weight = weight; } void show() { cout << id << ' ' << weight << ' ' << name << endl; } }; int main() { Person grace, ashley(2, "Ashley"), helen(3, "Helen", 32.5); grace.show(); ashley.show(); helen.show(); } | cs |
AP2_(2).cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> #include <string> using namespace std; class Person { int id; double weight; string name; public: Person(int id = 1, string name = "Grace", double weight = 20.5) { this->id = id; this->name = name; this->weight = weight; } void show() { cout << id << ' ' << weight << ' ' << name << endl; } }; int main() { Person grace, ashley(2, "Ashley"), helen(3, "Helen", 32.5); grace.show(); ashley.show(); helen.show(); } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 6장 4번 (0) | 2018.05.10 |
|---|---|
| 명품 C++ Programming 실습문제 6장 3번 (0) | 2018.05.10 |
| 명품 C++ Programming 실습문제 6장 1번 (0) | 2018.05.09 |
| 명품 C++ Programming 6장 OpenChallenge (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 8번 (0) | 2018.05.09 |