• 코드:
​x
 
1
#include <iostream>
2
using namespace std;
3
​
4
class Book
5
{
6
private:
7
    int current_page_;
8
    void set_percent();
9
public:
10
    Book(const string& title, int total_page);
11
    string title_;
12
    int total_page_;
13
    double percent_;
14
    void Move(int page);
15
    void Open();
16
    void Read();
17
};
18
​
19
int main(void)
20
{
21
    Book web_book("HTML과 CSS", 350);    // 생성자의 암시적 호출 
22
    // 생성자가 호출되어 멤버 변수인 percent_가 초기화되었는지를 확인함. 
23
    cout << web_book.percent_;
24
    return 0;
25
}
26
​
27
Book::Book(const string& title, int total_page)
28
{
29
    title_ = title;
30
    total_page_ = total_page;
31
    current_page_ = 0;
32
    set_percent();
33
}
34
​
35
void Book::set_percent()
36
{
37
    percent_ = (double) current_page_ / total_page_ * 100;
38
}
표준입력 & 실행옵션