<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>hyeonu_chun.log</title>
        <link>https://velog.io/</link>
        <description>Stay hungry, stay foolish</description>
        <lastBuildDate>Tue, 22 Jun 2021 09:15:03 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>hyeonu_chun.log</title>
            <url>https://images.velog.io/images/hyeonu_chun/profile/54a4ef53-6176-4c7f-ab33-f69de428fdbe/B612_20190420_162633_770.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. hyeonu_chun.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/hyeonu_chun" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[2020-11-30 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-11-30-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-tt2mcfky</link>
            <guid>https://velog.io/@hyeonu_chun/2020-11-30-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-tt2mcfky</guid>
            <pubDate>Tue, 22 Jun 2021 09:15:03 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.12 Programming Project.6</p>
<ol>
<li><p>문제 기술
필자는 첫번째 파일과 두번째 파일의 내용이 합쳐진 세번째 파일을 만들기를 요한다.</p>
</li>
<li><p>설계 계획
사용자에게 각각의 파일의 이름을 입력 받아 3개의 파일을 생성하고, 첫번째와 두번째 파일에 원하는 입력을 받아 각각의 내용을 합쳐 세번째 파일에 출력한다.</p>
</li>
<li><p>데이터 처리 과정
사용자에게 각각의 파일의 이름을 입력 받아 저장한다. 입력 받은 파일의 이름에 .txt를 붙여 파일생성을 하고, 첫번째 파일과 두번째 파일에 각각 사용자가 원하는 내용을 입력한다. 이후, 첫번째와 두번째 파일의 내용을 string 형태로 읽어 들여 세번째 파일에 출력한다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;string&gt;
using namespace std;
</code></pre></li>
</ol>
<p>int main()
{
    string alpha = &quot;.txt&quot;;
    string firstWords, secondWords;</p>
<pre><code>string firstFileName, secondFileName, mergedFileName;
cout &lt;&lt; &quot;Please enter the first file name : &quot;;
cin &gt;&gt; firstFileName;
cout &lt;&lt; &quot;Please write the words : &quot;;
cin &gt;&gt; firstWords;
cout &lt;&lt; &quot;Please enter the second file name : &quot;;
cin &gt;&gt; secondFileName;
cout &lt;&lt; &quot;Please write the words : &quot;;
cin &gt;&gt; secondWords;
cout &lt;&lt; &quot;Please enter the merged file name : &quot;;
cin &gt;&gt; mergedFileName;

ofstream fin1(firstFileName + alpha);
fin1 &lt;&lt; firstWords &lt;&lt; endl;

ofstream fin2(secondFileName + alpha);
fin2 &lt;&lt; secondWords &lt;&lt; endl;

fin1.close();
fin2.close();

ifstream fin3(firstFileName + alpha);
ifstream fin4(secondFileName + alpha);
ofstream fout(mergedFileName + alpha);

string line;
fin3 &gt;&gt; line;
fout &lt;&lt; line;

fin4 &gt;&gt; line;
fout &lt;&lt; line;

fin3.close();
fin4.close();
fout.close();

return 0;</code></pre><p>} 
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[2020-11-30 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-11-30-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-11-30-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:13:31 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.11 Programming Project.4</p>
<ol>
<li><p>문제 기술
필자는 본문에 있는 관리자와 유저의 로그인 정보를 관리하는 시스템의 구현을 요한다.</p>
</li>
<li><p>설계 계획
본문에 따라 각각의 클래스를 만들어 해당하는 멤버함수를 구현하고, 유저와 관리자에 해당하는 아이디와 비밀번호를 입력하였을 때 작동하는 메인을 설계한다.</p>
</li>
<li><p>데이터 처리 과정
본문에 있는 Security헤더를 각각 User와 Administrator 헤더에 선언하여 Security.cpp에 선언한다. 이후 Security 클래스의 멤버함수에서 나온 리턴값에 따라 각각의 클래스의 Login 함수의 아규먼트로 입력하여 나온 결과값에 따라 로그인을 시킨다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>&lt;Security.h&gt;
</code></pre></li>
</ol>
<p>#pragma once
#include <iostream>
#include <string>
using namespace std;</p>
<p>class Security {
public:
    static int validate(string username, string password);
};</p>
<p>int Security::validate(string username, string password) {
    if ((username == &quot;abbott&quot;) &amp;&amp; (password == &quot;monday&quot;)) return 1;
    if ((username == &quot;costello&quot;) &amp;&amp; (password == &quot;tuesday&quot;)) return 2;
    return 0;
}</p>
<p>&lt;Administrator.h&gt;</p>
<p>#pragma once
#include &quot;Security.h&quot;</p>
<p>class Administrator {
public:
    bool Login(int num);
};</p>
<p>bool Administrator::Login(int num) {
    if (num == 2) return true;
    else return false;
}</p>
<p>&lt;User.h&gt;</p>
<p>#pragma once
#include &quot;Security.h&quot;</p>
<p>class User {
public:
    bool Login(int num);
};</p>
<p>bool User::Login(int num) {
    if (num == 1) return true;
    else return false;
}</p>
<p>&lt;Security.cpp&gt;</p>
<p>#include &quot;Administrator.h&quot;
#include &quot;User.h&quot;</p>
<p>int main() {
    Security a;
    Administrator b;
    User c;</p>
<pre><code>if (c.Login(a.validate(&quot;abbott&quot;, &quot;monday&quot;)) == 1) cout &lt;&lt; &quot;Good morning, user&quot; &lt;&lt; endl;
if (b.Login(a.validate(&quot;costello&quot;, &quot;tuesday&quot;)) == 1) cout &lt;&lt; &quot;Good morning, admin&quot; &lt;&lt; endl;
return 0;</code></pre><p>}</p>
<p>```
<img src="https://images.velog.io/images/hyeonu_chun/post/8fd09cb6-e391-4ba1-bc62-e1c1c03d1336/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[2020-11-24 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-11-24-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-11-24-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:12:08 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.10 Programming Project.4</p>
<ol>
<li><p>문제 기술
필자는 구독자의 구독리스트를 관리하는 프로그램의 구현을 요한다.</p>
</li>
<li><p>설계 계획
클래스를 선언하여 오버로딩 생성자에 의해 사용자의 이름을 최초로 입력 받는다. 이후 사용자는 메뉴에서 리스트를 추가할 수 있는데 이때, 동적 할당을 이용해 받은 데이터만큼 새로운 string 방을 추가한다. 동시에 개수를 계산하여 채널 개수에 입력한다. 사용자는 이름과 리스트를 추가 및 리셋 시킬 수 있다.</p>
</li>
<li><p>데이터 처리 과정
리스트를 생성 할 시 사용자로부터 이름을 입력 받고 해당 데이터를 임시변수에 저장한다. 기존에 리스트가 생성되어 있지 않다면 동적할당을 하여 새로운 리스트를 추가하고, 리스트가 생성되어 있다면 임시주솟값에 기존의 리스트주소를 저장하여 데이터를 보존하고 새롭게 동적할당을 하여 임시주솟값에 들어간 데이터와 새로운 데이터를 입력 받고 임시주솟값의 데이터를 해제한다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;stdlib.h&gt;
using namespace std;
</code></pre></li>
</ol>
<p>class Subscriber {
private:
    string name;
    int numChannels;
    string* channelList;
public:
    Subscriber();
    Subscriber(string);
    ~Subscriber();
    void setName();
    void setList();
    void getInfo();
    void reset();
};</p>
<p>Subscriber::Subscriber(){
    cout &lt;&lt; &quot;Please write your name: &quot;;
    cin &gt;&gt; this-&gt;name;
    this-&gt;numChannels = 0;
    this-&gt;channelList = NULL;
}</p>
<p>Subscriber::Subscriber(string name) {
    this-&gt;name = name;
    this-&gt;numChannels = 0;
    this-&gt;channelList = NULL;
}</p>
<p>Subscriber::~Subscriber() {
    delete[] this-&gt;channelList;
}</p>
<p>void Subscriber::setName(){
    cout &lt;&lt; &quot;Please write your name: &quot;;
    cin &gt;&gt; this-&gt;name;
}</p>
<p>void Subscriber::setList() {
    string channel;
    cout &lt;&lt; &quot;Mr(s). &quot; &lt;&lt; this-&gt;name &lt;&lt; &quot;, please write names of the channels. If you want to quit, press q.&quot; &lt;&lt; endl;
    while (true) {
        cin &gt;&gt; channel;
        if (channel == &quot;q&quot;) break;
        else {
            if (this-&gt;numChannels == 0) {
                this-&gt;channelList = new string[this-&gt;numChannels + 1];
            }
            else if (this-&gt;numChannels &gt; 0) {
                string* tmp = this-&gt;channelList;
                this-&gt;channelList = new string[this-&gt;numChannels + 1];
                for (int i = 0; i &lt; this-&gt;numChannels; i++) {
                    this-&gt;channelList[i] = tmp[i];
                }
                delete[] tmp;
            }
            this-&gt;channelList[this-&gt;numChannels] = channel;
            this-&gt;numChannels++;
        }
    }
}</p>
<p>void Subscriber::getInfo() {
    cout &lt;&lt; &quot;The list Mr(s). &quot; &lt;&lt; this-&gt;name &lt;&lt; &quot; subcribes :&quot; &lt;&lt; endl;
    if (this-&gt;numChannels == 0) cout &lt;&lt; &quot;Nothing in your list.&quot; &lt;&lt; endl;
    for (int i = 0; i &lt; this-&gt;numChannels; i++) cout &lt;&lt; channelList[i] &lt;&lt; endl;
    cout &lt;&lt; &quot;please press any button. &quot;;
    cin.get();
    cin.get();
}</p>
<p>void Subscriber::reset() {
    this-&gt;name = &quot;&quot;;
    this-&gt;numChannels = 0;
    delete[] this-&gt;channelList;
    this-&gt;channelList = NULL;
}</p>
<p>int main(){
    int num;
    Subscriber a;
    while (1) {
        cout &lt;&lt; &quot;1. Show your information / 2. Change your name / 3. Add your list / 4. Reset your information / 5. Quit\nPress the number: &quot;;
        cin &gt;&gt; num;
        switch (num) {
        case 1: {
            a.getInfo();
        } break;
        case 2: {
            a.setName();
        } break;
        case 3: {
            a.setList();
        } break;
        case 4: {
            a.reset();
        } break;
        case 5: return 0;
        default: cout &lt;&lt; &quot;Wrong number&quot; &lt;&lt; endl;
        }
        system(&quot;cls&quot;);
    }
}</p>
<pre><code>![](https://images.velog.io/images/hyeonu_chun/post/49d8bf00-5caa-40d7-b28a-c2f02b036ede/image.png)![](https://images.velog.io/images/hyeonu_chun/post/6e255c02-f5f3-4b17-89c7-efe9b6ddc447/image.png)![](https://images.velog.io/images/hyeonu_chun/post/df6342d7-e0e1-489e-85a8-0e725b5e705b/image.png)리스트를 구현하는 여러 방법이 있었지만 사용자가 얼마나 구독을 할지 모르는 상황에서 구독채널 개수의 한계를 없애기 위해서 링크드 리스트를 간략하게 나마 표현했다. Equal operator를 현 코드에는 구현하지 않았는데, c++에서 제공하는 오퍼레이터를 그대로 사용할 경우 얕은 복사가 되어 같은 주소를 가리키는 변수가 2개가 생기게 되어 원치 않은 데이터의 손실이 생길 수 있다. 따라서 새로운 동적할당을 하여 변수가 각각 다른 주솟값을 가리키게 하는 것이 바람직하다.</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-11-08 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-11-08-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-11-08-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:10:10 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.9 Programming Project.6</p>
<ol>
<li><p>문제 기술
필자는 음악리스트를 각 조건에 맞는 연산을 수행하여 정렬하기를 원한다.</p>
</li>
<li><p>설계 계획
각 조건에 맞게 설계하기 위해서 string 배열타입의 음악리스트를 변수로 입력한다. 조건에 맞게끔 변수를 조정하여 정렬하기 쉬운 형태로 변경하고, 이후 알고리즘 헤더의 sort함수를 이용해 정렬한다.</p>
</li>
<li><p>데이터 처리 과정
String 타입의 배열을 만들어 각각의 방에 음악 타이틀을 하나씩 넣어 변수로 입력한다. 사용자가 원하는 타이틀의 개수를 num이라는 변수에 저장해 타이틀을 추가해도 반자동적으로 타이틀의 개수를 체크한다. 우선적으로, 타이틀 앞의 무의미한 정보를 삭제하기 위해 ‘.’앞뒤의 글자를 제거한다. 타이틀 내의 타이틀과 뮤지션을 나뉘어 주는 대쉬 표시를 헷갈리게 하지 않기 위해 타이틀 내의 대쉬 표시를 공백으로 전환하고, 동시에 중복되는 공백표시를 제거해 하나의 공백으로 변경한다. 변경된 정보들을 가지고 제목정렬을 한 뒤 번호를 붙인다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
</code></pre></li>
</ol>
<p>using namespace std;</p>
<p>bool comp(string s1, string s2) {
    return s1 &lt; s2;
}</p>
<p>int main() {
    string line[] = {&quot;1. Adagio &quot;Moon&quot; - Ludwig Van Beethoven&quot;,&quot;15. Dutch  Warblet - no author   listed&quot;, &quot;123. Ba- Be- -  no author listed&quot;};
    const int num = sizeof(line) / sizeof(line[0]);
    for (int i = 0; i &lt; num; i++) cout &lt;&lt; line[i] &lt;&lt; endl;
    cout &lt;&lt; endl;</p>
<pre><code>for (int i = 0; i &lt; num; i++) {
    line[i].erase(0, line[i].find(&quot;.&quot;) + 2);
    bool a = false;
    int b = 0;
    for (int j = line[i].size() - 1; j &gt;= 0; j--) {
        if (line[i].at(j) == &#39;-&#39; &amp;&amp; !a) {
            a = true;
            b = j;
        }
        else if (line[i].at(j) == &#39;-&#39; &amp;&amp; a) {
            line[i].at(j) = &#39; &#39;;
        }
        if (j &lt;= line[i].size() - 2 &amp;&amp; j &gt;= 1) {
            if (line[i].at(j) == &#39; &#39;) {
                if (line[i].at(j - 1) == &#39; &#39; || line[i].at(j + 1) == &#39; &#39;) line[i].erase(j, 1);
            }
        }
    }
}
sort(line, line + num, comp);
for (int i = 0; i &lt; num; i++) cout &lt;&lt; i + 1 &lt;&lt; &quot;. &quot; &lt;&lt; line[i] &lt;&lt; endl;</code></pre><p>}</p>
<pre><code> ![](https://images.velog.io/images/hyeonu_chun/post/f3b9acc8-307b-4f76-9c3f-787dfa60ae2b/image.png)                 
 조건에서 이해 가능한 조건을 우선적으로 실행하여 구현하였다. 제목정렬이 아닌 가수정렬로 바꿀 시 rfind 함수를 이용해 대쉬 표기를 찾아 가수와 제목의 위치를 바꾸고 sort 함수를 이용해 정렬하면 가수정렬도 가능하지만, 조건들에 있는 첫번째/두번째 이니셜과 이름의 위치 바꾸는 로직을 이해하지 못해 구현하지 않았다. </code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-10-22 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-10-22-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-10-22-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:08:15 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.8 Programming Project. 4</p>
<ol>
<li><p>문제 기술
필자는 본문의 8.7을 응용하여 멤버변수의 교체와 그에 따른 멤버함수들을 변환 및 생성자 추가를 요한다.</p>
</li>
<li><p>설계 계획
기본적인 틀은 다 설계가 되어있기에 문제에서 요구하듯, 기존 멤버변수를 삭제 시키고 배열과 사용중인 배열의 방의 사이즈를 나타내는 정수값을 변수로 둔다. 멤버변수를 초기화 시키는 디폴트 생성자, 오버로디드 생성자를 만들고 변수들이 변함에 따라 기존에 오버로딩 된 연산자의 정의를 바꾼다.</p>
</li>
<li><p>데이터 처리 과정
CharPair type의 a, b, c를 생성하게 되면 arguments에 따라 각각 디폴트 생성자, 오버로디드 생성자들이 호출되어 객체 생성을 완료한다. 객체 생성이 정상적으로 완료되었는지 확인하기 위해 각 객체마다 멤버변수를 확인할 수 있는 멤버함수를 불러 클래스 내부의 멤버변수를 간접적으로 확인한다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
using namespace std;
</code></pre></li>
</ol>
<p>class CharPair {
public:
    CharPair();
    CharPair(int sz);
    CharPair(int sz, char array[]);
    char&amp; operator[](int index);
    int returnSize() { return size; }</p>
<p>private:
    char array[100];
    int size;
};</p>
<p>CharPair::CharPair() {
    size = 10;
    for (int i = 0; i &lt; 100; i++) this-&gt;array[i] = &#39;#&#39;;
}</p>
<p>CharPair::CharPair(int sz) : size(sz) {
    for (int i = 0; i &lt; 100; i++) this-&gt;array[i] = &#39;#&#39;;
}</p>
<p>CharPair::CharPair(int sz, char array[]) : size(sz) {
    for (int i = 0; i &lt; 100; i++) this-&gt;array[i] = array[i];
}</p>
<p>char&amp; CharPair::operator[](int index) {
    int num = 0;
    for (int i = 0; i &lt; this-&gt;size; i++) {
        if (index == i) {
            num = 1;
            return this-&gt;array[i];
        }
    }
    if (num == 0) {
        cout &lt;&lt; &quot;Illegal index value. \n&quot;;
        exit(1);
    }
}</p>
<p>int main() {
    char array[] = { &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39; ,&#39;e&#39; };
    CharPair a;
    CharPair b(1);
    CharPair c(5, array);</p>
<pre><code>cout &lt;&lt; &quot;1. Size of a = &quot; &lt;&lt; a.returnSize() &lt;&lt; &quot;, a[2] = &quot; &lt;&lt; a[2] &lt;&lt; endl;

cout &lt;&lt; &quot;2. Size of b = &quot; &lt;&lt; b.returnSize() &lt;&lt; &quot;, b[0] = &quot; &lt;&lt; b[0] &lt;&lt; endl;

cout &lt;&lt; &quot;3. Size of c = &quot; &lt;&lt; c.returnSize() &lt;&lt; &quot;, c[4] = &quot; &lt;&lt; c[4] &lt;&lt; endl;

return 0;</code></pre><p>}</p>
<pre><code>![](https://images.velog.io/images/hyeonu_chun/post/05361920-a55a-401e-bf4c-fe2451f44cba/image.png)
기존 Display 8.7의 코드에 멤버 변수의 변화에 따라 작성된 코드이다. 오버로딩 연산자에서 기존코드에선 단순하게 배열을 흉내 냈을 뿐이지만 이번 과제에선 직간접적으로 배열을 이용해 원하는 배열의 방을 뽑아내야 함과 동시에 예외처리를 해야 했다. 콘솔창에서 입력 받는 변수가 없어 단순변수를 이용해 예외처리를 진행하였다.</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-10-16 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-10-16-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-10-16-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:06:36 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.8 Programming Project. 3</p>
<ol>
<li><p>문제 기술
필자는 복소수의 기초연산을 할 수 있는 프로그램의 설계를 요한다.</p>
</li>
<li><p>설계 계획
클래스 내부에 문제에서 요하는 데이터 멤버와 멤버 함수를 작성하고 연산자 오버로딩을 통해 클래스와 클래스의 연산을 가능하게 만든다. 입출력의 형태도 오버로딩을 통해 형태에 따라 입력되고 출력되게 만든다.</p>
</li>
<li><p>데이터 처리 과정
먼저 Complex class type의 (a, b), (c, d)를 파라메타로 가지는 객체를 생성한다. 이라는 객체를 생성한다. 따라서 Complex class의 오버로디드 생성자가 호출되어 데이터 멤버를 파라메타에 해당하는 객체 생성을 완료한다. 기존 main 함수에 입력되어 있는 연산문에 따라 Complex x와 y는 오버로디드 된 연산자 *를 호출하여 복소수의 곱셈연산을 수행하게 된다. 이후 출력 연산자를 호출하여 사용자가 원하는 출력의 형태로 출력하여 곱셈연산을 대조 비교한다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;
</code></pre></li>
</ol>
<p>class Complex {
private:
    double real;
    double imaginary;
public:
    Complex(double real = 0, double imaginary = 0);
    Complex(double realpart);
    ~Complex() {}
    Complex operator+(const Complex &amp;a) const;
    Complex operator-(const Complex &amp;a) const;
    Complex operator-() const;
    Complex operator*(const Complex &amp;a) const;
    Complex operator/ (const Complex &amp; a) const;
    bool operator==(const Complex&amp; a);
    bool operator!=(const Complex&amp; a);
    friend ostream &amp;operator&lt;&lt;(ostream &amp;os, Complex &amp;a);
    friend istream &amp;operator&gt;&gt;(istream &amp;is, Complex &amp;a);
    double displayReal() { return real; }
    double displayImaginary() { return imaginary; }
};</p>
<p>Complex::Complex(double real, double imaginary) {
    this-&gt;real = real;
    this-&gt;imaginary = imaginary;
}</p>
<p>Complex::Complex(double realpart) {
    this-&gt;real = realpart;
    this-&gt;imaginary = 0;
}</p>
<p>ostream &amp;operator&lt;&lt;(ostream &amp;os, Complex &amp;a) {
    if (a.real != 0) os &lt;&lt; a.real;
    if (a.imaginary != 0) {
        cout.setf(ios::showpos);
        os &lt;&lt; a.imaginary &lt;&lt; &quot;i&quot;;
        cout.unsetf(ios::showpos);
    }
    if (a.real == 0 &amp;&amp; a.imaginary == 0) os &lt;&lt; 0;
    return os;
}</p>
<p>istream &amp;operator&gt;&gt;(istream &amp;is, Complex &amp;a) {
    is &gt;&gt; a.real &gt;&gt; a.imaginary;
    return is;
}</p>
<p>Complex Complex::operator+(const Complex&amp; a) const {
    Complex temp(this-&gt;real + a.real, this-&gt;imaginary + a.imaginary);
    return temp;
}</p>
<p>Complex Complex::operator-(const Complex&amp; a) const {
    Complex temp(this-&gt;real - a.real, this-&gt;imaginary - a.imaginary);
    return temp;
}</p>
<p>Complex Complex::operator-() const {
    Complex temp(-this-&gt;real, -this-&gt;imaginary);
    return temp;
}</p>
<p>Complex Complex::operator*(const Complex&amp; a) const {
    double x, y;
    x = this-&gt;real * a.real - this-&gt;imaginary * a.imaginary;
    y = this-&gt;real * a.imaginary + this-&gt;imaginary * a.real;
    Complex temp(x, y);
    return temp;
}</p>
<p>Complex Complex::operator/ (const Complex&amp; a) const {
    double x, y, z;
    z = a.real * a.real + a.imaginary * a.imaginary;
    x = (this-&gt;real * a.real + this-&gt;imaginary * a.imaginary) / z;
    y = (this-&gt;imaginary * a.real + this-&gt;real * a.imaginary) / z;
    Complex temp(x, y);
    return temp;
}</p>
<p>bool Complex::operator==(const Complex&amp; a) {
    if (this-&gt;real == a.real &amp;&amp; this-&gt;imaginary == a.imaginary) {
        return true;
    }
    else return false;
}</p>
<p>bool Complex::operator!=(const Complex&amp; a) {
    if (this-&gt;real != a.real &amp;&amp; this-&gt;imaginary != a.imaginary) {
        return true;
    }
    else return false;
}</p>
<p>int main() {
    double a, b, c, d;
    cout &lt;&lt; &quot;Please enter four values to calculate : &quot;;
    cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
    Complex x(a,b), y(c,d);
    const Complex i(0, 1);</p>
<pre><code>Complex z = x * y;

cout &lt;&lt; x &lt;&lt; &quot; * &quot; &lt;&lt; y &lt;&lt; &quot; = &quot; &lt;&lt; z &lt;&lt; &quot; (=(&quot; &lt;&lt; a &lt;&lt; &quot;*&quot; &lt;&lt; c &lt;&lt; &quot; - &quot; &lt;&lt; b &lt;&lt; &quot;*&quot; &lt;&lt; d &lt;&lt; &quot;) + (&quot; &lt;&lt; a &lt;&lt; &quot;*&quot; &lt;&lt; d &lt;&lt; &quot; + &quot; &lt;&lt; b &lt;&lt; &quot;*&quot; &lt;&lt; c &lt;&lt; &quot;))&quot; &lt;&lt;endl;</code></pre><p>}</p>
<pre><code>![](https://images.velog.io/images/hyeonu_chun/post/d9387182-510b-4e44-a8f5-8957fbace9bb/image.png)
문제가 요한대로 각 객체를 생성하여 곱셈 뿐만 아니라 다양한 형태의 연산을 시도하였을 때 정상적으로 작동하였다. 복소수 i와의 연산에서도 문제가 없었지만 오버로디드 연산자를 사용하여 객체 3개 이상의 연산을 할 시 문제가 발생 되었다. 입출력 연산의 경우 함수 호출 과정을 줄이기 위해 Friend 함수로 입력했지만 이 점은 피드백 과정 이후에 개선한 것으로 기존 연산자 함수들은 유지하였는데, 나머지 연산자 함수들도 개선을 통해 3개 이상의 피연산 계산이 가능하도록 해야 한다는 것을 인지하였다.
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-10-08 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-10-08-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-10-08-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Tue, 22 Jun 2021 09:04:41 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.7 Programming Project. 3</p>
<ol>
<li><p>문제 기술
필자는 일정 금액 이하의 각 자릿수 덧셈 연산만 하는 덧셈기의 구현을 요한다. 뿐만 아니라 일정 금액 초과 시 경고를 띄워 사용자에게 인지시키고 리셋이 가능하다.</p>
</li>
<li><p>설계 계획
클래스 내부에 문제에서 요하는 데이터 멤버와 멤버 함수를 작성하고 금액의 합을 보여주는 멤버 함수를 추가한다. 생성자는 모두를 0으로 초기화하게 디폴트 생성자로 작성하고, 각 자리수의 덧셈 멤버 함수는 10을 초과할 시 해당 자릿수를 0으로 초기화하고 다음 자릿수를 하나 증가시키며 1000의 자리가 넘어갈 경우 오버플로우를 경고한다. 프로그램을 종료하지 않는 이상 리셋을 통해 덧셈기를 사용 가능하며 asdfor(ASDFOR)을 제외한 입력이나 1~9를 제외한 입력은 일체 예외 처리한다. </p>
</li>
<li><p>데이터 처리 과정
먼저 Counter class type의 Counter이라는 객체를 생성한다. 따라서 Counter class의 디폴트 생성자가 호출되어 데이터 멤버를 초기화 시키고, 객체 생성을 완료한다. (이전의 입력을 고려해) 콘솔창을 리셋시키고 오버플로우를 검사한다. 덧셈기에 해당하는 기능을 나타내는 디스플레이를 출력하고, 사용자에게 해당 기능에 맞는 문자를 입력 받으면 기능을 수행한다. 자릿수 덧셈 시 추가로 숫자를 입력 받아 입력 받은 횟수만큼 해당 자릿수를 1씩 증가시킨다. 덧셈, 리셋 등의 기능을 수행한 뒤 무한루프문에 의해 기능은 0.5초의 딜레이를 가지고 다시금 수행 가능하게 되며 Q(q)를 입력 시 프로그램이 종료된다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;windows.h&gt;
using namespace std;
</code></pre></li>
</ol>
<p>class Counter {
private:
    bool overflowflag;
    int units;
    int tens;
    int hundreds;
    int thousands;</p>
<p>public:
    Counter() :units(0), tens(0), hundreds(0), thousands(0), overflowflag(false) {}
    ~Counter() {}</p>
<pre><code>bool overflow();

void reset();

void incr1();
void incr10();
void incr100();
void incr1000();

void displayMoney();</code></pre><p>};</p>
<p>void Counter::reset() {
    this-&gt;overflowflag = false;
    this-&gt;units = this-&gt;tens = this-&gt;hundreds = this-&gt;thousands = 0;
}</p>
<p>void Counter::displayMoney() {
    cout &lt;&lt; &quot;Total : $&quot; &lt;&lt; this-&gt;thousands &lt;&lt; this-&gt;hundreds &lt;&lt; &quot;.&quot; &lt;&lt; this-&gt;tens &lt;&lt; this-&gt;units &lt;&lt; endl;
}</p>
<p>bool Counter::overflow() {
    return this-&gt;overflowflag;
}</p>
<p>void Counter::incr1000() {
    if (this-&gt;thousands &lt; 9) this-&gt;thousands++;
    else {
        this-&gt;thousands = 0;
        this-&gt;overflowflag = true;
    }
}</p>
<p>void Counter::incr100() {
    if (this-&gt;hundreds &lt; 9) this-&gt;hundreds++;
    else {
        this-&gt;hundreds = 0;
        this-&gt;incr1000();
    }
}</p>
<p>void Counter::incr10() {
    if (this-&gt;tens &lt; 9) this-&gt;tens++;
    else {
        this-&gt;tens = 0;
        this-&gt;incr100();
    }
}</p>
<p>void Counter::incr1() {
    if (this-&gt;units &lt; 9) this-&gt;units++;
    else {
        this-&gt;units = 0;
        this-&gt;incr10();
    }
}</p>
<p>int inputDigit();</p>
<p>int main() {
    int i;
    int digit;
    char key;
    Counter Counter;</p>
<pre><code>while (true) {
    system(&quot;cls&quot;);
    if (Counter.overflow() == true) cout &lt;&lt; &quot;WARNING : Overflow has happened. Press r to reset.&quot; &lt;&lt; endl;
    Counter.displayMoney();
    cout &lt;&lt; &quot;a - units\ns - tens\nd - hundreds\nf - thousands\no - check overflow\nr - reset\nQ - quit\nEnter a character : &quot;;
    cin &gt;&gt; key;

    while(cin.get() != &#39;\n&#39;) {
        key = 0;
    }

    switch (key) {
    case &#39;A&#39;:
    case &#39;a&#39;: {
        digit = inputDigit();
        for (i = 0; i &lt; digit; i++) {
            Counter.incr1();
        }
    } break;
    case &#39;S&#39;:
    case &#39;s&#39;: {
        digit = inputDigit();
        for (i = 0; i &lt; digit; i++) {
            Counter.incr10();
        }
    } break;
    case &#39;D&#39;:
    case &#39;d&#39;: {
        digit = inputDigit();
        for (i = 0; i &lt; digit; i++) {
            Counter.incr100();
        }
    } break;
    case &#39;F&#39;:
    case &#39;f&#39;: {
        digit = inputDigit();
        for (i = 0; i &lt; digit; i++) {
            Counter.incr1000();
        }
    } break;
    case &#39;O&#39;:
    case &#39;o&#39;: {
        if (Counter.overflow() == true) {
            cout &lt;&lt; &quot;WARNING : Overflow has happened. Press r to reset.&quot; &lt;&lt; endl;
        }
        else cout &lt;&lt; &quot;Overflow has not happended.&quot; &lt;&lt; endl;
    } break;
    case &#39;R&#39;:
    case &#39;r&#39;: {
        cout &lt;&lt; &quot;Resetting...&quot; &lt;&lt; endl;
        Counter.reset();
    } break;
    case &#39;Q&#39;:
    case &#39;q&#39;: {
        cout &lt;&lt; &quot;Quitting...&quot; &lt;&lt; endl;;
        return 0;
    }
    default: {
        cout &lt;&lt; &quot;Please enter a CORRECT character.&quot; &lt;&lt; endl;
        break;
    }
    }
    Sleep(500);
}</code></pre><p>}</p>
<p>int inputDigit() {
    int digit;
    cout &lt;&lt; &quot;Enter a digit between 1 and 9 : &quot;;
    cin &gt;&gt; digit;
    if (cin.get() != &#39;\n&#39;) {
        cout &lt;&lt; &quot;Please enter a CORRECT number.&quot; &lt;&lt; endl;
        cin.clear();
        while (cin.get() != &#39;\n&#39;) {}
        return 0;
    }
    if (cin.fail() == true) {
        cout &lt;&lt; &quot;Please enter a CORRECT number.&quot; &lt;&lt; endl;
        cin.clear();
        while (cin.get() != &#39;\n&#39;) {}
        return 0;
    }
    if (0 &gt; digit || digit &gt; 9) {
        cout &lt;&lt; &quot;Please enter a CORRECT number.&quot; &lt;&lt; endl;
        return 0;
    }
    else return digit;
}</p>
<pre><code>![](https://images.velog.io/images/hyeonu_chun/post/1f76b7fb-c423-4afc-8cae-0924c6fabd09/image.png)
덧셈기의 원리에 따라 각 자릿수에 해당하는 숫자를 받고 더해서 오버플로우가 발생하면 경고하고 리셋을 권하는 형태의 결과물이 완성되었다. 기능적인 측면에서 오버플로우가 발생할 시 어떤 기능을 입력하던 경고문이 지속되어 ‘o’ 기능의 필요성을 느끼지는 못했다(독해를 잘못했을 가능성이 크다). 기존 과제에서 예외처리를 시행하지 않았었지만, 이번 과제의 경우 연속적인 입력의 경우 하나라도 잘못된 입력이 들어가면 무한루프에 빠지거나 원치 않은 기능을 수행하게 되어 최대한 노력을 해보았지만 깔끔하게 처리하지 못했다는 문제가 있다.</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-10-03 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-10-03-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-o1e72ata</link>
            <guid>https://velog.io/@hyeonu_chun/2020-10-03-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-o1e72ata</guid>
            <pubDate>Tue, 22 Jun 2021 09:02:50 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.6 Programming Project. 2</p>
<ol>
<li><p>문제 기술
필자는 반지름을 오브젝트로 갖고 이 반지름을 제어하고 이를 통해 원의 넓이, 지름, 원주 그리고 반지름을 보여주는 함수들을 가진 클래스의 구현을 요한다.</p>
</li>
<li><p>설계 계획
클래스 외에서 직접적으로 제어할 수 없는 데이터 멤버를 지정하고, 디폴트 생성자를 수동생성한다. 변수를 간접적으로 제어하기 위해 문제에서 요하는 각각의 기능을 가진 SetRadius, Calculate, ReturnRadius 함수를 만든다. 각각의 함수를 정의하고 메인함수 내에서 원하는 반지름을 double 형으로 받으면 그에 따라 반지름을 세팅하고 원의 넓이, 지름 그리고 원주를 계산하여 보여준다. 마지막으로 입력 받은 반지름을 보여준다.</p>
</li>
<li><p>데이터 처리 과정
먼저 Circle class type의 Circle이라는 데이터 멤버를 선언한다. 따라서 Circle class의 디폴트 생성자가 호출되어 데이터 멤버를 초기화 시키고, 객체 생성을 완료한다. 다음으로 원하는 반지름을 입력 받기 위해 r이라는 변수를 선언하고, 입출력 함수를 통해 반지름을 입력 받는다. 클래스를 테스트하기 위해 입력 받은 반지름을 멤버 함수를 통해 전달하여 입력한다. 전달받은 반지름으로 원의 넓이, 지름 그리고 원주를 계산하고 출력한다. 입력 받은 반지름 값이 데이터 멤버에 입력되었는지 확인하는 리턴함수를 통해 출력한다. 마지막으로 소멸자를 통해 객체 소멸을 완료시킨다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;math.h&gt;
#define PI 3.14
using namespace std;
</code></pre></li>
</ol>
<p>class Circle {
private:
    double radius;
public:
    Circle();
    ~Circle() { /* cout &lt;&lt; &quot;Call Destructor...&quot; &lt;&lt; endl; */ }
    void SetRadius(double r);
    void Calculate();
    double ReturnRadius();
};</p>
<p>Circle::Circle() {
    this-&gt;radius = 0;
    /* cout &lt;&lt; &quot;Call Constructor...&quot; &lt;&lt; end/; */
}</p>
<p>void Circle::SetRadius(double r) {
    this-&gt;radius = r;
}</p>
<p>void Circle::Calculate() {
    cout &lt;&lt; &quot;The area of the circle is &quot; &lt;&lt; fixed &lt;&lt; 2 * PI * pow(this-&gt;radius, 2) &lt;&lt; endl;
    cout &lt;&lt; &quot;The diameter of the circle is &quot; &lt;&lt; 2 * this-&gt;radius  &lt;&lt; endl;
    cout &lt;&lt; &quot;The circumference of the circle is &quot; &lt;&lt; 2 * PI * this-&gt;radius &lt;&lt; endl;
}</p>
<p>double Circle::ReturnRadius() {
    return this-&gt;radius;
}</p>
<p>int main() {
    Circle Circle;
    double r;</p>
<pre><code>cout &lt;&lt; &quot;Please enter the radius you want to change. &quot;;
cin &gt;&gt; r;

Circle.SetRadius(r);
Circle.Calculate();

cout &lt;&lt; &quot;The radius of the circle is &quot; &lt;&lt; Circle.ReturnRadius() &lt;&lt; endl;</code></pre><p>}</p>
<pre><code>![](https://images.velog.io/images/hyeonu_chun/post/99e2be5e-33e0-4f9f-84aa-b08e50f550f8/image.png)
금일 날짜를 반지름으로써 입력하여 원의 넓이, 지름, 원주 그리고 반지름을 정상적으로 출력한다. 강제형변환 횟수를 줄이기 위해 데이터를 double 형으로 입력 받아 제곱 함수의 데이터 리턴값과의 계산에도 문제가 생기지 않았다. 본 클래스에는 This 포인터를 쓸 이유는 없었지만 개인적으로 쓰는 것이 입출력 되는 데이터들의 구분이 되어 사용하였다. 생성자의 개념이 미숙하여 생성자와 소멸자의 수행 위치를 확인하기 위한 테스트를 진행하였다.</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2020-09-22 고급프로그래밍]]></title>
            <link>https://velog.io/@hyeonu_chun/2020-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</link>
            <guid>https://velog.io/@hyeonu_chun/2020-%EA%B3%A0%EA%B8%89%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D</guid>
            <pubDate>Mon, 21 Jun 2021 04:55:46 GMT</pubDate>
            <description><![CDATA[<p>Absolute C++ 6th ed./Savitch Chap.5 Programming Project. 2</p>
<ol>
<li><p>문제 기술</p>
<p>필자는 메인 함수 내의 배열 데이터에서 중복되는 데이터를 삭제하여 나열하고, 동시에 의도적으로 사용되는 배열 내의 데이터 수를 계산하는 함수의 구현을 요한다.</p>
</li>
<li><p>설계 계획</p>
<p>함수를 구현하기 위해서 배열내의 각각의 데이터가 중복되지 않아야 한다. 첫번째 배열이 자신을 제외한 나머지 배열을 확인하며 같은 데이터가 있을 경우, 그 데이터의 뒤에서부터 배열을 한 칸 씩 앞으로 이동시킨다. 이와 동시에 Garbage 데이터로 인한 혼동을 막기 위해 마지막 번째 배열은 널문자로 초기화 시킨다. 마찬가지로 두번째 데이터 또한 첫번째 데이터와 자신을 제외한 나머지 데이터와 비교하며 중복되는 데이터를 삭제 및 이동시킨다. 같은 방법으로 함수에 입력 받는 사이즈 값에 따라 동작을 수행한다.</p>
</li>
<li><p>데이터 처리 과정</p>
<p>문제에 따라 deleteRepeats 함수는 입력 받는 데이터는 Character type의 배열과 배열내의 의도적으로 사용되는 배열의 개수이다. 즉, 매개변수들은 각각 Character pointer type과 int의 참조형이다. 입력 받은 배열은 함수 정의부에 따라 3중 For문에 의해 데이터를 비교, 삭제 및 이동시키고 정수 값에 중복되지 않은 데이터의 개수를 입력시킨다. 이후 deleteRepeats 함수에 의해 중복되지 않은 데이터와 개수가 출력되게 된다.</p>
</li>
<li><p>실행 결과 및 분석</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;
</code></pre></li>
</ol>
<p>void deleteRepeats(char *, int &amp;);</p>
<p>int main() {
    char a[10];
    a[0] = &#39;c&#39;;
    a[1] = &#39;a&#39;;
    a[2] = &#39;c&#39;;
    a[3] = &#39;a&#39;;
    int size = 4;
    deleteRepeats(a, size);
}</p>
<p>void deleteRepeats(char *ch, int &amp;size) {</p>
<pre><code>for (int i = 0; i &lt; size; i++) {
    for (int j = i + 1; j &lt; size; j++) {
        if (ch[i] == ch[j]) {
            for (int k = j + 1; k &lt; size; k++) {
                ch[k - 1] = ch[k];
            }
            size--;
            ch[size] = NULL;
            j--;
        }
    }
}
cout &lt;&lt; ch[0] &lt;&lt; ch[1] &lt;&lt; ch[2] &lt;&lt; ch[3] &lt;&lt; size &lt;&lt; endl;</code></pre><p>}</p>
<p>```
5. 소감 및 피드백</p>
<p>메인에서 입력되는 데이터에 따라 구동하는 함수이다. 결과적으로 3중 For문을 이용해 비교하며 데이터 삭제 및 이동을 위해 데이터를 하나하나 앞으로 옮기는 행위는 적은 데이터에서는 상관이 없으나 중복 횟수가 많고 배열의 길이가 길어질 시 연산의 횟수를 끊임없이 늘리는데 동조할 것이다. 동적 메모리 할당에 관해 공부하여 더욱 깔끔한 코드를 작성해야 함을 다시 끔 느꼈다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[2017 수색대대 전자식신호기 아두이노 프로젝트]]></title>
            <link>https://velog.io/@hyeonu_chun/2017-%EC%88%98%EC%83%89%EB%8C%80%EB%8C%80-%EC%A0%84%EC%9E%90%EC%8B%9D%EC%8B%A0%ED%98%B8%EA%B8%B0-%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</link>
            <guid>https://velog.io/@hyeonu_chun/2017-%EC%88%98%EC%83%89%EB%8C%80%EB%8C%80-%EC%A0%84%EC%9E%90%EC%8B%9D%EC%8B%A0%ED%98%B8%EA%B8%B0-%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</guid>
            <pubDate>Mon, 21 Jun 2021 04:48:02 GMT</pubDate>
            <description><![CDATA[<h1 id="master-part-code">Master part code</h1>
<pre><code>#include &lt;SoftwareSerial.h&gt;
#include &lt;Adafruit_NeoPixel.h&gt;

SoftwareSerial mySerial(2, 3); // RX, TX
int BUTTON1 = 4;
int BUTTON2 = 5;
int BUTTON3 = 6;
int pot = A0;
int btnstate1;
int prevstate1 = 1;
int btnstate2;
int prevstate2 = 1;
int btnstate3;
int prevstate3 = 1;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int lednum1 = 0;
int lednum2 = 0;
int lednum3 = 0;
int lednum4 = 0;
int lednum5 = 0;
int lednum6 = 0;
#define PIN 7
#define LEDNUM 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  mySerial.begin(4800);
  int reading = analogRead(pot);
  int b = map(reading,0,1024,1,150);
    strip.begin();    
  strip.setPixelColor(0, b, 0, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(1, b, b, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(2, 0, b, 0);
  strip.show();     
  delay(400);
  int k = 0;
  while(k &lt; 4)
  {
    strip.setPixelColor(0, b, 0, 0);
    strip.setPixelColor(1, b, b, 0);
    strip.setPixelColor(2, 0, b, 0);
    strip.show();
    delay(200);
  strip.setPixelColor(0, 0, 0, 0);
  strip.setPixelColor(1, 0, 0, 0);
  strip.setPixelColor(2, 0, 0, 0);
  strip.show();
  delay(200);
  k++;
  }
}

void loop() {
  int reading = analogRead(pot);
int b = map(reading,0,1024,1,150);

  if (Serial.available()) {
    char c = (char)Serial.read();
   if (c == &#39;m&#39;){
         mySerial.print(&quot;m&quot;);
  strip.setPixelColor(2, b, 0, 0);
    strip.show();
  }
   if (c == &#39;n&#39;){
         mySerial.print(&quot;n&quot;);
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;o&#39;){
         mySerial.print(&quot;o&quot;);
  strip.setPixelColor(2, b, b, 0);
    strip.show();
  }
   if (c == &#39;p&#39;){
         mySerial.print(&quot;p&quot;);
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;q&#39;){
         mySerial.print(&quot;q&quot;);
  strip.setPixelColor(2, 0, b, 0);
    strip.show();
  }
   if (c == &#39;r&#39;){
         mySerial.print(&quot;r&quot;);
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
  }

    if (mySerial.available()) {
    char c = (char)mySerial.read();
   if (c == &#39;g&#39;){
        Serial.print(&quot;g&quot;);
  strip.setPixelColor(0, b, 0, 0);
    strip.show();
  }
   if (c == &#39;h&#39;){
        Serial.print(&quot;h&quot;);
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;i&#39;){
        Serial.print(&quot;i&quot;);
  strip.setPixelColor(0, b, b, 0);
    strip.show();
  }
   if (c == &#39;j&#39;){
        Serial.print(&quot;j&quot;);
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;k&#39;){
        Serial.print(&quot;k&quot;);
  strip.setPixelColor(0, 0, b, 0);
    strip.show();
  }
   if (c == &#39;l&#39;){
        Serial.print(&quot;l&quot;);
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
  }


    btnstate1 = digitalRead(BUTTON1);
if(btnstate1 != prevstate1){
  if(btnstate1 ==1){
    if(num1 == 0){
      mySerial.print(&quot;a&quot;);
    Serial.print(&quot;a&quot;);
  strip.setPixelColor(1, b, 0, 0);
    strip.show();
        num1 ++;
  }
  else {
    mySerial.print(&quot;b&quot;);    
    Serial.print(&quot;b&quot;);
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
        num1 = 0;
  }
  }
  prevstate1 = btnstate1;
}

    btnstate2 = digitalRead(BUTTON2);
if(btnstate2 != prevstate2){
  if(btnstate2 ==1){
    if(num2 == 0){
      mySerial.print(&quot;c&quot;);
    Serial.print(&quot;c&quot;);
  strip.setPixelColor(1, b, b, 0);
    strip.show();
        num2 ++;
  }
  else {    
    mySerial.print(&quot;d&quot;);
    Serial.print(&quot;d&quot;);
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
        num2 = 0;
  }
  }
  prevstate2 = btnstate2;
}

btnstate3 = digitalRead(BUTTON3);
if(btnstate3 != prevstate3){
  if(btnstate3 ==1){
    if(num3 == 0){
      mySerial.print(&quot;e&quot;);
    Serial.print(&quot;e&quot;);
  strip.setPixelColor(1, 0, b, 0);
    strip.show();
        num3 ++;
  }
  else {    
    mySerial.print(&quot;f&quot;);
    Serial.print(&quot;f&quot;);
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
        num3 = 0;
  }
  }
  prevstate3 = btnstate3;
}
delay(10);
}</code></pre><h1 id="slave-part-code-hardwareserial">Slave part code (HardwareSerial)</h1>
<pre><code>#include &lt;Adafruit_NeoPixel.h&gt;

int BUTTON1 = 4;
int BUTTON2 = 5;
int BUTTON3 = 6;
int pot = A0;
int btnstate1;
int prevstate1 = 1;
int btnstate2;
int prevstate2 = 1;
int btnstate3;
int prevstate3 = 1;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int lednum1 = 0;
int lednum2 = 0;
int lednum3 = 0;
int lednum4 = 0;
int lednum5 = 0;
int lednum6 = 0;

#define PIN 7
#define LEDNUM 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  strip.begin();                           // 네오픽셀 제어시작
  strip.show();                            // 네오픽셀 초기화
  int reading = analogRead(pot);
  int b = map(reading,0,1024,1,150);
    strip.begin();    
  strip.setPixelColor(0, b, 0, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(1, b, b, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(2, 0, b, 0);
  strip.show();     
  delay(400);
  int k = 0;
  while(k &lt; 4)
  {
    strip.setPixelColor(0, b, 0, 0);
    strip.setPixelColor(1, b, b, 0);
    strip.setPixelColor(2, 0, b, 0);
    strip.show();
    delay(200);
  strip.setPixelColor(0, 0, 0, 0);
  strip.setPixelColor(1, 0, 0, 0);
  strip.setPixelColor(2, 0, 0, 0);
  strip.show();
  delay(200);
  k++;
  }
}

void loop() {
int reading = analogRead(pot);
int b = map(reading,0,1024,1,150);

  if (Serial.available()) {
    char c = (char)Serial.read();
   if (c == &#39;a&#39;){
  strip.setPixelColor(1, b, 0, 0);
    strip.show();
  }
   if (c == &#39;b&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;c&#39;){
  strip.setPixelColor(1, b, b, 0);
    strip.show();
  }
   if (c == &#39;d&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;e&#39;){
  strip.setPixelColor(1, 0, b, 0);
    strip.show();
  }
   if (c == &#39;f&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;g&#39;){
  strip.setPixelColor(0, b, 0, 0);
    strip.show();
  }
   if (c == &#39;h&#39;){
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;i&#39;){
  strip.setPixelColor(0, b, b, 0);
    strip.show();
  }
   if (c == &#39;j&#39;){
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;k&#39;){
  strip.setPixelColor(0, 0, b, 0);
    strip.show();
  }
   if (c == &#39;l&#39;){
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
  }
  }



    btnstate1 = digitalRead(BUTTON1);
if(btnstate1 != prevstate1){
  if(btnstate1 ==1){
    if(num1 == 0){
      Serial.print(&quot;m&quot;);
  strip.setPixelColor(2, b, 0, 0);
    strip.show();
        num1 ++;
  }
  else {
    Serial.print(&quot;n&quot;);    
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
        num1 = 0;
  }
  }
  prevstate1 = btnstate1;
}

    btnstate2 = digitalRead(BUTTON2);
if(btnstate2 != prevstate2){
  if(btnstate2 ==1){
    if(num2 == 0){
      Serial.print(&quot;o&quot;);
  strip.setPixelColor(2, b, b, 0);
    strip.show();
        num2 ++;
  }
  else {    
    Serial.print(&quot;p&quot;);
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
        num2 = 0;
  }
  }
  prevstate2 = btnstate2;
}

btnstate3 = digitalRead(BUTTON3);
if(btnstate3 != prevstate3){
  if(btnstate3 ==1){
    if(num3 == 0){
      Serial.print(&quot;q&quot;);
  strip.setPixelColor(2, 0, b, 0);
    strip.show();
        num3 ++;
  }
  else {    
    Serial.print(&quot;r&quot;);
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
        num3 = 0;
  }
  }
  prevstate3 = btnstate3;
}
delay(10);
}</code></pre><h1 id="slave-part-code-softwareserial">Slave part code (SoftwareSerial)</h1>
<pre><code>#include &lt;SoftwareSerial.h&gt;
#include &lt;Adafruit_NeoPixel.h&gt;

SoftwareSerial mySerial(2, 3);
int BUTTON1 = 4;
int BUTTON2 = 5;
int BUTTON3 = 6;
int pot = A0;
int btnstate1;
int prevstate1 = 1;
int btnstate2;
int prevstate2 = 1;
int btnstate3;
int prevstate3 = 1;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int lednum1 = 0;
int lednum2 = 0;
int lednum3 = 0;
int lednum4 = 0;
int lednum5 = 0;
int lednum6 = 0;

#define PIN 7
#define LEDNUM 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  mySerial.begin(4800);
      strip.begin();                           // 네오픽셀 제어시작
  strip.show();                            // 네오픽셀 초기화
  int reading = analogRead(pot);
  int b = map(reading,0,1024,1,150);
    strip.begin();    
  strip.setPixelColor(0, b, 0, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(1, b, b, 0);
  strip.show();     
  delay(400);
  strip.setPixelColor(2, 0, b, 0);
  strip.show();     
  delay(400);
  int k = 0;
  while(k &lt; 4)
  {
    strip.setPixelColor(0, b, 0, 0);
    strip.setPixelColor(1, b, b, 0);
    strip.setPixelColor(2, 0, b, 0);
    strip.show();
    delay(200);
  strip.setPixelColor(0, 0, 0, 0);
  strip.setPixelColor(1, 0, 0, 0);
  strip.setPixelColor(2, 0, 0, 0);
  strip.show();
  delay(200);
  k++;
  }
}

void loop() {
int reading = analogRead(pot);
int b = map(reading,0,1024,1,150);

  if (mySerial.available()) {
    char c = (char)mySerial.read();
   if (c == &#39;a&#39;){
  strip.setPixelColor(1, b, 0, 0);
    strip.show();
  }
   if (c == &#39;b&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;c&#39;){
  strip.setPixelColor(1, b, b, 0);
    strip.show();
  }
   if (c == &#39;d&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;e&#39;){
  strip.setPixelColor(1, 0, b, 0);
    strip.show();
  }
   if (c == &#39;f&#39;){
  strip.setPixelColor(1, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;m&#39;){
  strip.setPixelColor(2, b, 0, 0);
    strip.show();
  }
   if (c == &#39;n&#39;){
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;o&#39;){
  strip.setPixelColor(2, b, b, 0);
    strip.show();
  }
   if (c == &#39;p&#39;){
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
   if (c == &#39;q&#39;){
  strip.setPixelColor(2, 0, b, 0);
    strip.show();
  }
   if (c == &#39;r&#39;){
  strip.setPixelColor(2, 0, 0, 0);
    strip.show();
  }
  }

    btnstate1 = digitalRead(BUTTON1);
if(btnstate1 != prevstate1){
  if(btnstate1 ==1){
    if(num1 == 0){
      mySerial.print(&quot;g&quot;);
  strip.setPixelColor(0, b, 0, 0);
    strip.show();
        num1 ++;
  }
  else {
    mySerial.print(&quot;h&quot;);    
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
        num1 = 0;
  }
  }
  prevstate1 = btnstate1;
}

    btnstate2 = digitalRead(BUTTON2);
if(btnstate2 != prevstate2){
  if(btnstate2 ==1){
    if(num2 == 0){
      mySerial.print(&quot;i&quot;);
  strip.setPixelColor(0, b, b, 0);
    strip.show();
        num2 ++;
  }
  else {    
    mySerial.print(&quot;j&quot;);
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
        num2 = 0;
  }
  }
  prevstate2 = btnstate2;
}

btnstate3 = digitalRead(BUTTON3);
if(btnstate3 != prevstate3){
  if(btnstate3 ==1){
    if(num3 == 0){
      mySerial.print(&quot;k&quot;);
  strip.setPixelColor(0, 0, b, 0);
    strip.show();
        num3 ++;
  }
  else {    
    mySerial.print(&quot;l&quot;);
  strip.setPixelColor(0, 0, 0, 0);
    strip.show();
        num3 = 0;
  }
  }
  prevstate3 = btnstate3;
}
delay(10);
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2021 숭실 스마트 산학융합 공모전 아두이노 프로젝트]]></title>
            <link>https://velog.io/@hyeonu_chun/2021-%EC%88%AD%EC%8B%A4-%EC%8A%A4%EB%A7%88%ED%8A%B8-%EC%82%B0%ED%95%99%EC%9C%B5%ED%95%A9-%EA%B3%B5%EB%AA%A8%EC%A0%84-%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</link>
            <guid>https://velog.io/@hyeonu_chun/2021-%EC%88%AD%EC%8B%A4-%EC%8A%A4%EB%A7%88%ED%8A%B8-%EC%82%B0%ED%95%99%EC%9C%B5%ED%95%A9-%EA%B3%B5%EB%AA%A8%EC%A0%84-%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</guid>
            <pubDate>Mon, 21 Jun 2021 04:41:45 GMT</pubDate>
            <description><![CDATA[<h1 id="아두이노-ide-code">아두이노 IDE code</h1>
<pre><code>//TRIG, ECHO PIN 정의//

const int TRIG = 2;
const int ECHO = 3;                  

//평균 이동 필터의 Buffer Size 정의//

//변수 정의//
float duration;

void setup(){

  Serial.begin(9600);       //시리얼 통신 설정
  Serial.flush();         //시리얼 통신 후 다시 시리얼 통신을 시작할 때, 들어오거나 남아있던 값을 제거

  //핀 모드 설정

  pinMode(TRIG,OUTPUT);     
  pinMode(ECHO,INPUT);
  digitalWrite(TRIG,LOW);
}

void loop(){

  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  duration = pulseIn(ECHO, HIGH);

  Serial.println(duration);

  delay(1000);
}</code></pre><h1 id="python-code">Python code</h1>
<pre><code># pip install pySerial
import serial

arduino = serial.Serial(&#39;COM8&#39;, 9600)

class Student():
    def __init__(self):
        self.z=2
        print(&quot;z init as :&quot;, self.z)

a = list()

duration = 0
distance = 0

cm_distance = 0
new_cm_distance = 0

pre_distance = 0

sum_of_buffer = 0

new_duration = 0

alpha = 0.3
beta = 0.01

cnt = 0
s = 1  # 0.1

cnt_hit = 0
h = 1  # 0.1

outCount = 0

human_sig = False

for i in range(10):

    duration = float(arduino.readline().decode()[:-1])
    cm_distance = ((duration * 340) / 10000) / 2
    a.append(cm_distance)

    if cm_distance &gt; 280:
        cm_distance = 280
    elif cm_distance &lt; 2:
        cm_distance = 2

    sum_of_buffer += a[i]

pre_distance = sum_of_buffer / len(a)

while 1:
    new_duration = float(arduino.readline().decode()[:-1])
    new_cm_distance = ((new_duration * 340) / 10000) / 2

    if new_cm_distance &lt; 190:
        distance = alpha * pre_distance + (1-alpha) * new_cm_distance

    elif new_cm_distance &lt; 280:
        distance = (1-alpha) * pre_distance + alpha * new_cm_distance
    else:
        distance = (1-beta) * pre_distance + beta * new_cm_distance

    if distance &gt; 280:
        distance = 280
    elif distance &lt; 2:
        distance = 2

    print(&quot;distance(cm) :&quot;, int(distance), end=&#39; &#39;)

    cnt += s

    times = 100000 - cnt * 930  # 300000 - cnt * 930

    print(&quot;Sample Number :&quot;, cnt, end=&#39; &#39;)

    if distance &lt;= 150:
        cnt_hit += h

    print(&quot;Human Cnt_Number :&quot;, cnt_hit, end=&#39; &#39;)

    if cnt_hit &lt; 16.10:
        if times &lt;= 60000:  #120000
            # delay(120000) 고정된 2분
            cnt = 0
            # 시간을 뽑아 실시간 기록하거나 찾을 필요없이 현회차와 전회차 비교해서 오차 확인 가능
            cnt_hit = 0
            times = 0
            outCount += 1
    else:
        human_sig = True
        print(&quot;Human_Signal :&quot;, human_sig)
        # delay(times) 측정되는 3분 중에 남는 시간 + 2분
        human_sig = False
        cnt = 0
        # 시간을 뽑아 엑셀이든 txt파일 데이터가 실시간으로 밀리지 않는지 확인하지 위해서
        cnt_hit = 0
        times = 0
        outCount = 0

    pre_distance = distance
    print(&quot;outCount :&quot;, outCount)
    # outCount 18cycle일때 경고 메세지, 24cycle일땐 out
    # 가방이나 물건 올려놨을때 움직임 없을때 확인하는 로직 현회차와 전회차 비교해서 오차 확인 가능
    # 실시간 실내/실외 온도나 습도에 따른 파라메타 변화 적용 or not</code></pre><h1 id="20210707-ver25">20210707 Ver2.5</h1>
<h1 id="arduino-ide-code">Arduino IDE code</h1>
<pre><code>const int ECHO1=13;        // mini_size 3
const int TRIG1=12;     // mini_size 2
const int ECHO2=9;         // mini_size 5
const int TRIG2=8;         // mini_size 4
const int ECHO3=3;         // mini_size 7
const int TRIG3=2;         // mini_size 6

#define SIZE 20         // Buffer of setting Moving average filter
#define DIST 280*58.8     // mini_size 50*58.8

int buffer1[SIZE];
int buffer2[SIZE];
int buffer3[SIZE];

const int maxdist = 280;    //mini_size 50
const int mindist = 2;        //mini_size 2
double kalman1(double U1);
double kalman2(double U2);
double kalman3(double U3);        

double tmp1 = 200;    //tmp_value for invalid, mini_size 32
double tmp2 = 200;    //tmp_value for invalid, mini_size 32
double tmp3 = 200;    //tmp_value for invalid, mini_size 32

long Cm1, Cm2, Cm3;
long duration1, duration2, duration3;

float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float distance1, distance2, distance3;

char ch;

double kalman1(double U1){
  static const double R1 = 40;
  static const double H1 = 1.00;
  static double Q1 = 10;
  static double P1 = 0;
  static double U_hat1 = 170;    // mini_size 20
  static double K1 = 0;
  K1 = P1*H1/(H1*P1*H1+R1);
  U_hat1 += + K1*(U1-H1*U_hat1);
  P1 = (1-K1*H1)*P1+Q1;
  return U_hat1;
}

double kalman2(double U2){
  static const double R2 = 40;
  static const double H2 = 1.00;
  static double Q2 = 10;
  static double P2 = 0;
  static double U_hat2 = 170;    // mini_size 20
  static double K2 = 0;
  K2 = P2*H2/(H2*P2*H2+R2);
  U_hat2 += + K2*(U2-H2*U_hat2);
  P2 = (1-K2*H2)*P2+Q2;
  return U_hat2;
}

double kalman3(double U3){
  static const double R3 = 40;
  static const double H3 = 1.00;
  static double Q3 = 10;
  static double P3 = 0;
  static double U_hat3 = 170;    // mini_size 20
  static double K3 = 0;
  K3 = P3*H3/(H3*P3*H3+R3);
  U_hat3 += + K3*(U3-H3*U_hat3);
  P3 = (1-K3*H3)*P3+Q3;
  return U_hat3;
}

void setup() {
  Serial.begin(9600);
  Serial.flush();
  pinMode(TRIG1,OUTPUT);
  pinMode(ECHO1,INPUT);
  digitalWrite(TRIG1,LOW);
  pinMode(TRIG2,OUTPUT);
  pinMode(ECHO2,INPUT);
  digitalWrite(TRIG2,LOW);
  pinMode(TRIG3,OUTPUT);
  pinMode(ECHO3,INPUT);
  digitalWrite(TRIG3,LOW);

  for(int i=0; i&lt;=SIZE-1; i++)
  {
    digitalWrite(TRIG1,HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG1,LOW);
    duration1=pulseIn(ECHO1,HIGH);
    Cm1=duration1*0.034/2;
    if(Cm1&gt;maxdist) Cm1=maxdist;
    else if(Cm1&lt;mindist) Cm1=mindist;
    buffer1[i]=Cm1;
    sum1+=buffer1[i];
  }
  for(int i=0; i&lt;=SIZE-1; i++)
  {
    digitalWrite(TRIG2,HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG2,LOW);
    duration2=pulseIn(ECHO2,HIGH);
    Cm2=duration2*0.034/2;
    if(Cm2&gt;maxdist) Cm2=maxdist;
    else if(Cm2&lt;mindist) Cm2=mindist;
    buffer2[i]=Cm2;
    sum2+=buffer2[i];
  }
  for(int i=0; i&lt;=SIZE-1; i++)
  {
    digitalWrite(TRIG3,HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG3,LOW);
    duration3=pulseIn(ECHO3,HIGH);
    Cm3=duration3*0.034/2;
    if(Cm3&gt;maxdist) Cm3=maxdist;
    else if(Cm3&lt;mindist) Cm3=mindist;
    buffer3[i]=Cm3;
    sum3+=buffer3[i];
  }
  Serial.flush();
}

void loop() {
  if(Serial.available() &gt;0){
    ch = Serial.read();
    if(ch == &#39;a&#39;) delay(1000);    // Break time
  }

  digitalWrite(TRIG1,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG1,LOW);
  duration1=pulseIn(ECHO1,HIGH, DIST); // invaild value(280cm 이상) 1차 예외처리(timeout 조절)
  Cm1=duration1*0.034/2;

  if(Cm1==0) Cm1 = tmp1;  // 1차 예외처리 된 data 직전 typical data 사용
  else{
    if(Cm1&gt;maxdist) Cm1=maxdist;  // extreme case 2차 예외처리(distance limiting)
    else if(Cm1&lt;mindist) Cm1=mindist;
    tmp1 = Cm1;
  }

  sum1-=buffer1[0];
  for(int i=0; i&lt;SIZE-1; i++)
  {
    buffer1[i]=buffer1[i+1];
  }
  buffer1[SIZE-1]=Cm1;
  sum1+=buffer1[SIZE-1];

  if(Cm1 &gt; 150){    // mini_size 22
    distance1=sum1/SIZE;    // Moving average filtered distance 사용
  }
  else{
    distance1 = kalman1(Cm1);    // Kalman filtered distance 사용
  }

  delay(50);
  /////////////////////////////////////////////////////////////////////////////////////
  digitalWrite(TRIG2,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG2,LOW);
  duration2=pulseIn(ECHO2,HIGH,DIST); // invaild value(280cm 이상) 1차 예외처리(timeout 조절)
  Cm2=duration2*0.034/2;

  if(Cm2==0) Cm2 = tmp2;  // 1차 예외처리 된 data 직전 typical data 사용
  else{
    if(Cm2&gt;maxdist) Cm2=maxdist;  // extreme case 2차 예외처리(distance limiting)
    else if(Cm2&lt;mindist) Cm2=mindist;
    tmp2 = Cm2;
  }

  sum2-=buffer2[0];
  for(int i=0; i&lt;SIZE-1; i++)
  {
    buffer2[i]=buffer2[i+1];
  }
  buffer2[SIZE-1]=Cm2;
  sum2+=buffer2[SIZE-1];  

  if(Cm2 &gt; 150){    // mini_size 22
    distance2=sum2/SIZE;    // Moving average filtered distance 사용
  }
  else{
    distance2 = kalman2(Cm2);    // Kalman filtered distance 사용
  }

  delay(50);
  ///////////////////////////////////////////////////////////////////////////////
  digitalWrite(TRIG3,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG3,LOW);
  duration3=pulseIn(ECHO3,HIGH, DIST); // invaild value(280cm 이상) 1차 예외처리(timeout 조절)
  Cm3=duration3*0.034/2;

  if(Cm3==0) Cm3 = tmp3;  // 1차 예외처리 된 data 직전 typical data 사용
  else{
    if(Cm3&gt;maxdist) Cm3=maxdist;  // extreme case 2차 예외처리(distance limiting)
    else if(Cm3&lt;mindist) Cm3=mindist;
    tmp3 = Cm3;
  }

  sum3-=buffer3[0];
  for(int i=0; i&lt;SIZE-1; i++)
  {
    buffer3[i]=buffer3[i+1];
  }
  buffer3[SIZE-1]=Cm3;
  sum3+=buffer3[SIZE-1];  

  if(Cm3 &gt; 150){    // mini_size 22
    distance3=sum3/SIZE;    // Moving average filtered distance 사용
  }
  else{  // 3차 칼만필터 filtering 구간
    distance3 = kalman3(Cm3);    // Kalman filtered distance 사용
  }

  delay(50);

  //Serial.print(distance1); Serial.print(&quot; &quot;); Serial.println(Cm1);// Serial.print(&quot; &quot;); Serial.println(distance3);
  Serial.print(distance1); Serial.print(&#39; &#39;); Serial.print(distance2); Serial.print(&#39; &#39;); Serial.println(distance3);

  delay(50);
}</code></pre><h1 id="python-code-server">Python code (Server)</h1>
<pre><code>import serial
import time

select_comport = input(&#39;select port:&#39;)

arduino = serial.Serial(select_comport, 9600)

sample_cnt = 200
human_exist_dist = 150  # 22
yellow_card = 45
red_card = 60
sec = 1
line_list = list()
desk_list = list()
full_cycle_time = 60

with open(&quot;number_of_student.txt&quot;, &quot;r&quot;) as f:
    line_tmp = f.readlines()
    max_desk_cnt = len(line_tmp)

cnt = max_desk_cnt * sample_cnt


class Desk:
    def __init__(self):
        self.distance = 0
        self.hit_cnt = 0
        self.out_cnt = 0
        self.flag = False
        self.stu_phone = &quot;&quot;

    def print_desk_info(self):
        print(self.stu_phone, &quot;(Dist:&quot;, int(self.distance), &quot;Hit:&quot;, self.hit_cnt, &quot;Out:&quot;, self.out_cnt, end=&#39;)\t\t\t\t&#39;)


def read_distance():
    if arduino.readable():
        try:
            tmp_distance = arduino.readline().decode().split(&#39; &#39;)
            tmp_distance = [float(e) for e in tmp_distance]
            for m in range(max_desk_cnt - len(tmp_distance)):
                tmp_distance.append(0)
            return tmp_distance
        except ValueError:
            return [0]

# Initialize
for i in range(max_desk_cnt):
    desk_list.append(Desk())

first_time = time.time()  # real time checking

# Loop
while True:
    try:
        # 실시간으로 number_of_student value 들이 kiosk 에 의해 변했는지 확인
        with open(&quot;number_of_student.txt&quot;, &quot;r&quot;) as f:
            line_list = f.readlines()
        for i in range(len(line_list)):
            temp = desk_list[i]
            temp.stu_phone = line_list[i][:-1]
            if temp.stu_phone == &quot;0&quot;:  # 학생 번호가 있어야하는 위치에 0이 있으면 객체 데이터 초기화
                temp.flag = False
                temp.out_cnt = 0
                temp.hit_cnt = 0
            else:  # 학생 번호가 입장되었으면 flag value on (distance 에 따른 logic 실행)
                temp.flag = True

        dist_list = read_distance()  # 아두이노를 통해 들어온 데이터 1차 정제

        if len(dist_list) == max_desk_cnt:
            for i in range(max_desk_cnt):  # 각 센서의 데이터별로 처리 시작
                tmp_desk = desk_list[i]
                tmp_desk.distance = dist_list[i]

                cnt -= sec
                print(cnt, end=&#39;: &#39;)
                if cnt == -sec:

                    cnt = max_desk_cnt * sample_cnt  # break time 이후 cnt 값 초기화
                    cycle_time = time.time() - first_time
                    print(&quot;BREAK&quot;)
                    if cycle_time &lt; full_cycle_time:
                        time.sleep(full_cycle_time - cycle_time)
                    arduino.read_all()
                    with open(&quot;data_list.txt&quot;, &quot;a&quot;) as f:  # cycle time 기록
                        f.write(str(cycle_time) + &quot;;&quot;)
                        for j in desk_list:
                            f.write(str(j.hit_cnt) + &quot;;&quot;)
                        f.write(&quot;\n&quot;)
                    for j in desk_list:  # break time 이후 cnt_hit 초기화
                        j.hit_cnt = 0
                    first_time = time.time()
                    break

                if tmp_desk.flag == True:  # flag 가 1일때, 즉 사람이 입장했을때 실행
                    if 0 &lt; tmp_desk.distance &lt;= human_exist_dist:  # 사람이 있다는 거리
                        tmp_desk.hit_cnt += sec
                    if cnt &lt; max_desk_cnt:  # break 전 마지막 루프에서 cnt_hit 값에 따른 결과 처리
                        if tmp_desk.hit_cnt &lt;= sample_cnt * 0.2:  # sensing time 의 20%, 사람이 일정이상 앉아 있지 않을 때
                            tmp_desk.out_cnt += 1
                            if tmp_desk.out_cnt == red_card:  # 퇴장 처리
                                with open(&quot;sign_list.txt&quot;, &quot;a&quot;) as f:  # 퇴장 메세지 전송
                                    f.write(tmp_desk.stu_phone + &quot;Red&quot; + &quot;\n&quot;)
                                with open(&quot;out_student.txt&quot;, &quot;a&quot;) as f:  # kiosk 에게 퇴장한 사람 데이터 전송
                                    out_student_list = [str(i), &quot;&#39;&quot;, tmp_desk.stu_phone, &quot;&#39;&quot;, str(time.time()), &quot;&#39;&quot;,
                                                        str(time.strftime(&#39;%c&#39;, time.localtime(time.time()))), &quot;\n&quot;]
                                    f.writelines(out_student_list)
                                line_list[i] = &quot;0\n&quot;  # number_of_student 에서 받아들였던 데이터 수정
                                with open(&quot;number_of_student.txt&quot;, &quot;w&quot;) as f:  # 수정된 number_of_student 데이터 전송
                                    for line in line_list:
                                        f.write(line)
                                tmp_desk.stu_phone = &quot;0&quot;  # 객체 데이터 수정
                                tmp_desk.flag = False
                                tmp_desk.out_cnt = 0
                                tmp_desk.hit_cnt = 0
                            elif tmp_desk.out_cnt == yellow_card:  # 경고 처리
                                with open(&quot;sign_list.txt&quot;, &quot;a&quot;) as f:  # 경고 메세지 전송
                                    f.write(tmp_desk.stu_phone + &quot;Yellow&quot; + &#39;\n&#39;)
                        else:   # 사람이 일정이상 앉아 있을 때
                            tmp_desk.out_cnt = 0
                tmp_desk.print_desk_info()
            print()
    except IOError:
        pass</code></pre><h1 id="python-code-kiosk">Python code (Kiosk)</h1>
<pre><code>import os
import time
from openpyxl import load_workbook

data_list = list()

with open(&quot;number_of_student.txt&quot;, &quot;r&quot;) as f:
    line_ori = f.readlines()
num_of_data = len(line_ori)


def read_data():
    with open(&quot;number_of_student.txt&quot;, &quot;r&quot;) as p:
        line_ori_tmp = p.readlines()
    line_tmp = [line_ori_tmp[x][:-1] for x in range(num_of_data)]

    with open(&quot;out_student.txt&quot;, &quot;r&quot;) as s:
        line_stu = s.readlines()
    if line_stu != &quot;&quot;:
        for x in range(len(line_stu)):
            line_stu_tmp = line_stu[x].split(&quot;&#39;&quot;)
            for data_tmp in data_list:
                if (data_tmp[0] == int(line_stu_tmp[0])) &amp; (data_tmp[1] == line_stu_tmp[1]):
                    data_tmp[2] = int(-(float(line_stu_tmp[2]) - data_tmp[2]))
                    data_tmp.append(line_stu_tmp[3][:-1])
                    print(data_tmp)  # 엑셀에 프린트

                    wb_tmp = load_workbook(&#39;using_list.xlsx&#39;)
                    ws_tmp = wb_tmp[&#39;Sheet1&#39;]
                    ws_tmp.append(data_tmp)
                    wb_tmp.save(&#39;using_list.xlsx&#39;)

                    data_list.remove(data_tmp)
        with open(&quot;out_student.txt&quot;, &quot;w&quot;) as s:
            s.write(&quot;&quot;)
    return line_tmp


while True:
    enter_or_exit = input(&quot;입장 / 퇴장 : &quot;)
    line = read_data()
    if enter_or_exit == &quot;입장&quot;:
        print(&quot;사용 가능한 좌석 : &quot;)
        for i in range(num_of_data):
            if line[i] == &#39;0&#39;:
                print(i+1, &quot;번&quot;, end=&quot; &quot;)
        print()
        num_sit = input(&quot;입장할 좌석번호 / 나가기(0) : &quot;)[:1]
        line = read_data()
        if num_sit.isnumeric() == 1:
            num_sit = int(num_sit) - 1
            if 0 &lt;= num_sit &lt; num_of_data:
                if line[num_sit] == &#39;0&#39;:
                    num_student = input(&quot;사용자의 핸드폰 번호 : &quot;)
                    line = read_data()
                    line[num_sit] = num_student
                    if (len(num_student) == 11) &amp; (num_student.isnumeric() == 1) &amp; (num_student[:2] == &quot;01&quot;):
                        data_list.append([num_sit, num_student, time.time(), time.strftime(&#39;%c&#39;, time.localtime(time.time()))])
                        with open(&quot;number_of_student.txt&quot;, &quot;w&quot;) as f:
                            for j in range(num_of_data):
                                f.write(line[j]+&#39;\n&#39;)
                        print(&quot;회원님의 자리는&quot;, num_sit + 1, &quot;번 입니다.&quot;)
                    else:
                        print(&quot;잘못된 입력입니다.&quot;)
                else:
                    print(&quot;잘못된 좌석을 지정하였습니다.&quot;)
            else:
                print(&quot;잘못된 좌석을 지정하였습니다.&quot;)
        else:
            print(&quot;잘못된 좌석을 지정하였습니다.&quot;)
        print(&quot;메인화면으로 돌아갑니다.&quot;)
        input(&quot;아무버튼이나 눌러주세요.&quot;)
        os.system(&#39;cls&#39;)
    elif enter_or_exit == &quot;퇴장&quot;:
        num_sit = input(&quot;퇴장할 좌석번호 / 나가기(0) : &quot;)[:1]
        line = read_data()
        if num_sit.isnumeric() == 1:
            num_sit = int(num_sit) - 1
            if 0 &lt;= num_sit &lt; num_of_data:
                if line[num_sit] != &#39;0&#39;:
                    num_student = input(&quot;사용자의 핸드폰 번호 : &quot;)
                    if (len(num_student) == 11) &amp; (num_student.isnumeric() == 1):
                        with open(&quot;number_of_student.txt&quot;, &quot;r&quot;) as f:
                            line_ori = f.readlines()
                        line = [line_ori[x][:-1] for x in range(num_of_data)]
                        for data in data_list:
                            if (num_sit == data[0]) &amp; (num_student == data[1]):
                                data[2] = int(time.time() - data[2])
                                # data[2] = data[2] // 60
                                data.append(time.strftime(&#39;%c&#39;, time.localtime(time.time())))
                                line_ori[num_sit] = &quot;0\n&quot;
                                with open(&quot;number_of_student.txt&quot;, &quot;w&quot;) as f:
                                    for j in line_ori:
                                        f.write(j)
                                print(data)  # 엑셀에 프린트
                                wb = load_workbook(&#39;using_list.xlsx&#39;)
                                ws = wb[&#39;Sheet1&#39;]
                                ws.append(data)
                                wb.save(&#39;using_list.xlsx&#39;)
                                data_list.remove(data)
                                print(num_sit + 1, &quot;번 자리가 퇴장처리 되었습니다. 이용해주셔서 감사합니다.&quot;)
                                break
                        else:
                            print(&quot;올바르지 않은 번호입니다.&quot;)
                    else:
                        print(&quot;잘못된 입력입니다.&quot;)
                else:
                    print(&quot;잘못된 좌석을 지정하였습니다.&quot;)
        else:
            print(&quot;잘못된 좌석을 지정하였습니다.&quot;)
        print(&quot;메인화면으로 돌아갑니다.&quot;)
        input(&quot;아무버튼이나 눌러주세요.&quot;)
        os.system(&#39;cls&#39;)
    else:
        print(&quot;잘못된 입력입니다.&quot;)
        print(&quot;메인화면으로 돌아갑니다.&quot;)
        input(&quot;아무버튼이나 눌러주세요.&quot;)
        os.system(&#39;cls&#39;)</code></pre><h1 id="python-code-message">Python code (Message)</h1>
<pre><code>import requests
import time

while 1:
    try:
        with open(&quot;sign_list.txt&quot;, &quot;r&quot;) as f:
            signs = f.readlines()
            num_of_sign = len(signs)
        for i in range(num_of_sign):
            a = signs[i][:11] + &quot; 고객님께 보내는 알림입니다.\n&quot;
            if signs[i][11:-1] == &quot;Yellow&quot;:
                b = &quot;경고 알림: 15분 동안 자리를 비우셨습니다.\n25분 동안 자리를 비울시 퇴장 처리됩니다.&quot;
            else:
                b = &quot;퇴장 알림: 25동안 자리를 비우셨습니다.\n좌석이 퇴장 처리됩니다.&quot;
            try:
                TARGET_URL = &#39;https://notify-api.line.me/api/notify&#39;
                TOKEN = &#39;i8DYbNCp5k6B6m7QP4kfiLYzvJZNzQX27cMwd5E8Jo5&#39;  # 발급받은 토큰
                headers = {&#39;Authorization&#39;: &#39;Bearer &#39; + TOKEN}
                data = {&#39;message&#39;: a+b}

                response = requests.post(TARGET_URL, headers=headers, data=data)
            except Exception as ex:
                print(ex)
        if num_of_sign != 0:
            with open(&quot;sign_list.txt&quot;, &quot;w&quot;) as f:
                f.write(&quot;&quot;)
    except IOError:
        pass
    time.sleep(1)</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-22 도서관리시스템 팀 프로젝트]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-22-%EB%8F%84%EC%84%9C%EA%B4%80%EB%A6%AC%EC%8B%9C%EC%8A%A4%ED%85%9C-%ED%8C%80-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-22-%EB%8F%84%EC%84%9C%EA%B4%80%EB%A6%AC%EC%8B%9C%EC%8A%A4%ED%85%9C-%ED%8C%80-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8</guid>
            <pubDate>Mon, 21 Jun 2021 04:16:29 GMT</pubDate>
            <description><![CDATA[<h1 id="도서관리시스템">도서관리시스템</h1>
<ol>
<li><p>로그인
 (1) 관리자 모드</p>
<pre><code> - 책 추가 (Input : 책 제목, 출판사, 종류)
 - 책 삭제 (Input : 책 제목)
 - 사용자들의 대출 리스트 (Output : 사용자 이름, 전공, 학번, 대출날짜)
 - 책 검색 (Input : 책 제목 / Output : 출판사, 종류, 코드, 대출여부)
 - 전체 책 목록 (Output : 책 제목, 출판사, 종류, 코드, 대출여부)</code></pre><p> (2) 사용자 모드</p>
<pre><code> - 책 대출 (Input : 책 제목, 코드)
 - 책 반납 (Input : 책 제목, 코드)
 - 나의 대출 리스트 (Output : 책 제목, 코드, 대출날짜)
 - 책 검색 (Input : 책 제목 / Output : 출판사, 종류, 코드, 대출여부)
 - 전체 책 목록 (Output : 책 제목, 출판사, 종류, 코드, 대출여부)</code></pre></li>
<li><p>사용자 추가</p>
<ul>
<li>사용자 입력 (Input : 이름, 전공, 학번)</li>
</ul>
</li>
<li><p>사용자 삭제</p>
<ul>
<li>사용자 삭제 (Input : 이름)
<img src="https://images.velog.io/images/hyeonu_chun/post/da06a3cd-4687-4764-8ac9-e00104cdce58/%EB%8F%84%EC%84%9C%20%EA%B4%80%EB%A6%AC%20%EC%8B%9C%EC%8A%A4%ED%85%9C.png" alt=""><pre><code>//Rent.h
#pragma once
#include &lt;string&gt;
#include &lt;time.h&gt;  
#include &lt;iostream&gt;
using namespace std;
</code></pre></li>
</ul>
</li>
</ol>
<p>struct Rent{
    char BookKind;
    int BookCode;
    int Personid;
    int startDay;
    //int useDay;
};</p>
<p>//Person.h
#pragma once
#include <string>
#include <iostream>
#define pMax 10
using namespace std;</p>
<p>class Person
{
private:
    int id;
    string major;
    string PersonName;
public:
    Person(string PersonName = &quot;아무개&quot;, int id = 0, string major = &quot;noname&quot;);
    int getId();
    void setId(int id);
    string getMajor();
    void setMajor(string major);
    string getPersonName();
    void setPersonName(string PersonName);
};</p>
<p>//Person.cpp
#include &quot;Person.h&quot;</p>
<p>Person::Person(string PersonName, int id , string major ) : id(id), major(major), PersonName(PersonName) {};</p>
<p>int Person::getId()
{
    return id;
}</p>
<p>void Person::setId(int id)
{
    this-&gt;id = id;
}</p>
<p>string Person::getMajor()
{
    return major;
}</p>
<p>void Person::setMajor(string major)
{
    this-&gt;major = major;
}</p>
<p>string Person::getPersonName()
{
    return PersonName;
}</p>
<p>void Person::setPersonName(string PersonName)
{
    this-&gt;PersonName = PersonName;
}</p>
<p>//PersonManage.h
#pragma once
#include &quot;Person.h&quot;
#include &quot;RentBookList.h&quot;</p>
<p>class PersonManage
{
private:
    Person *PersonArray[pMax];
public:
    int PersonCnt;
    PersonManage();</p>
<pre><code>Person** getPersonArray();    
PersonManage &amp; operator=(const PersonManage &amp;r);    
Person* findPerson(int id);
bool addPerson(Person* ap);
bool deletePerson(string PersonName);    
// friend int RentBookList::getPersonId(Person &amp;rp);</code></pre><p>};</p>
<p>//PersonManage.cpp
#include &quot;PersonManage.h&quot;
#include <iostream>
using namespace std;</p>
<p>PersonManage::PersonManage() : PersonCnt(0) 
{
    PersonArray[pMax] = { NULL, };
};</p>
<p>Person** PersonManage::getPersonArray()
{
    return PersonArray;
}</p>
<p>PersonManage&amp; PersonManage::operator=(const PersonManage &amp;r)
{
    if (this == &amp;r)
        return *this;
    for (int i = 0; i &lt; this-&gt;PersonCnt; i++)
    {
        delete this-&gt;getPersonArray()[i];
    }
    this-&gt;PersonCnt = r.PersonCnt;
    return *this;
}</p>
<p>Person* PersonManage::findPerson(int id)
{
    for (int i = 0; i &lt; PersonCnt; i++)
    {
        if (PersonArray[i]-&gt;getId() == id)
            return PersonArray[i];
    }
    return NULL;
}</p>
<p>bool PersonManage::addPerson(Person *ap) //등록 성공 - 1, 등록 실패 - 0 리턴
{
    if (PersonCnt &gt; pMax)
        return false;
    else
    {<br>        for (int i = 0; i &lt; PersonCnt; i++)
        {
            if (PersonArray[i]-&gt;getId() == ap-&gt;getId())
            {
                cout &lt;&lt; &quot;해당 학번은 이미 존재합니다.&quot; &lt;&lt; endl;
                return false;
            }
        }
        PersonArray[PersonCnt] = new Person(ap-&gt;getPersonName(),ap-&gt;getId(), ap-&gt;getMajor());
        PersonCnt++;
        return true;
    }
}</p>
<p>bool PersonManage::deletePerson(string PersonName) // 삭제 성공 - true, 삭제 실패 - false 리턴
{
    int i;
    int j;
    int index = -1;
    char ch;</p>
<pre><code>if (PersonCnt == 0)
    return false;

for (i = 0; i &lt; PersonCnt; i++)
    if (PersonArray[i]-&gt;getPersonName() == PersonName)
        index = i;

if (index != -1) {
    i = index;
    cout &lt;&lt; &quot;정말 삭제하시겠습니까?(Y/N) : &quot;;
    cin &gt;&gt; ch;
    if (ch == &#39;y&#39; || ch == &#39;Y&#39;) {
        delete PersonArray[i];
        for (j = i; j &lt; PersonCnt - 1; j++) {
            PersonArray[i] = PersonArray[i + 1];
        }
        PersonCnt--;
        return true;
    }
    else
        return false;
}
return false;</code></pre><p>}</p>
<p>//Book.h
#pragma once
#include <string>
#include <iostream>
using namespace std;</p>
<p>class Book
{
private:
    string BookName;
    string CpyName;
public:
    Book();
    Book(string BookName, string CpyName);</p>
<pre><code>string getBookName();
void setBookName(string BookName);
string getCpyName();
void setCpyName(string CpyName);

virtual void infoView() = 0;
virtual bool getflag() = 0;
virtual void setflag(bool num) = 0;</code></pre><p>};</p>
<p>//Book.cpp
#include <string>
#include <iostream>
using namespace std;
#include &quot;Book.h&quot;</p>
<p>Book::Book() :BookName(&quot;&quot;), CpyName(&quot;&quot;)
{}
Book::Book(string BookName, string CpyName) : BookName(BookName), CpyName(CpyName)
{}</p>
<p>string Book::getBookName()
{
    return BookName;
}
void Book::setBookName(string BookName)
{
    this-&gt;BookName = BookName;
}
string Book::getCpyName()
{
    return CpyName;
}
void Book::setCpyName(string CpyName)
{
    this-&gt;CpyName = CpyName;
}</p>
<p>//Novel.h
#pragma once
#include &quot;Book.h&quot;</p>
<p>class Novel : public Book {
    char BookKind;
    int BookCode;
    bool flag = false;
public:
    static int NovelNum;
    Novel();
    Novel(string BookName, string CpyName, char kind);
    char getBookKind();
    void setBookKind(char kind);
    int getBookCode();
    void setBookCode(int Code);
    void infoView();
    void setflag(bool num);
    bool getflag();
};</p>
<p>//Novel.cpp
#include <string>
#include <iostream>
using namespace std;
#include &quot;Novel.h&quot;</p>
<p>int Novel::NovelNum = 1;</p>
<p>Novel::Novel() : Book(&quot;&quot;,&quot;&quot;), BookKind(0)
{}
Novel::Novel(string BookName, string CpyName, char kind)
    : Book(BookName, CpyName), BookKind(kind)
{
    BookCode = NovelNum;
    NovelNum++;
}
char Novel::getBookKind()
{
    return BookKind;
}
void Novel::setBookKind(char kind)
{
    BookKind = kind;
}
int Novel::getBookCode()
{
    return BookCode;
}
void Novel::setBookCode(int Code)
{
    BookCode = Code;
}</p>
<p>void Novel::infoView()
{
    cout &lt;&lt; &quot;책제목 : &quot; &lt;&lt; this-&gt;getBookName() &lt;&lt; &quot;  &quot; &lt;&lt; &quot;출판사 : &quot; &lt;&lt; this-&gt;getCpyName() &lt;&lt; &quot;  &quot;
        &lt;&lt; &quot;책종류 : 소설 &quot; &lt;&lt; &quot;  &quot; &lt;&lt; &quot;책코드 : &quot; &lt;&lt; this-&gt;BookKind &lt;&lt; this-&gt;BookCode;
    if (this-&gt;flag == true) cout &lt;&lt; &quot;  (대출중...)&quot;;
    cout &lt;&lt; endl;
}</p>
<p>void Novel::setflag(bool num) {
    this-&gt;flag = num;
}
bool Novel::getflag() {
    return flag;
}</p>
<p>//Comic.h
#pragma once
#include &quot;Book.h&quot;</p>
<p>class Comic : public Book {
    char BookKind;
    int BookCode;
    bool flag = false;
public:
    static int ComicNum;
    Comic();
    Comic(string BookName, string CpyName, char kind);
    char getBookKind();
    void setBookKind(char kind);
    int getBookCode();
    void setBookCode(int Code);
    void infoView();
    void setflag(bool num);
    bool getflag();
};</p>
<p>//Comic.cpp
#include <string>
#include <iostream>
using namespace std;
#include &quot;Comic.h&quot;</p>
<p>int Comic::ComicNum = 1;</p>
<p>Comic::Comic() : Book(&quot;&quot;, &quot;&quot;), BookKind(0)
{}
Comic::Comic(string BookName, string CpyName, char kind)
    : Book(BookName, CpyName), BookKind(kind)
{
    BookCode = ComicNum;
    ComicNum++;
}
char Comic::getBookKind()
{
    return BookKind;
}
void Comic::setBookKind(char kind)
{
    BookKind = kind;
}
int Comic::getBookCode()
{
    return BookCode;
}
void Comic::setBookCode(int Code)
{
    BookCode = Code;
}
void Comic::infoView()
{
    cout &lt;&lt; &quot;책제목 : &quot; &lt;&lt; this-&gt;getBookName() &lt;&lt; &quot;  &quot; &lt;&lt; &quot;출판사 : &quot; &lt;&lt; this-&gt;getCpyName() &lt;&lt; &quot;  &quot;
        &lt;&lt; &quot;책종류 : 만화 &quot; &lt;&lt; &quot;  &quot; &lt;&lt; &quot;책코드 : &quot; &lt;&lt; this-&gt;BookKind &lt;&lt; this-&gt;BookCode;
    if (this-&gt;flag == true) cout &lt;&lt; &quot;  (대출중...)&quot;;
    cout &lt;&lt; endl;
}</p>
<p>void Comic::setflag(bool num) {
    this-&gt;flag = num;
}
bool Comic::getflag() {
    return flag;
}</p>
<p>//MajorBook.h
#pragma once
#include &quot;Book.h&quot;</p>
<p>class MajorBook : public Book {
    char BookKind;
    int BookCode;
    bool flag = false;
public:
    static int MajorNum;
    MajorBook();
    MajorBook(string BookName, string CpyName, char kind);
    char getBookKind();
    void setBookKind(char kind);
    int getBookCode();
    void setBookCode(int Code);
    void infoView();
    void setflag(bool num);
    bool getflag();
};</p>
<p>//MajorBook.cpp
#include <string>
#include <iostream>
using namespace std;
#include &quot;MajorBook.h&quot;</p>
<p>int MajorBook::MajorNum = 1;</p>
<p>MajorBook::MajorBook() : Book(&quot;&quot;, &quot;&quot;), BookKind(0)
{}
MajorBook::MajorBook(string BookName, string CpyName, char kind)
    : Book(BookName, CpyName), BookKind(kind)
{
    BookCode = MajorNum;
    MajorNum++;
}
char MajorBook::getBookKind()
{
    return BookKind;
}
void MajorBook::setBookKind(char kind)
{
    BookKind = kind;
}
int MajorBook::getBookCode()
{
    return BookCode;
}
void MajorBook::setBookCode(int Code)
{
    BookCode = Code;
}
void MajorBook::infoView()
{
    cout &lt;&lt; &quot;책제목 : &quot; &lt;&lt; this-&gt;getBookName() &lt;&lt; &quot;  &quot; &lt;&lt; &quot;출판사 : &quot; &lt;&lt; this-&gt;getCpyName() &lt;&lt; &quot;  &quot;
        &lt;&lt; &quot;책종류 : 전공서적 &quot; &lt;&lt; &quot;  &quot; &lt;&lt; &quot;책코드 : &quot; &lt;&lt; this-&gt;BookKind &lt;&lt; this-&gt;BookCode;
    if (this-&gt;flag == true) cout &lt;&lt; &quot;  (대출중...)&quot;;
    cout &lt;&lt; endl;</p>
<p>}</p>
<p>void MajorBook::setflag(bool num) {
    this-&gt;flag = num;
}
bool MajorBook::getflag() {
    return flag;
}</p>
<p>//BookManage.h
#pragma once
#include &quot;Book.h&quot;
#include &quot;Novel.h&quot;
#include &quot;MajorBook.h&quot;
#include &quot;Comic.h&quot;
#include &lt;stdlib.h&gt;
#include &quot;RentBookList.h&quot;
#include <string>
using namespace std;
#define bMax 10</p>
<p>class BookManage
{
private:
    Book* BookArray[bMax];
    RentBookList List;
public:
    int BookCnt;
    BookManage();
    ~BookManage();
    BookManage (const BookManage &amp;r);
    Book** getBookArray();
    BookManage &amp; operator=(const BookManage &amp;r);
    RentBookList &amp;getRentBookList();
    void printBook();
    bool addBook(Book * ap);
    bool deleteBook(string BookName);
    Book *findBook(char BookKind, int BookCode);
};</p>
<p>//BookManage.cpp
#include <iostream>
#include &quot;BookManage.h&quot;</p>
<p>BookManage::BookManage() {
    for (int i = 0; i &lt; bMax; i++) {
        this-&gt;BookArray[i] = NULL;
    }
    BookCnt = 0;
}
BookManage::~BookManage() {
    for (int i = 0; i &lt; bMax; i++) {
        delete[] this-&gt;BookArray[i];
    }
}</p>
<p>BookManage::BookManage(const BookManage &amp;r) {
    int i;
    this-&gt;BookCnt = r.BookCnt;
    for (i = 0; i &lt; this-&gt;BookCnt; i++) {
        if (dynamic_cast&lt;Novel <em>&gt;(r.BookArray[i]) != NULL) {
            this-&gt;BookArray[i] = new Novel(</em>(dynamic_cast&lt;Novel <em>&gt;(r.BookArray[i])));
        }
        else if (dynamic_cast&lt;MajorBook *&gt;(r.BookArray[i]) != NULL) {
            this-&gt;BookArray[i] = new MajorBook(</em>(dynamic_cast&lt;MajorBook <em>&gt;(r.BookArray[i])));
        }
        else if (dynamic_cast&lt;Comic *&gt;(r.BookArray[i]) != NULL)    {
            this-&gt;BookArray[i] = new Comic(</em>(dynamic_cast&lt;Comic *&gt;(r.BookArray[i])));
        }
    }
}</p>
<p>Book** BookManage::getBookArray() {
    return this-&gt;BookArray;
}</p>
<p>BookManage &amp; BookManage::operator=(const BookManage &amp;r) {
    int i;</p>
<pre><code>if (this == &amp;r) {
    return *this;
}

this-&gt;BookCnt = r.BookCnt;

for (i = 0; i &lt; this-&gt;BookCnt; i++)
{
    delete this-&gt;BookArray[i];
}

for (i = 0; i &lt; this-&gt;BookCnt; i++) {
    if (dynamic_cast&lt;Novel *&gt;(r.BookArray[i]) != NULL) {
        this-&gt;BookArray[i] = new Novel(*(dynamic_cast&lt;Novel *&gt;(r.BookArray[i])));
    }
    else if (dynamic_cast&lt;MajorBook *&gt;(r.BookArray[i]) != NULL) {
        this-&gt;BookArray[i] = new MajorBook(*(dynamic_cast&lt;MajorBook *&gt;(r.BookArray[i])));
    }
    else if (dynamic_cast&lt;Comic *&gt;(r.BookArray[i]) != NULL) {
        this-&gt;BookArray[i] = new Comic(*(dynamic_cast&lt;Comic *&gt;(r.BookArray[i])));
    }

}
return *this;</code></pre><p>}</p>
<p>void BookManage::printBook() {
    for (int i = 0; i &lt; this-&gt;BookCnt; i++) {
        this-&gt;BookArray[i]-&gt;infoView();
    }
}</p>
<p>bool BookManage::addBook(Book * ap) {<br>    if (this-&gt;BookCnt &lt; bMax) {
        this-&gt;BookArray[this-&gt;BookCnt] = ap;
        this-&gt;BookCnt++;
        return true;
    }
    return false;
}
bool BookManage::deleteBook(string BookName) {
    int i, res;
    char YorN;</p>
<pre><code>res = -1;

for (int i = 0; i &lt; this-&gt;BookCnt; i++) {
    if (this-&gt;BookArray[i]-&gt;getBookName() == BookName) {
        res = i;
    }
}

if (res == -1) {
    return false;
}

else {
    cout &lt;&lt; &quot;** 정말로 삭제하겠습니까?(y/n) : &quot;;
    cin &gt;&gt; YorN;
    if (YorN == &#39;y&#39; || YorN == &#39;Y&#39;) {
        delete this-&gt;BookArray[res];

        for (i = res; i &lt; this-&gt;BookCnt - 1; i++) {
            this-&gt;BookArray[i] = this-&gt;BookArray[i + 1];
            if (i == this-&gt;BookCnt - 2)
                this-&gt;BookArray[BookCnt - 1] = NULL;
        }
        this-&gt;BookCnt--;
        return true;
    }
    else
        return false;

}</code></pre><p>}</p>
<p>Book *BookManage::findBook(char BookKind, int BookCode) {</p>
<pre><code>Novel *np;
Comic *cp;
MajorBook *mp;

//cout &lt;&lt; BookCnt &lt;&lt; endl;
for(int i=0;i&lt;BookCnt;i++){

    if (dynamic_cast&lt;Novel *&gt;(BookArray[i]) != NULL) {
        np = dynamic_cast&lt;Novel *&gt;(BookArray[i]);
        //cout &lt;&lt; np-&gt;getBookKind() &lt;&lt; np-&gt;getBookCode() &lt;&lt; endl;
        if ((np-&gt;getBookKind()== BookKind) &amp;&amp;(np-&gt;getBookCode() == BookCode)) {
            return BookArray[i];
        }
    }
    else if (dynamic_cast&lt;MajorBook *&gt;(BookArray[i]) != NULL) {
        mp = dynamic_cast&lt;MajorBook *&gt;(BookArray[i]);
        if ((mp-&gt;getBookKind() == BookKind) &amp;&amp; (mp-&gt;getBookCode() == BookCode)) {
            return BookArray[i];
        }
    }
    else if (dynamic_cast&lt;Comic *&gt;(BookArray[i]) != NULL) {
        cp = dynamic_cast&lt;Comic *&gt;(BookArray[i]);
        if ((cp-&gt;getBookKind() == BookKind) &amp;&amp; (cp-&gt;getBookCode() == BookCode)) {
            return BookArray[i];
        }
    }
}
return NULL;</code></pre><p>}</p>
<p>RentBookList &amp;BookManage::getRentBookList() {
    return this-&gt;List;
}</p>
<p>//RentBookList.h
#pragma once
#include &quot;Rent.h&quot;
#include &quot;Person.h&quot;
#define bMax 10 
class RentBookList {
private:
    Rent * RentArray[bMax] = { NULL, };
public:
    RentBookList();
    ~RentBookList();
    Rent ** getRentArray();
    // int getPersonId(Person &amp;rp);
};</p>
<p>//RentBookList.cpp
#include &quot;BookManage.h&quot;
#include &quot;PersonManage.h&quot;
#include &quot;Rent.h&quot;
#include &quot;RentBookList.h&quot;</p>
<p>RentBookList::RentBookList()
{}
RentBookList::~RentBookList()
{}
Rent ** RentBookList::getRentArray()
{
    return RentArray;
}
//int RentBookList::getPersonId(Person &amp;rp)
//{
//    return Personid;
//}</p>
<p>//main.cpp
#include <iostream>
using namespace std;
#include <string>
#define MASTER 1111 // 관리자 아이디
#define bMax 10
#pragma warning (disable : 4996)</p>
<p>#include &quot;BookManage.h&quot;
#include &quot;PersonManage.h&quot;
#include &quot;Book.h&quot;
#include &quot;Person.h&quot;
#include &quot;Novel.h&quot;
#include &quot;MajorBook.h&quot;
#include &quot;Comic.h&quot;
#include &quot;RentBookList.h&quot;
#include <ctime></p>
<p>void PersonLogin(PersonManage &amp;Pm, BookManage &amp;Bm); // 관리자, 사용자 로그인</p>
<p>void masterMenu(PersonManage &amp;Pm, BookManage &amp;Bm); // 관리자 메뉴</p>
<p>void addbook(BookManage &amp;Bm); // 책 추가</p>
<p>void deletebook(BookManage &amp;Bm); // 책 삭제</p>
<p>void rentlist(PersonManage &amp;Pm, BookManage &amp;Bm); // 대출자 명단</p>
<p>void normalMenu(Person *p, BookManage &amp;Bm); // 사용자 메뉴</p>
<p>void rentbook(int id, BookManage &amp;Bm); // 책 대출</p>
<p>void returnbook(int id, BookManage &amp;Bm); // 책 반납</p>
<p>void myrentlist(int id, BookManage &amp;Bm); // 나의 대출 목록</p>
<p>void findbook(BookManage &amp;Bm); // 단일 책 검색</p>
<p>void allbook(BookManage &amp;Bm); // 책 목록 전체 보기</p>
<p>void PersonRegist(PersonManage &amp;Pm); // 사용자 추가</p>
<p>void PersonDelete(PersonManage &amp;Pm); // 사용자 삭제</p>
<p>int menu(const char **menuList, int menuCnt);</p>
<p>void displayTitle(const char *title);</p>
<p>int controlMenuSelect(const char *message, int menuCnt);</p>
<p>int inputInteger(const char *message);</p>
<p>void myFlush();</p>
<p>int main() {
    BookManage bmanage;
    PersonManage pmanage;</p>
<pre><code>const char *menuList[] = { &quot;로그인 &quot;, &quot;사용자 등록 &quot;, &quot;사용자 삭제 &quot;, &quot;종료 &quot; };
int menuCnt = sizeof(menuList) / sizeof(menuList[0]);
int menuNum;

displayTitle(&quot;도서 관리 시스템 시작&quot;);
while (true)
{
    menuNum = menu(menuList, menuCnt);
    if (menuNum == menuCnt) { break; }
    switch (menuNum)
    {
    case 1: PersonLogin(pmanage, bmanage); break;
    case 2:    PersonRegist(pmanage); break;
    case 3:    PersonDelete(pmanage); break;
    }
}
displayTitle(&quot;도서 관리 시스템 종료&quot;);
return 0;</code></pre><p>}</p>
<p>int menu(const char <em>*menuList, int menuCnt)
{
    int i;
    int menuNum = 0; /</em> 입력된 메뉴 번호 저장 변수*/</p>
<pre><code>cout &lt;&lt; endl &lt;&lt; &quot;==================================&quot; &lt;&lt; endl;
for (i = 0; i &lt; menuCnt; i++)
{
    cout &lt;&lt; i + 1 &lt;&lt; &quot;.&quot; &lt;&lt; menuList[i] &lt;&lt; endl;
}
cout &lt;&lt; &quot;==================================&quot; &lt;&lt; endl;
while (menuNum&lt;1 || menuNum&gt;menuCnt)  /* 범위 내의 번호가 입력될 때 까지 반복*/
{
    menuNum = inputInteger(&quot;# 메뉴번호를 입력하세요 : &quot;);

}
return menuNum;</code></pre><p>}</p>
<p>void displayTitle(const char *title)
{
    cout &lt;&lt; endl &lt;&lt; &quot;------------------------------&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;    &quot; &lt;&lt; title &lt;&lt; endl;
    cout &lt;&lt; &quot;------------------------------&quot; &lt;&lt; endl;
}</p>
<p>void PersonLogin(PersonManage &amp;Pm, BookManage &amp;Bm) {
    Person * p;
    int id;</p>
<pre><code>displayTitle(&quot;로그인&quot;);
id = inputInteger(&quot;* 사용자 학번 : &quot;);

if (id == MASTER) {
    cout &lt;&lt; &quot;로그인 되었습니다.&quot; &lt;&lt; endl;
    masterMenu(Pm, Bm);
}
else {
    p = Pm.findPerson(id);
    if (p == NULL) {
        cout &lt;&lt; &quot;존재하지 않는 입력입니다.&quot; &lt;&lt; endl;
        return;
    }
    cout &lt;&lt; &quot;로그인 되었습니다.&quot; &lt;&lt; endl;
    normalMenu(p, Bm);
}</code></pre><p>}</p>
<p>void masterMenu(PersonManage &amp;Pm, BookManage &amp;Bm) {</p>
<pre><code>const char *menuList[] = { &quot;책 추가 &quot;, &quot;책 삭제 &quot;, &quot;대출자 명단 &quot;, &quot;책 검색 &quot;, &quot;전체 목록 &quot;, &quot;종료 &quot; };
int menuCnt = sizeof(menuList) / sizeof(menuList[0]);
int menuNum;

displayTitle(&quot;관리자 모드 실행&quot;);
while (true)
{
    menuNum = menu(menuList, menuCnt);
    if (menuNum == menuCnt) { break; }
    switch (menuNum)
    {
    case 1: addbook(Bm); break;
    case 2:    deletebook(Bm); break;
    case 3:    rentlist(Pm, Bm); break;
    case 4: findbook(Bm); break;
    case 5: allbook(Bm); break;
    }
}
displayTitle(&quot;관리자 모드 종료&quot;);</code></pre><p>}</p>
<p>void addbook(BookManage &amp;Bm) {
    string BookName;
    string CpyName;
    int num;
    Book *ap = NULL;
    bool res;</p>
<pre><code>displayTitle(&quot;책 등록&quot;);

cout &lt;&lt; &quot;* 책 제목 : &quot;;
cin &gt;&gt; BookName;
cout &lt;&lt; &quot;* 책 출판사 : &quot;;
cin &gt;&gt; CpyName;
num = controlMenuSelect(&quot;* 책의 종류(1. 소설 / 2. 전공서적 / 3. 만화) : &quot;, 3);

switch (num) {
case 1: ap = new Novel(BookName, CpyName, &#39;N&#39;); break;
case 2: ap = new MajorBook(BookName, CpyName, &#39;M&#39;); break;
case 3: ap = new Comic(BookName, CpyName, &#39;C&#39;); break;
}

res = Bm.addBook(ap);
if (res)
{
    cout &lt;&lt; BookName &lt;&lt; &quot; 등록을 완료하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}
else
{
    cout &lt;&lt; &quot;등록을 실패하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}</code></pre><p>}</p>
<p>void deletebook(BookManage &amp;Bm) {
    string BookName;
    bool res;</p>
<pre><code>displayTitle(&quot;책 삭제&quot;);

cout &lt;&lt; &quot;* 책 제목 : &quot;;
cin &gt;&gt; BookName;

res = Bm.deleteBook(BookName);
if (res)
{
    cout &lt;&lt; BookName &lt;&lt; &quot;이 삭제되었습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}
else
{
    cout &lt;&lt; &quot;삭제를 실패하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}</code></pre><p>}</p>
<p>void rentlist(PersonManage &amp;Pm, BookManage &amp;Bm) {
    displayTitle(&quot;대출자 명단&quot;);</p>
<pre><code>Rent **list;
list = Bm.getRentBookList().getRentArray();

for (int i = 0;i&lt; bMax;i++) {
    if (list[i] != NULL) {
        Person* a = Pm.findPerson(list[i]-&gt;Personid);
        Book * b = Bm.findBook(list[i]-&gt;BookKind, list[i]-&gt;BookCode);
        cout &lt;&lt; &quot;이름 : &quot; &lt;&lt; a-&gt;getPersonName() &lt;&lt; &quot;, 전공 : &quot; &lt;&lt; a-&gt;getMajor() &lt;&lt; &quot;, 학번 : &quot; &lt;&lt; a-&gt;getId() &lt;&lt; &quot; (&quot; &lt;&lt; b-&gt;getBookName() &lt;&lt; &quot; 대출날짜 : &quot; &lt;&lt; list[i]-&gt;startDay &lt;&lt; &quot;일)&quot; &lt;&lt; endl;
    }
}
cout &lt;&lt; endl;</code></pre><p>}</p>
<p>void normalMenu(Person *p, BookManage &amp;Bm) {</p>
<pre><code>const char *menuList[] = { &quot;대출 &quot;, &quot;반납 &quot;, &quot;대출명단 &quot;, &quot;책검색 &quot;,&quot;전체 목록 &quot;,&quot;종료 &quot; };
int menuCnt = sizeof(menuList) / sizeof(menuList[0]);
int menuNum;
int id = p-&gt;getId();

displayTitle(&quot;사용자 메뉴&quot;);
while (true)
{
    menuNum = menu(menuList, menuCnt);
    if (menuNum == menuCnt) { break; }
    switch (menuNum)
    {
    case 1: rentbook(id, Bm); break;
    case 2:    returnbook(id, Bm); break;
    case 3:    myrentlist(id, Bm); break;
    case 4: findbook(Bm); break;
    case 5: allbook(Bm); break;
    }
}
displayTitle(&quot;사용자 메뉴 종료&quot;);</code></pre><p>}</p>
<p>void rentbook(int id, BookManage &amp;Bm) {
    displayTitle(&quot;대출&quot;);</p>
<pre><code>string bookname;

char ch;
int n;
Rent **list;
list = Bm.getRentBookList().getRentArray();

cout &lt;&lt; &quot;* 책 제목 : &quot;;
cin &gt;&gt; bookname;
for (int i = 0; i &lt; Bm.BookCnt;i++) {
    if (Bm.getBookArray()[i]-&gt;getBookName() == bookname) {
        cout &lt;&lt; &quot;* 책 코드 : &quot;;
        cin &gt;&gt; ch &gt;&gt; n;

        Book * b = Bm.findBook(ch, n);

        if (b != NULL) {
            if (b-&gt;getBookName() != bookname) {
                cout &lt;&lt; &quot;대출이 불가능합니다.&quot; &lt;&lt; endl;
                return;
            }
            for (int i = 0; i &lt; Bm.BookCnt;i++) {
                if (list[i] != NULL) {
                    //cout &lt;&lt; list[i]-&gt;BookKind &lt;&lt; list[i]-&gt;BookCode &lt;&lt; endl;
                    if (list[i]-&gt;BookKind == ch &amp;&amp; list[i]-&gt;BookCode == n) {
                        cout &lt;&lt; &quot;대출이 불가능합니다.&quot; &lt;&lt; endl;
                        return;
                    }
                }
            }
        }
        else {
            cout &lt;&lt; &quot;대출이 불가능합니다.&quot; &lt;&lt; endl;
            return;
        }
        // 도서관에도 책이 있고, 대출도서명단에 책이 없을때, 즉, 대출 가능
        time_t day = time(NULL);
        for (int i = 0;i &lt; Bm.BookCnt;i++) {
            if (list[i] == NULL) {
                time_t timer;
                struct tm *t;
                timer = time(NULL); // 현재 시각을 초 단위로 얻기
                t = localtime(&amp;timer);
                list[i] = new Rent;
                list[i]-&gt;BookKind = ch;
                list[i]-&gt;BookCode = n;
                list[i]-&gt;Personid = id;
                list[i]-&gt;startDay = t-&gt;tm_mday;
                cout &lt;&lt; &quot;대출이 완료되었습니다.&quot; &lt;&lt; endl;
                b-&gt;setflag(true);
                break;
            }
        }
        return;
    }
}
cout &lt;&lt; &quot;대출이 불가능합니다.&quot; &lt;&lt; endl;</code></pre><p>}</p>
<p>void returnbook(int id, BookManage &amp;Bm) {
    displayTitle(&quot;반납&quot;);</p>
<pre><code>string bookname;
char ch;
int n;
int num = 0;
Rent **list;
list = Bm.getRentBookList().getRentArray();

cout &lt;&lt; &quot;* 책 제목 : &quot;;
cin &gt;&gt; bookname;

for (int i = 0; i &lt; Bm.BookCnt;i++) {
    if (Bm.getBookArray()[i]-&gt;getBookName() == bookname) {
        cout &lt;&lt; &quot;* 책 코드 : &quot;;
        cin &gt;&gt; ch &gt;&gt; n;

        Book * b = Bm.findBook(ch, n);

        if (b != NULL) {
            if (b-&gt;getBookName() != bookname) {
                cout &lt;&lt; &quot;반납이 불가능합니다.&quot; &lt;&lt; endl;
                return;
            }
        }
        // rent 배열 한칸씩 앞으로 떙기는 작업
        for (int i = 0; i &lt; Bm.BookCnt;i++) {
            if (list[i] != NULL) {
                if (list[i]-&gt;Personid == id) {
                    if (list[i]-&gt;BookKind == ch &amp;&amp; list[i]-&gt;BookCode == n) {
                        // memset(list[i], 0, sizeof(Rent));
                        delete list[i];
                        for (i; i &lt; Bm.BookCnt - 1; i++)
                        {
                            list[i] = list[i + 1];
                            if (i == Bm.BookCnt - 2)
                            {
                                // memset(list[i], 0, sizeof(Rent));
                                // delete list[Bm.BookCnt - 1];
                                list[Bm.BookCnt - 1] = NULL;
                            }
                        }
                        cout &lt;&lt; &quot;반납이 완료되었습니다.&quot; &lt;&lt; endl;
                        b-&gt;setflag(false);
                        return;
                    }
                    else {
                        cout &lt;&lt; &quot;반납이 불가능합니다.&quot; &lt;&lt; endl;
                        return;
                    }
                }
            }
        }
        cout &lt;&lt; &quot;반납이 불가능합니다.&quot; &lt;&lt; endl;
        return;
    }
}</code></pre><p>}</p>
<p>void myrentlist(int id, BookManage &amp;Bm) {
    displayTitle(&quot;나의 대출 책 목록&quot;);
    Book * b;
    Rent **list;
    list = Bm.getRentBookList().getRentArray();
    for (int i = 0; i &lt; Bm.BookCnt;i++) {
        if (list[i] != NULL) {
            //cout &lt;&lt; list[i]-&gt;Personid &lt;&lt; &quot; &quot; &lt;&lt; id &lt;&lt; endl;
            if (list[i]-&gt;Personid == id) {
                b = Bm.findBook(list[i]-&gt;BookKind, list[i]-&gt;BookCode);
                cout &lt;&lt; &quot;제목 : &quot; &lt;&lt; b-&gt;getBookName() &lt;&lt; &quot;, 코드 : &quot; &lt;&lt; list[i]-&gt;BookKind &lt;&lt; list[i]-&gt;BookCode &lt;&lt; &quot; (대출 날짜 : &quot; &lt;&lt; list[i]-&gt;startDay &lt;&lt; &quot;일)&quot; &lt;&lt; endl;
            }
        }
    }
}</p>
<p>void findbook(BookManage &amp;Bm) {
    displayTitle(&quot;책 검색&quot;);
    cout &lt;&lt; &quot;* 책제목을 입력하세요: &quot;;
    char sBookName[50];
    cin &gt;&gt; sBookName;
    for (int i = 0; i &lt; Bm.BookCnt; i++) {
        if (Bm.getBookArray()[i]-&gt;getBookName() == sBookName) {
            Bm.getBookArray()[i]-&gt;infoView();
        }
    }
}</p>
<p>void allbook(BookManage &amp;Bm) {
    displayTitle(&quot;전체 목록&quot;);
    for (int i = 0; i &lt; Bm.BookCnt; i++) {
        cout &lt;&lt; i + 1 &lt;&lt; &quot;. &quot;;
        Bm.getBookArray()[i]-&gt;infoView();
    }
}</p>
<p>int controlMenuSelect(const char *message, int menuCnt)
{
    int menuNum;</p>
<pre><code>while (true)
{
    menuNum = inputInteger(message);
    if (menuNum &gt; 0 &amp;&amp; menuNum &lt;= menuCnt) { break; }
}
return menuNum;</code></pre><p>}</p>
<p>void PersonRegist(PersonManage &amp;Pm) {
    string personName;
    string major;
    int id;
    Person *ap = NULL;
    bool res;</p>
<pre><code>displayTitle(&quot;사용자 등록하기&quot;);

cout &lt;&lt; &quot;* 사용자 이름 : &quot;;
cin &gt;&gt; personName;
cout &lt;&lt; &quot;* 사용자 전공 : &quot;;
cin &gt;&gt; major;
id = inputInteger(&quot;* 사용자 학번 : &quot;);

ap = new Person(personName, id, major);

res = Pm.addPerson(ap);
if (res)
{
    cout &lt;&lt; personName &lt;&lt; &quot;님의 등록을 완료하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}
else
{
    cout &lt;&lt; &quot;등록을 실패하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}</code></pre><p>}</p>
<p>void PersonDelete(PersonManage &amp;Pm)
{
    string personName;
    bool res;</p>
<pre><code>displayTitle(&quot;사용자 탈퇴하기&quot;);

cout &lt;&lt; &quot;* 사용자 이름 : &quot;;
cin &gt;&gt; personName;

res = Pm.deletePerson(personName);
if (res)
{
    cout &lt;&lt; personName &lt;&lt; &quot;님의 정보가 삭제되었습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}
else
{
    cout &lt;&lt; &quot;탈퇴를 실패하였습니다.&quot; &lt;&lt; endl &lt;&lt; endl;
}</code></pre><p>}</p>
<p>int inputInteger(const char *message)
{
    int number;</p>
<pre><code>while (1) {
    cout &lt;&lt; message;
    cin &gt;&gt; number;

    if (cin.get() == &#39;\n&#39;) {
        return number;
    }

    myFlush();
}</code></pre><p>}</p>
<p>void myFlush()
{
    cin.clear();
    while (cin.get() != &#39;\n&#39;);
}</p>
<p>```
<img src="https://images.velog.io/images/hyeonu_chun/post/7e6f8335-d581-4245-97b4-e5af227206db/%EC%A0%9C%EB%AA%A9%20%EC%97%86%EC%9D%8C2.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-13]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-13</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-13</guid>
            <pubDate>Mon, 21 Jun 2021 04:03:56 GMT</pubDate>
            <description><![CDATA[<h1 id="hw16">HW16</h1>
<pre><code>//Happy.h
#pragma once
#include &lt;string&gt;
using namespace std;

class Happy {
private:
    string name;
    int money;
    char *list[100] = { NULL, };
    int index;
public:
    Happy(string np = &quot;&quot;, int money = 10000);
    Happy(Happy &amp;r);
    ~Happy();
    Happy &amp;operator=(Happy &amp;r);
    void use(char *lp, int n);
    Happy &amp;winner(Happy &amp;r);
    void setName(string &amp;name);
    string &amp;getName();
    void setMoney(int money);
    int getMoney();
    char **getList();
    int getIndex();
};
//Happy.cpp
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &quot;Happy.h&quot;
#pragma warning (disable : 4996)
using namespace std;

Happy::Happy(string np, int n) {
    this-&gt;name = np;
    this-&gt;money = n;
    this-&gt;index = 0;
}

Happy::Happy(Happy &amp;r) {
    int i = 0;
    this-&gt;name = r.name;
    this-&gt;money = r.money;
    this-&gt;index = r.index;
    while (r.list[i] != NULL) {
        this-&gt;list[i] = new char[strlen(r.list[i]) + 1];
        strcpy(this-&gt;list[i], r.list[i]);
        i++;
    }
}

Happy::~Happy() {
    int i = 0;
    while (this-&gt;list[i] != NULL) {
        delete[] this-&gt;list[i];
        i++;
    }
}

Happy &amp;Happy::operator=(Happy &amp;r) {
    int i = 0;
    this-&gt;name = r.name;
    this-&gt;money = r.money;
    this-&gt;index = r.index;
    while (r.list[i] != NULL) {
        this-&gt;list[i] = new char[strlen(r.list[i]) + 1];
        strcpy(this-&gt;list[i], r.list[i]);
        i++;
    }
    return *this;
}

void Happy::use(char *lp, int n) {
    int i = 0;
    int len = strlen(lp) + 2;
    if (this-&gt;money &gt;= n) {
        this-&gt;money -= n;
    }
    else cout &lt;&lt; &quot;잔액이 부족합니다.&quot; &lt;&lt; endl;
    this-&gt;index++;
    while (1) {
        if (this-&gt;list[i] == NULL) {
            this-&gt;list[i] = new char[len];
            strcpy(this-&gt;list[i], lp);
            break;
        }
        else i++;
    }
}

Happy &amp;Happy::winner(Happy &amp;r) {
    if (this-&gt;money &gt; r.money) {
        return *this;
    }
    else {//if (this-&gt;money &lt; r.money) {
        return r;
    }
    //else return Happy();
}

void Happy::setName(string &amp;name) {
    this-&gt;name = name;
}

string &amp;Happy::getName() {
    return this-&gt;name;
}

void Happy::setMoney(int money) {
    this-&gt;money = money;
}

int Happy::getMoney() {
    return this-&gt;money;
}

char **Happy::getList() {
    return this-&gt;list;
}

int Happy::getIndex() {
    return this-&gt;index;
}
//HW16.cpp
#include &lt;iostream&gt;
#include &quot;Happy.h&quot;
#pragma warning (disable : 4996)
using namespace std;

int main() {
    Happy a(&quot;철이&quot;), b(&quot;메텔&quot;), w;
    char item[100];
    int price;

    cout &lt;&lt; &quot;철이가 돈을 씁니다...&quot; &lt;&lt; endl;
    while (1) {
        cout &lt;&lt; &quot;구입 내역 : &quot;;
        cin &gt;&gt; item;
        if (strcmp(item, &quot;끝&quot;) == 0)break;
        cout &lt;&lt; &quot;금액 입력 : &quot;;
        cin &gt;&gt; price;
        a.use(item, price);
    }

    cout &lt;&lt; &quot;\n메텔이 돈을 씁니다...&quot; &lt;&lt; endl;
    while (1) {
        cout &lt;&lt; &quot;구입 내역 : &quot;;
        cin &gt;&gt; item;
        if (strcmp(item, &quot;끝&quot;) == 0)break;
        cout &lt;&lt; &quot;금액 입력 : &quot;;
        cin &gt;&gt; price;
        b.use(item, price);
    }

    cout &lt;&lt; &quot;\n최종 승자는?&quot; &lt;&lt; endl;
    w = a.winner(b);
    cout &lt;&lt; w.getName() &lt;&lt; &quot;이고 총 &quot; &lt;&lt; w.getIndex() &lt;&lt; &quot;건을 사용하고 남은 금액은 &quot; &lt;&lt; w.getMoney() &lt;&lt; &quot;원 입니다.&quot; &lt;&lt; endl;

    int i = 0;
    cout &lt;&lt; &quot;사용 내역 : &quot;;
    while (w.getList()[i]) {
        cout &lt;&lt; w.getList()[i] &lt;&lt; &quot; &quot;;
        i++;
    }
    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-12]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-12</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-12</guid>
            <pubDate>Mon, 21 Jun 2021 04:02:37 GMT</pubDate>
            <description><![CDATA[<h1 id="hw13">HW13</h1>
<pre><code>#include &lt;iostream&gt;
using namespace std;

class Time {
private:
    int hour;
    int min;
    double time;
    static int mode;
    enum { integer, real };
public:
    Time();
    Time(int, int);
    Time(double);
    Time(const Time &amp;tr);
    Time plus(const Time &amp;tr);
    void setHour(int);
    int getHour();
    void setMin(int);
    int getMin();
    int getMode();
    friend ostream &amp;operator&lt;&lt;(ostream &amp;os, const Time &amp;br);
    static void mode_change();
};

int Time::mode = integer;

Time::Time() {
    this-&gt;hour = 0;
    this-&gt;min = 0;
    this-&gt;time = 0.0;
}

Time::Time(int hour,int min) {
    this-&gt;hour = hour;
    this-&gt;min = min;
    this-&gt;time = hour + double(min) / 60;
}

Time::Time(double time) {
    this-&gt;hour = int(time);
    this-&gt;min = int((time - int(time)) * 60);
    this-&gt;time = time;
}

Time::Time(const Time &amp;tr) {
    this-&gt;hour = tr.hour;
    this-&gt;min = tr.min;
    this-&gt;time = tr.time;
}

Time Time::plus(const Time &amp;tr){
    int sum = this-&gt;min + tr.min;
    this-&gt;hour += tr.hour;
    if (sum &gt;= 60) {
        this-&gt;hour++;
        this-&gt;min = sum - 60
;
    }
    this-&gt;time = this-&gt;hour + double(this-&gt;min) / 60;
    return *this;
}

void Time::setHour(int hour) {
    this-&gt;hour = hour;
}

int Time::getHour() {
    return this-&gt;hour;
}

void Time::setMin(int min) {
    this-&gt;min = min;
}

int Time::getMin() {
    return this-&gt;min;
}

int Time::getMode() {
    return this-&gt;mode;
}

void Time::mode_change() {
    mode = (mode + real) % 2;
}

ostream &amp;operator&lt;&lt;(ostream &amp;os, Time &amp;br);

int main() {
    Time a(3, 21);
    Time b(2.7);
    cout &lt;&lt; &quot;기본 출력 형태(시간, 분)...&quot; &lt;&lt; endl;
    cout &lt;&lt; a &lt;&lt; endl;
    cout &lt;&lt; b &lt;&lt; endl;
    Time::mode_change();
    cout &lt;&lt; &quot;출력모드를 바꾼 후...&quot; &lt;&lt; endl;
    cout &lt;&lt; a &lt;&lt; endl;
    cout &lt;&lt; b &lt;&lt; endl;
    return 0;
}

ostream &amp;operator&lt;&lt;(ostream &amp;os, Time &amp;br) {
    double time = br.getHour() + double(br.getMin()) / 60;
    if (br.getMode() == 0) {
        os &lt;&lt; br.getHour() &lt;&lt; &quot;시간 &quot; &lt;&lt; br.getMin() &lt;&lt; &quot;분&quot;;
    }
    else {
        os &lt;&lt; time &lt;&lt; &quot;시간&quot;;
    }
    return os;
}</code></pre><h1 id="hw14">HW14</h1>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#pragma warning (disable : 4996)
using namespace std;

class MyString {
private:
    char *str;
    int len;
public:
    MyString();
    MyString(const char*cp);
    MyString(const MyString &amp;br);
    ~MyString();
    MyString &amp;operator=(const MyString &amp;br);
    MyString operator+(const MyString &amp;br);
    bool operator&gt;(const MyString &amp;br);
    friend ostream &amp;operator&lt;&lt;(ostream &amp;os, MyString &amp;br);
    friend istream &amp;operator&gt;&gt;(istream &amp;is, MyString &amp;br);
    void setStr(const char *cp);
    char *getStr() const;
    int getLen() const;
};

ostream &amp;operator&lt;&lt;(ostream &amp;os, MyString &amp;br);
istream &amp;operator&gt;&gt;(istream &amp;is, MyString &amp;br);

MyString::MyString() {
    this-&gt;str = new char[strlen(&quot;&quot;) + 1];
    strcpy(this-&gt;str, &quot;&quot;); // this-&gt;str = &quot;&quot;; string 영역(상수영역)의 null string을 가리킴
    this-&gt;len = 0;
}

MyString::MyString(const char *cp) {
    this-&gt;len = strlen(cp);
    this-&gt;str = new char[this-&gt;len + 1];
    strcpy(this-&gt;str, cp);
}

MyString::MyString(const MyString &amp;br) {
    this-&gt;len = br.len;
    this-&gt;str = new char[this-&gt;len + 1];
    strcpy(this-&gt;str, br.str);
}

MyString::~MyString() {
    delete[] this-&gt;str;
}

MyString &amp;MyString::operator=(const MyString &amp;br) {
    if (this == &amp;br) { // **** 나 - 나 방지코드
        return *this;
    }
    delete[] this-&gt;str;
    this-&gt;len = br.len;
    this-&gt;str = new char[this-&gt;len + 1];
    strcpy(this-&gt;str, br.str);
    return *this;
}

MyString MyString::operator+(const MyString &amp;br) {
    char temp[100] = &quot;&quot;;
    strcpy(temp, this-&gt;str);
    strcat(temp, br.str);
    return MyString(temp);
    //char *cp;
    //cp = new char[this-&gt;len + br.len + 1];
    //strcpy(cp, this-&gt;str);
    //strcat(cp, br.str);
    //MyString temp(cp);
    //delete[] cp;
    //return temp;
}

bool MyString::operator&gt;(const MyString &amp;br) {
    //return (this-&gt;len &gt; br.len); // 길이 비교
    return strcmp(this-&gt;str, br.str); // 스펠링 비교
}

void MyString::setStr(const char *cp) {
    if (this-&gt;str == cp) { // 본인의 문자열로 초기화시키려 할때
        return;
    }
    this-&gt;len = strlen(cp);
    delete[] this-&gt;str;
    this-&gt;str = new char[this-&gt;len + 1];
    strcpy(this-&gt;str, cp);
}

char *MyString::getStr() const{
    return this-&gt;str;
}

int MyString::getLen() const{
    return this-&gt;len;
}

int main() {
    MyString ary[5];
    MyString res;
    cout &lt;&lt; &quot;5개의 과일이름 입력 : &quot;;
    for (int i = 0;i &lt; 5;i++) {
        cin &gt;&gt; ary[i];
    }
    cout &lt;&lt; &quot;첫번째와 두번째 중 긴 과일 이름 : &quot;;
    if (ary[0] &gt; ary[1]) {
        cout &lt;&lt; ary[0] &lt;&lt; endl;
    }
    else {
        cout &lt;&lt; ary[1] &lt;&lt; endl;
    }
    res = ary[0] + ary[1] + ary[2] + ary[3] + ary[4];
    cout &lt;&lt; &quot;모든 문자열 출력 : &quot; &lt;&lt; res &lt;&lt; endl;
    cout &lt;&lt; &quot;배열내의 문자열 출력...&quot; &lt;&lt; endl;
    for (int i = 0;i &lt; 5;i++) {
        cout &lt;&lt; ary[i] &lt;&lt; endl;
    }
    for (int i = 0;i &lt; 5;i++) {
        ary[i].setStr(&quot;abc&quot;);
        cout &lt;&lt; ary[i].getStr();
        cout &lt;&lt; ary[i].getLen();
    }
    return 0;
}

ostream &amp;operator&lt;&lt;(ostream &amp;os, MyString &amp;br) {
    os &lt;&lt; br.str &lt;&lt; &quot;(&quot; &lt;&lt; br.len &lt;&lt; &quot;)&quot; &lt;&lt; endl;
    return os;
}

istream &amp;operator&gt;&gt;(istream &amp;is, MyString &amp;br) { // *****
    char temp[5000];
    is &gt;&gt; temp;
    delete[] br.str;
    br.len = strlen(temp);
    br.str = new char[br.len + 1];
    strcpy(br.str, temp);
    return is;
}

//int main() {
//    char temp[1000];
//    char str1[20] = &quot;apple &quot;;
//    char str2[20] = &quot;pie&quot;;
//
//    strcpy(temp, str1); // temp : &quot;apple &quot;
//    strcat(temp, str2); // temp의 \0 자리에서부터 str2를 붙임
//    cout &lt;&lt; temp &lt;&lt; &quot;&quot; &lt;&lt; str1 &lt;&lt; &quot;&quot; &lt;&lt; str2 &lt;&lt; endl;
//
//    char temp2[1000] = &quot;&quot;;
//    strcat(temp2, str1); // temp : &quot;apple &quot;
//    strcat(temp2, str2); // temp의 \0 자리에서부터 str2를 붙임
//    cout &lt;&lt; temp2 &lt;&lt; &quot;&quot; &lt;&lt; str1 &lt;&lt; &quot;&quot; &lt;&lt; str2 &lt;&lt; endl;
//}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-11]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-11</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-11</guid>
            <pubDate>Mon, 21 Jun 2021 04:01:28 GMT</pubDate>
            <description><![CDATA[<h1 id="hw15">HW15</h1>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#pragma warning (disable : 4996)
using namespace std;

// Fitness.h
class Fitness {
private:
    int num;
    char *name;
    double weight;
    double height;
public:
    // 생성자
    Fitness();
    Fitness(int num, const char *name, double weight, double height);
    Fitness(Fitness &amp;r);
    ~Fitness();
    // 연산자
    Fitness &amp;operator=(Fitness &amp;r);
    bool operator==(Fitness &amp;r);
    // setter, getter
    void setNum(int num);
    int getNum();
    void setName(const char *name);
    char *getName();
    void setWeight(double weight);
    double getWeight();
    void setHeight(double height);
    double getHeight();
    // 기타멤버함수
    double bmi();
};

// Fitness.cpp
Fitness::Fitness() {
    this-&gt;num = 0;
    this-&gt;name = new char[1];
    strcpy(this-&gt;name, &quot;&quot;);
    this-&gt;weight = 0;
    this-&gt;height = 0;
}

Fitness::Fitness(int num, const char *name, double weight, double height) {
    if (this-&gt;name != NULL) {
        if (name != NULL) {
            this-&gt;name = new char[strlen(name) + 1];
            strcpy(this-&gt;name, name);
        }
    }
    else return;
    this-&gt;num = num;
    this-&gt;weight = weight;
    this-&gt;height = height;
}

Fitness::Fitness(Fitness &amp;r) {
    if (name != NULL) {
        this-&gt;name = new char[strlen(r.name) + 1];
        strcpy(this-&gt;name, r.name);
    }
    else return;
    this-&gt;num = r.num;
    this-&gt;weight = r.weight;
    this-&gt;height = r.height;
}

Fitness::~Fitness() {
    if (name != NULL) {
        strcpy(this-&gt;name, &quot;&quot;);
        delete[] this-&gt;name;
    }
    else return;
    this-&gt;num = 0;
    this-&gt;weight = 0;
    this-&gt;height = 0;
    //cout &lt;&lt; &quot;소멸 성공&quot; &lt;&lt; endl;
}

Fitness &amp;Fitness::operator=(Fitness &amp;r) {
    if (*this == r) return *this;
    strcpy(this-&gt;name, &quot;&quot;);
    delete[] this-&gt;name;
    this-&gt;name = new char[strlen(r.name) + 1];
    strcpy(this-&gt;name, r.name);
    this-&gt;num = r.num;
    this-&gt;weight = r.weight;
    this-&gt;height = r.height;
    return *this;
}

bool Fitness::operator==(Fitness &amp;r) {
    if (this-&gt;num == r.num) {
        return 1;
    }
    if (r.name != NULL) {
        if (strcmp(this-&gt;name, r.name) == 0) {
            return 1;
        }
    }
    return 0;
}

void Fitness::setNum(int num) {
    this-&gt;num = num;
}

int Fitness::getNum() {
    return this-&gt;num;
}

void Fitness::setName(const char *name) {
    if (this-&gt;name != NULL) {
        if (name != NULL) {
            strcpy(this-&gt;name, &quot;&quot;);
            delete[] this-&gt;name;
            this-&gt;name = new char[strlen(name) + 1];
            strcpy(this-&gt;name, name);
        }
    }
}

char *Fitness::getName() {
    return this-&gt;name;
}

void Fitness::setWeight(double weight) {
    this-&gt;weight = weight;
}

double Fitness::getWeight() {
    return this-&gt;weight;
}

void Fitness::setHeight(double height) {
    this-&gt;height = height;
}

double Fitness::getHeight() {
    return this-&gt;height;
}

double Fitness::bmi() {
    return this-&gt;weight / (this-&gt;height * this-&gt;height) * 10000;
}

// main.cpp
int menu(const char **menuList, int menuCnt);
void memInput(Fitness **br, int &amp;memNum, int &amp;memCnt, int &amp;dataCnt);
void memPrint(Fitness **br, int memCnt);
void memFind(Fitness **br, int memCnt);
void memDelete(Fitness **br, int &amp;memNum, int &amp;memCnt, int &amp;dataCnt);
void memBmi(Fitness **br, int &amp;memCnt);
void myflush();

int main() {
    const char *menuList[] = { &quot;회원등록&quot;, &quot;회원전체보기&quot;, &quot;회원정보검색&quot;, &quot;회원탈퇴&quot; , &quot;특별관리회원&quot;,&quot;종료&quot; };
    int menuCnt, menuNum, memNum = 1, memCnt = 0, dataCnt = 0;

    Fitness *fary[100] = { 0, };

    menuCnt = sizeof(menuList) / sizeof(menuList[0]);

    while(1)
    {
        menuNum = menu(menuList, menuCnt);
        if (menuNum == menuCnt)
        {
            break;
        }
        switch (menuNum)
        {
        case 1: memInput(fary, memNum, memCnt, dataCnt); cout &lt;&lt; endl; break;
        case 2: memPrint(fary, memCnt); cout &lt;&lt; endl;  break;
        case 3: memFind(fary, memCnt); cout &lt;&lt; endl;  break;
        case 4: memDelete(fary, memNum, memCnt, dataCnt); cout &lt;&lt; endl; break;
        case 5: memBmi(fary, memCnt); cout &lt;&lt; endl; break;
        }
    }
    for (int i = 0;i &lt; dataCnt;i++) {
        delete[] fary[i];
    }
    return 0;
}

int menu(const char **menuList, int menuCnt)
{
    int menuNum = 0;
    for (int i = 0; i &lt; menuCnt; i++)
    {
        cout &lt;&lt; i + 1 &lt;&lt; &quot;.&quot; &lt;&lt; menuList[i] &lt;&lt; &quot; / &quot;;
    }
    cout &lt;&lt; &quot;\b\b \n&quot;;
    while (menuNum&lt;1 || menuNum&gt;menuCnt)
    {
        cout &lt;&lt; &quot;# 메뉴번호를 입력하세요 : &quot;;
        cin &gt;&gt; menuNum;
        while (cin.fail()) {
            cin.clear();
            myflush();
            cout &lt;&lt; &quot;* 잘못된 메뉴번호 입니다.&quot; &lt;&lt; endl &lt;&lt; &quot;# 메뉴번호를 입력하세요 : &quot;;
            cin &gt;&gt; menuNum;
        }
        myflush();
    }
    return menuNum;
}

void memInput(Fitness **br, int &amp;memNum, int &amp;memCnt, int &amp;dataCnt) {
    double weight, height;
    char temp[30];
    cout &lt;&lt; &quot;\n* 회원 입력 메뉴&quot; &lt;&lt; endl;
    while (1) {
        cout &lt;&lt; &quot;\n회원 성명(종료) : &quot;;
        cin.getline(temp, sizeof(temp));
        if (strcmp(temp, &quot;종료&quot;) == 0) break;
        if (br[memCnt] == NULL) {
            br[memCnt] = new Fitness[1];
            br[memCnt]-&gt;setNum(memNum);
            dataCnt++;
        }
        cout &lt;&lt; &quot;회원 번호 : &quot; &lt;&lt; br[memCnt]-&gt;getNum() &lt;&lt; &quot;번&quot; &lt;&lt; endl;
        br[memCnt]-&gt;setName(temp);
        cout &lt;&lt; &quot;회원 몸무게(kg) : &quot;;
        cin &gt;&gt; weight;
        cout &lt;&lt; &quot;회원 키(cm) : &quot;;
        cin &gt;&gt; height;
        myflush();
        br[memCnt]-&gt;setWeight(weight);
        br[memCnt]-&gt;setHeight(height);
        memCnt++;
        memNum = memCnt + 1;
    }
}

void memPrint(Fitness **br, int memCnt) {
    cout &lt;&lt; &quot;\n* 회원 전체 보기&quot; &lt;&lt; endl &lt;&lt; endl;
    for (int i = 0;i &lt; memCnt;i++) {
        cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님, 키(cm) : &quot; &lt;&lt; br[i]-&gt;getHeight() &lt;&lt; &quot;, 몸무게(kg) : &quot; &lt;&lt; br[i]-&gt;getWeight() &lt;&lt; endl;
    }
}

void memFind(Fitness **br, int memCnt) {
    int num = 0;
    char temp[30];
    cout &lt;&lt; &quot;\n* 회원 정보 검색 메뉴&quot; &lt;&lt; endl &lt;&lt; &quot;\n회원 성명 : &quot;;
    cin &gt;&gt; temp;
    for (int i = 0;i &lt; memCnt;i++) {
        if (strcmp(br[i]-&gt;getName(), temp) == 0) {
            cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님, 키(cm) : &quot; &lt;&lt; br[i]-&gt;getHeight() &lt;&lt; &quot;, 몸무게(kg) : &quot; &lt;&lt; br[i]-&gt;getWeight() &lt;&lt; endl;
            num++;
        }
    }
    if (num == 0) cout &lt;&lt; &quot;* 등록되지 않은 회원입니다.&quot; &lt;&lt; endl;
}

void memDelete(Fitness **br, int &amp;memNum, int &amp;memCnt, int &amp;dataCnt) {
    int num;
    char temp[10];
    cout &lt;&lt; &quot;\n* 회원 탈퇴 메뉴&quot; &lt;&lt; endl;
    while (1) {
        cout &lt;&lt; &quot;\n회원 번호(종료) : &quot;;
        cin &gt;&gt; num;
        while (cin.fail()) {
            cin.clear();
            cin.getline(temp, sizeof(temp));
            if (strcmp(temp, &quot;종료&quot;) == 0) return;
            else {
                cout &lt;&lt; &quot;* 잘못된 회원번호 입니다.&quot; &lt;&lt; endl &lt;&lt; endl &lt;&lt; &quot;회원 번호 : &quot;;
                cin &gt;&gt; num;
            }
        }
        myflush();
        if (num &lt;= dataCnt) {
            int cnt = 0;
            for (int i = 0;i &lt; memCnt;i++) {
                if (br[i]-&gt;getNum() == num) {
                    cnt++;
                    cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님, 키(cm) : &quot; &lt;&lt; br[i]-&gt;getHeight() &lt;&lt; &quot;, 몸무게(kg) : &quot; &lt;&lt; br[i]-&gt;getWeight() &lt;&lt; endl;
                    cout &lt;&lt; &quot;* 삭제하시겠습니까?(네/아니오) : &quot;;
                    cin.getline(temp, sizeof(temp));
                    if (strcmp(temp, &quot;네&quot;) == 0) {
                        int num = br[i]-&gt;getNum();
                        cout &lt;&lt; &quot;삭제가 완료되었습니다.&quot; &lt;&lt; endl;
                        *br[i] = *br[memCnt - 1];
                        br[memCnt - 1]-&gt;setNum(num);
                        //delete[] br[memCnt - 1];
                        memCnt--;
                    }
                    else {
                        cout &lt;&lt; &quot;삭제가 취소되었습니다.&quot; &lt;&lt; endl;
                        break;
                    }
                }
            }
            if (cnt == 0)cout &lt;&lt; &quot;* 잘못된 회원번호 입니다.&quot; &lt;&lt; endl;;
        }
        else {
            cout &lt;&lt; &quot;* 잘못된 회원번호 입니다.&quot; &lt;&lt; endl;
        }
    }
}

void memBmi(Fitness **br, int &amp;memCnt) {
    cout &lt;&lt; &quot;\n* 특별 관리 회원 명단\n&quot;;
    for (int i = 0;i &lt; memCnt;i++) {
        int bmi = int(br[i]-&gt;bmi());
        if (bmi &gt;= 25) {
            if (bmi &lt; 30) { cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님의 BMI : &quot; &lt;&lt; bmi &lt;&lt; &quot; (과체중)&quot; &lt;&lt; endl; }
            else if (bmi &lt; 40) { cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님의 BMI : &quot; &lt;&lt; bmi &lt;&lt; &quot; (비만)&quot; &lt;&lt; endl; }
            else { cout &lt;&lt; br[i]-&gt;getNum() &lt;&lt; &quot;번 - &quot; &lt;&lt; br[i]-&gt;getName() &lt;&lt; &quot;님의 BMI : &quot; &lt;&lt; bmi &lt;&lt; &quot; (과도비만)&quot; &lt;&lt; endl; }
        }
    }
}

void myflush() {
    while (cin.get() != &#39;\n&#39;);
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-08]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-08</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-08</guid>
            <pubDate>Mon, 21 Jun 2021 04:00:27 GMT</pubDate>
            <description><![CDATA[<h1 id="hw10">HW10</h1>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#pragma warning (disable : 4996)
using namespace std;

class Time {
private:
    int hour;
    int min;
public:
    Time();
    Time(int, int);
    Time(double);
    Time(const Time &amp;tr);
    Time plus(const Time &amp;tr);
    void setHour(int);
    int getHour() const;
    void setMin(int);
    int getMin() const;
};

Time::Time(){
    this-&gt;hour = 0;
    this-&gt;min = 0;
}

Time::Time(int hour, int min) {
    this-&gt;hour = hour;
    this-&gt;min = min;
}

Time::Time(double time) {
    this-&gt;hour = int(time);
    this-&gt;min = int((time - double(this-&gt;hour)) * 60);
}

Time::Time(const Time &amp;tr) {
    this-&gt;hour = tr.hour;
    this-&gt;min = tr.min;
}

Time Time::plus(const Time &amp;tr) {
    this-&gt;hour += tr.getHour();
    this-&gt;min += tr.getMin();
    if (this-&gt;min &gt;= 60) {
        this-&gt;hour += this-&gt;min / 60;
        this-&gt;min %= 60;
    }
    return *this;
}

void Time::setHour(int hour) {
    this-&gt;hour = hour;
}

void Time::setMin(int min) {
    this-&gt;min = min;
}

int Time::getHour() const{
    return this-&gt;hour;
}

int Time::getMin() const{
    return this-&gt;min;
}

int main() {
    Time a(3, 20), b;
    cout &lt;&lt; a.getHour() &lt;&lt; &quot;시간&quot; &lt;&lt; a.getMin() &lt;&lt; &quot;분&quot; &lt;&lt; endl;
    b.setHour(4);
    b.setMin(42);
    cout &lt;&lt; b.getHour() &lt;&lt; &quot;시간&quot; &lt;&lt; b.getMin() &lt;&lt; &quot;분&quot; &lt;&lt; endl;
    Time res = a.plus(b);
    cout &lt;&lt; &quot;두 시간을 더하면 : &quot; &lt;&lt; res.getHour() &lt;&lt; &quot;시간&quot; &lt;&lt; res.getMin() &lt;&lt; &quot;분&quot; &lt;&lt; endl;
    return 0;
}</code></pre><h1 id="hw12">HW12</h1>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#pragma warning (disable : 4996)
using namespace std;

class Save {
private:
    char name[20];
    int capital;
    int profit;
    int tax;
    int tot;
    static double ratio;
public:
    static double tax_ratio;
    Save(const char *np = &quot;아무개&quot;, int n = 0);
    ~Save() {};
    void calculate();
    static void set_ratio(double r);
    char *getName() const;
    int getCap() const;
    int getPro() const;
    int getTax() const;
    int getTot() const;
    double getRat() const;
    double getTaxRat() const;
};

double Save::ratio = 0.2;
double Save::tax_ratio = 0.1;

Save::Save(const char *np, int n) {
    if (np != NULL) {
        strcpy(this-&gt;name, np);
    }
    this-&gt;capital = n;
}

void Save::calculate() {
    this-&gt;profit = int(this-&gt;capital * this-&gt;ratio);
    this-&gt;tax = int(this-&gt;profit * this-&gt;tax_ratio);
    this-&gt;tot = int(this-&gt;capital + this-&gt;profit - this-&gt;tax);
}

void Save::set_ratio(double r){
    Save::ratio = r;
}

char* Save::getName() const {
    cout &lt;&lt; &quot;이름 : &quot;;
    return (char*)(this-&gt;name);
}

int Save::getCap() const {
    cout &lt;&lt; endl &lt;&lt; &quot;원금 : &quot;;
    return this-&gt;capital;
}

int Save::getPro() const {
    cout &lt;&lt; endl &lt;&lt; &quot;이자소득 : &quot;;
    return this-&gt;profit;
}

int Save::getTax() const {
    cout &lt;&lt; endl &lt;&lt; &quot;세금 : &quot;;
    return this-&gt;tax;
}

int Save::getTot() const {
    cout &lt;&lt; endl &lt;&lt; &quot;총금액 : &quot;;
    return this-&gt;tot;
}

double Save::getRat() const {
    cout &lt;&lt; endl &lt;&lt; &quot;이율 : &quot;;
    return this-&gt;ratio;
}

double Save::getTaxRat() const {
    cout &lt;&lt; endl &lt;&lt; &quot;세율 : &quot;;
    return this-&gt;tax_ratio;
}

int main() {
    Save a(&quot;철이&quot;, 1000000), b(&quot;메텔&quot;, 2000000);
    a.calculate();
    cout &lt;&lt; a.getName();
    cout &lt;&lt; a.getCap();
    cout &lt;&lt; a.getPro(); 
    cout &lt;&lt; a.getTax();
    cout &lt;&lt; a.getTot();
    cout &lt;&lt; a.getRat();
    cout &lt;&lt; a.getTaxRat() &lt;&lt; endl &lt;&lt; endl;
    Save::tax_ratio = 0.15;
    Save::set_ratio(0.25);
    b.calculate();
    cout &lt;&lt; b.getName();
    cout &lt;&lt; b.getCap();
    cout &lt;&lt; b.getPro();
    cout &lt;&lt; b.getTax();
    cout &lt;&lt; b.getTot();
    cout &lt;&lt; b.getRat();
    cout &lt;&lt; b.getTaxRat() &lt;&lt; endl &lt;&lt; endl;
    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-07]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-07</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-07</guid>
            <pubDate>Mon, 21 Jun 2021 03:59:29 GMT</pubDate>
            <description><![CDATA[<h1 id="hw11">HW11</h1>
<pre><code>//Robot.h
#pragma once

class Robot {
private:
    char *name;
    int energy;
    void errPrn();
public:
    Robot();
    ~Robot();
    Robot(const char *name, int energy = 0);
    Robot(Robot &amp;r);
    void go();
    void back();
    void turn();
    void jump();
    void charge(int e);
    char *getName();
    void setName(const char *);
    int getEnergy();
    void setEnergy(int);
};
//Robot.cpp
#include &lt;iostream&gt;
#include &quot;Robot.h&quot;
using namespace std;
#pragma warning (disable : 4996)

void Robot::errPrn() {
    cout &lt;&lt; &quot;에너지 부족!&quot; &lt;&lt; endl;
}

Robot::Robot() {
    this-&gt;name = new char[1];
    strcpy(this-&gt;name, &quot;&quot;);
    this-&gt;energy = 0;
}

Robot::~Robot() {
    delete[] this-&gt;name;
}

Robot::Robot(const char *name, int energy) {
    this-&gt;name = new char[strlen(name) + 1];
    strcpy(this-&gt;name, name);
    this-&gt;energy = energy;
}

Robot::Robot(Robot &amp;r) {
    this-&gt;name = new char[strlen(r.name) + 1];
    strcpy(this-&gt;name, r.name);
    this-&gt;energy = r.energy;
}

// 전진 메세지 출력
void Robot::go() {
    if (this-&gt;energy &lt; 10) {
        this-&gt;errPrn();
    }
    else {
        cout &lt;&lt; this-&gt;name &lt;&lt; &quot;전진...&quot; &lt;&lt; endl &lt;&lt; endl;
        this-&gt;energy -= 10;
    }
}

// 후진 메세지 출력
void Robot::back() {
    if (this-&gt;energy &lt; 20) {
        this-&gt;errPrn();
    }
    else {
        cout &lt;&lt; this-&gt;name &lt;&lt; &quot;후진...&quot; &lt;&lt; endl &lt;&lt; endl;
        this-&gt;energy -= 20;
    }
}

// 턴 메세지 출력
void Robot::turn() {
    if (this-&gt;energy &lt; 30) {
        this-&gt;errPrn();
    }
    else {
        cout &lt;&lt; this-&gt;name &lt;&lt; &quot;턴...&quot; &lt;&lt; endl &lt;&lt; endl;
        this-&gt;energy -= 30;
    }
}

// 점프 메세지 출력
void Robot::jump() {
    if (this-&gt;energy &lt; 40) {
        this-&gt;errPrn();
    }
    else {
        cout &lt;&lt; this-&gt;name &lt;&lt; &quot;점프...&quot; &lt;&lt; endl &lt;&lt; endl;
        this-&gt;energy -= 40;
    }
}

void Robot::charge(int e) {
    if (e &lt; 0) {
        return;
    }
    else {
        this-&gt;energy += e;
    }
}

char *Robot::getName() {
    return this-&gt;name;
}

void Robot::setName(const char *name) {
    if (this-&gt;name != NULL) {
        delete[] this-&gt;name;
    }
    this-&gt;name = new char[strlen(name) + 1];
    strcpy(this-&gt;name, name);
}

int Robot::getEnergy() {
    return this-&gt;energy;
}

void Robot::setEnergy(int e) {
    if (e &lt; 0) {
        return;
    }
    else {
        this-&gt;energy = e;
    }
}
//HW11.cpp
#include&lt;iostream&gt;
#include&lt;cstring&gt;
#include &quot;Robot.h&quot;
using namespace std;
#pragma warning (disable : 4996)

//int main()
//{
//    Robot r1;
//    Robot r2(&quot;하랑이&quot;);
//    Robot r3(&quot;댕댕이&quot;, 100);
//    Robot r4(r2);
//
//    cout &lt;&lt; r1.getName() &lt;&lt; &quot; &quot; &lt;&lt; r2.getEnergy() &lt;&lt; endl;
//    cout &lt;&lt; r2.getName() &lt;&lt; &quot; &quot; &lt;&lt; r2.getEnergy() &lt;&lt; endl;
//    cout &lt;&lt; r3.getName() &lt;&lt; &quot; &quot; &lt;&lt; r3.getEnergy() &lt;&lt; endl;
//    cout &lt;&lt; r4.getName() &lt;&lt; &quot; &quot; &lt;&lt; r4.getEnergy() &lt;&lt; endl;
//
//    r2.setName(&quot;로보트태권브이&quot;);
//    r2.setEnergy(250);
//    r2.setEnergy(-50);
//    cout &lt;&lt; r2.getName() &lt;&lt; &quot; &quot; &lt;&lt; r2.getEnergy() &lt;&lt; endl;
//
//    r3.go();
//    r3.back();
//    r3.turn();
//    r3.jump();
//    r3.charge(120);
//    cout &lt;&lt; r3.getName() &lt;&lt; &quot; &quot; &lt;&lt; r3.getEnergy() &lt;&lt; endl;
//
//    return 0;
//}

void input(Robot *rp, int rCnt);
void work(Robot *rp, int rCnt);
void output(Robot *rp, int rCnt);
void myflush();

int main() {

    Robot *rp;
    int rCnt;
    cout &lt;&lt; &quot;구입할 로봇 대수를 입력하시오 : &quot;;
    cin &gt;&gt; rCnt;
    rp = new Robot[rCnt];
    input(rp, rCnt);
    work(rp, rCnt);
    output(rp, rCnt);
    return 0;
}

void input(Robot *rp, int rCnt) {
    char name[30];
    int energy;
    for (int i = 0; i &lt; rCnt;i++) {
        cout &lt;&lt; endl &lt;&lt; i + 1 &lt;&lt; &quot;번 로봇명을 입력하시오 : &quot;;
        cin &gt;&gt; name;
        (rp + i)-&gt;setName(name);
        cout &lt;&lt; name &lt;&lt; &quot;의 에너지 양을 입력하시오 : &quot;;
        cin &gt;&gt; energy;
        (rp + i)-&gt;setEnergy(energy);
    }
}

void work(Robot *rp, int rCnt) {
    myflush();
    while (1) {
        char name[30];
        int num, energy;
        cout &lt;&lt; endl &lt;&lt; &quot;# 로봇명 선택(&quot;;
        for (int i = 0; i &lt; rCnt;i++) {
            cout &lt;&lt; (rp + i)-&gt;getName() &lt;&lt; &quot;, &quot;;
        }
        cout &lt;&lt; &quot;\b\b) : &quot;;
        cin.getline(name, sizeof(name));
        if (strcmp(name, &quot;&quot;) == 0) return;
        for (int i = 0; i &lt; rCnt;i++) {
            //cout &lt;&lt; name &lt;&lt; (rp + i)-&gt;getName() &lt;&lt; strcmp(name, (rp + i)-&gt;getName()) &lt;&lt; endl;
            if (strcmp(name, (rp + i)-&gt;getName()) == 0) {
                cout &lt;&lt; &quot;# 할일 선택(1.전진/2.후진/3.회전/4.점프/5.충전) : &quot;;
                cin &gt;&gt; num;
                switch (num) {
                case 1: (rp + i)-&gt;go(); break;
                case 2: (rp + i)-&gt;back(); break;
                case 3: (rp + i)-&gt;turn(); break;
                case 4: (rp + i)-&gt;jump(); break;
                case 5: {
                    cout &lt;&lt; &quot;# 충전할 에너지양 입력 : &quot;;
                    cin &gt;&gt; energy;
                    (rp + i)-&gt;charge(energy); break;
                }
                default: break;
                }
                myflush();
                break;
            }
            else {
                if (i == rCnt - 1) {
                    cout &lt;&lt; &quot;올바르지 못한 로봇명입니다!&quot; &lt;&lt; endl;
                }
            }
        }
    }
}

void output(Robot *rp, int rCnt) {
    cout &lt;&lt; endl;
    for (int i = 0; i &lt; rCnt; i++) {
        cout &lt;&lt; i + 1 &lt;&lt; &quot;. &quot; &lt;&lt; (rp + i)-&gt;getName() &lt;&lt; &quot; : &quot; &lt;&lt; (rp + i)-&gt;getEnergy() &lt;&lt; endl;
    }
}

void myflush() {
    while (cin.get() != &#39;\n&#39;);
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-02-01]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-02-01</link>
            <guid>https://velog.io/@hyeonu_chun/2019-02-01</guid>
            <pubDate>Mon, 21 Jun 2021 03:57:10 GMT</pubDate>
            <description><![CDATA[<h1 id="hw4">HW4</h1>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;string.h&gt;
#pragma warning (disable : 4996)

int random(int);
void myflush();

void praGame(void);
void figGame(void);

void printBin(int**, int);
void printBin_2(int **, int **, int N);

void compareData(int**, int);
void compareData_2(int **, int **, int);

void makeRanBin(int**, int);
void dataClear(int**, int);
int whoWin(int **, int **, int);
int winBin(int**, int);
void inputInt(const char *, int *, int, int);

int main() {
    srand(unsigned int(time(NULL)));
    int menu;
    while (1) {
        printf(&quot;1. 연습게임(개인 연습용)\n2. 대전게임(컴퓨터와 대전용)\n3. 종료\n\n&quot;);
        inputInt(&quot;# 메뉴선택 : &quot;, &amp;menu, 1, 3);
        switch (menu) {
        case 1: praGame(); getchar(); break;
        case 2: figGame(); getchar(); break;
        case 3: return 0;
        }
    }
    return 0;
}

// practice game
void praGame(void) {
    int N;
    printf(&quot;연습용 빙고게임을 시작합니다.\n\n&quot;);
    inputInt(&quot;# 빙고판의 가로, 세로 크기를 입력해주세요(양수값 입력) : &quot;, &amp;N, 2, 10);

    int **bin = (int**)calloc(N, sizeof(int*));
    for (int i = 0; i &lt; N;i++) {
        bin[i] = (int*)calloc(N, sizeof(int));
    }

    makeRanBin(bin, N);
    printBin(bin, N);

    compareData(bin, N);

    dataClear(bin, N);
    printf(&quot;\n&quot;);
}

// fight game
void figGame(void) {
    int N;
    printf(&quot;컴퓨터 대전 빙고게임을 시작합니다.\n\n&quot;);
    inputInt(&quot;# 빙고판의 가로, 세로 크기를 입력해주세요(양수값 입력) : &quot;, &amp;N, 2, 10);
    printf(&quot;\n사용자 빙고게임판 내용을 생성중입니다.\n&quot;);
    printf(&quot;컴퓨터 빙고게임판 내용을 생성중입니다.\n\n&quot;);

    int **uBin = (int**)calloc(N, sizeof(int*));
    int **cBin = (int**)calloc(N, sizeof(int*));
    for (int i = 0; i &lt; N;i++) {
        uBin[i] = (int*)calloc(N, sizeof(int));
    }
    for (int i = 0; i &lt; N;i++) {
        cBin[i] = (int*)calloc(N, sizeof(int));
    }

    makeRanBin(uBin, N);
    makeRanBin(cBin, N);
    printBin_2(uBin, cBin, N);

    compareData_2(uBin, cBin, N);

    dataClear(uBin, N);
    dataClear(cBin, N);
    printf(&quot;\n&quot;);
}

// compare data - practice game
void compareData(int **bin, int N) {
    int cData;
    for (int i = 0; i &lt; N*N;i++) {
        inputInt(&quot;\n# 지울 숫자 입력(1~%d) : &quot;, &amp;cData, 1, N*N);
        for (int j = 0; j &lt; N;j++) {
            for (int k = 0;k &lt; N;k++) {
                if (bin[j][k] == cData) {
                    bin[j][k] = -cData;
                    printBin(bin, N);
                    if (winBin(bin, N) == 1) { 
                        printf(&quot;\n# 아무 키나 치면 주 메뉴로 돌아갑니다.&quot;);
                        return; 
                    }
                    break;
                }
                else if (bin[j][k] == -cData) {
                    printf(&quot;* 이미 지워진 숫자 입니다. 다시 입력하세요.\n&quot;);
                    i--;
                }
            }
        }
    }
}

// compare data - fight game
void compareData_2(int **ubin,int **cbin, int N) {
    int cData, num = 0;
    for (int i = 0; i &lt; N*N;i++) {
        if (i % 2 == 0) {
            inputInt(&quot;\n# 지울 숫자 입력(1~%d) : &quot;, &amp;cData, 1, N*N);
            for (int j = 0; j &lt; N;j++) {
                for (int k = 0;k &lt; N;k++) {
                    if (ubin[j][k] == -cData || cbin[j][k] == -cData) {
                        num = 1;
                        break;
                    }
                    if (ubin[j][k] == cData) ubin[j][k] = -cData;
                    if (cbin[j][k] == cData) cbin[j][k] = -cData;
                }
            }
            if (num == 1) {
                printf(&quot;* 이미 지워진 숫자 입니다. 다시 입력하세요.\n&quot;);
                i--;
                num = 0;
            }
            else {
                printBin_2(ubin, cbin, N);
                cData = whoWin(ubin, cbin, N);
                if (cData == 1) return;
            }
        }
        else {
            while (1) {
                int num = 0;
                cData = random(N*N) + 1;
                for (int i = 0; i &lt; N;i++) {
                    for (int j = 0;j &lt; N;j++) {
                        if (ubin[i][j] == -cData) num++;
                    }
                }
                if (num == 0)break;
            }
            printf(&quot;\n# 컴퓨터가 선택한 숫자는 (%d)입니다.\n&quot;, cData);
            for (int j = 0; j &lt; N;j++) {
                for (int k = 0;k &lt; N;k++) {
                    if (ubin[j][k] == cData) ubin[j][k] = -cData;
                    if (cbin[j][k] == cData) cbin[j][k] = -cData;
                }
            }
            printBin_2(ubin, cbin, N);
            cData = whoWin(ubin, cbin, N);
            if (cData == 1) return;
        }
    }
}

// who win : compare bingo that succes &#39;Bingo&#39; first
int whoWin(int **ubin, int **cbin, int N) {
    int unum = 0, cnum = 0;
    if ((unum = winBin(ubin, N)) &gt; 0 || (cnum = winBin(cbin, N)) &gt; 0) {
        if (unum &gt; cnum) printf(&quot;\n# 사용자 승!&quot;);
        else if (unum &lt; cnum) printf(&quot;\n# 컴퓨터 승!&quot;);
        else printf(&quot;\n# 사용자, 컴퓨터 !&quot;);
        printf(&quot;\n# 아무 키나 치면 주 메뉴로 돌아갑니다.&quot;);
        return 1;
    }
    return 0;
}

// win bingo : count &#39;Bingo&#39; line
int winBin(int **bin, int N) {
    int sum = 0;
    int val[4] = { 0, };
    for (int i = 0; i &lt; N;i++) {
        val[0] = val[1] = 0;
        for (int j = 0;j &lt; N;j++) {
            if (bin[i][j] &lt; 0) val[0]++;
            if (bin[j][i] &lt; 0) val[1]++;
            if (i == j) {
                if (bin[i][j] &lt; 0) val[2]++;
            }
            if (i == N - j - 1) {
                if (bin[i][j] &lt; 0) val[3]++;
            }
        }
        for (int k = 0;k &lt; 4;k++) {
            if (val[k] == N) sum++;
        }
    }
    if (sum &gt;= N) return 1;
    return 0;
}

// print practice game bingo
void printBin(int **bin, int N) {
    printf(&quot;\n|&quot;);
    for (int i = 0; i &lt; N;i++) {
        for (int j = 0;j &lt; N;j++) {
            if (bin[i][j] &lt; 0) printf(&quot;    X&quot;);
            else printf(&quot;%5d&quot;, bin[i][j]);
        }
        printf(&quot;  |\n|&quot;);
    }
    printf(&quot;\b &quot;);
}

// print fight game bingo
void printBin_2(int **ubin, int **cbin, int N) {

    printf(&quot;[user]\t\t\t\t[couputer]\n|&quot;);
    for (int i = 0; i &lt; N;i++) {
        for (int j = 0;j &lt; N;j++) {
            if (ubin[i][j] &lt; 0) printf(&quot;    X&quot;);
            else printf(&quot;%5d&quot;, ubin[i][j]);
        }
        printf(&quot;  |\t|&quot;);
        for (int k = 0;k &lt; N;k++) {
            if (cbin[i][k] &lt; 0) printf(&quot;    X&quot;);
            else printf(&quot;%5d&quot;, cbin[i][k]);
        }
        printf(&quot;  |\n|&quot;);
    }
    printf(&quot;\b &quot;);
}

// make random bingo : put random number in bingo 
void makeRanBin(int**bin, int N)
{
    int temp;
    int *cBin = (int*)calloc(N*N, sizeof(int));
    for (int i = 0; i &lt; N*N;i++) {
            cBin[i] = i + 1;
    }
    for (int i = 0; i &lt; N*N;i++) {
        int *num1 = cBin + random(N*N);
        int *num2 = cBin + random(N*N);
        temp = *num1; *num1 = *num2; *num2 = temp;
    }
    for (int i = 0; i &lt; N;i++) {
        for (int j = 0; j &lt; N;j++) {
            bin[i][j] = cBin[i*N + j];
        }
    }
    memset(cBin, 0, N*N);
    free(cBin);
}

// input integer : put integer that user select in data and do exception handling
void inputInt(const char *msg, int *p, int min, int max) {
    while (1) {
        printf(msg, max);
        scanf(&quot;%d&quot;, p);
        if (getchar() == &#39;\n&#39;) {
            if (*p &gt;= min &amp;&amp; *p &lt;= max) return;
            else printf(&quot;* 올바르지 못한 숫자입니다.\n&quot;);
        }
        else {
            printf(&quot;* 올바르지 못한 숫자입니다.\n&quot;);
            myflush();
        }
    }
}

// data clear
void dataClear(int **bin, int N) {
    for (int i = 0; i &lt; N;i++) {
        memset(bin[i], 0, N);
        free(bin[i]);
    }
    memset(bin, 0, N);
    free(bin);
}

// make radom integer
int random(int num) {
    int res;
    res = rand() % num;
    return res;
}

// myflush
void myflush() {
    while (getchar() != &#39;\n&#39;);
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-01-31]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-01-31</link>
            <guid>https://velog.io/@hyeonu_chun/2019-01-31</guid>
            <pubDate>Mon, 21 Jun 2021 03:56:23 GMT</pubDate>
            <description><![CDATA[<h1 id="hw9">HW9</h1>
<pre><code>#include &lt;iostream&gt;
#include &lt;time.h&gt;
#pragma warning (disable : 4996)
using namespace std;

struct Goods {
    char item[50];
    int price;
    int year;
    int mon;
    int day;
    int discount;
};

void input(Goods &amp;s);
void selling_price(Goods &amp;s);
void prn(const Goods &amp;s);
int tot_days(int y, int m, int d);
int leap_check(int year);
int errorCheck(int *num);

int main() {

    struct Goods s;
    input(s);
    selling_price(s);
    if (s.discount == -1) return -1;
    prn(s);
    return 0;
}

void selling_price(Goods &amp;s) {
    time_t timer;
    struct tm *cur;
    timer = time(NULL);
    cur = localtime(&amp;timer);

    int cur_year = cur-&gt;tm_year + 1900; //현재 해
    int cur_mon = cur-&gt;tm_mon + 1; // 현재 달
    int cur_day = cur-&gt;tm_mday; // 현재 날짜

    int res = tot_days(s.year, s.mon, s.day) - tot_days(cur_year, cur_mon, cur_day);

    if (res &gt; 10) {
        s.discount = 0;
    }
    else {
        if (res &lt; 0) {
            cout &lt;&lt; &quot;유통기한이 지났습니다!&quot; &lt;&lt; endl;
            s.discount = -1;
        }
        else if (res &gt;= 0 &amp;&amp; res &lt;= 3) {
            s.price /= 2;
            s.discount = 50;
        }
        else if (res &gt;= 4 &amp;&amp; res &lt;= 10) {
            s.price = s.price - (s.price / 5);
            s.discount = 20;
        }
    }
    return;
}

void input(Goods &amp;s) {
    int res;
    cout &lt;&lt; &quot;품목 입력 : &quot;;
    cin &gt;&gt; s.item;
    cout &lt;&lt; &quot;정가 입력 : &quot;;
    cin &gt;&gt; s.price;
    while (1) {
        cout &lt;&lt; &quot;유통기한 입력 : &quot;;
        cin &gt;&gt; s.year &gt;&gt; s.mon &gt;&gt; s.day;
        int num[3] = { s.year,s.mon,s.day };
        res = errorCheck(num);
        if (res == 1) break;
        cout &lt;&lt; &quot;올바르지 못한 날짜입니다&quot; &lt;&lt; endl;
    }
    return;
}

void prn(const Goods &amp;s) {


    cout &lt;&lt; &quot;품목 : &quot; &lt;&lt; s.item &lt;&lt; endl;
    cout &lt;&lt; &quot;판매가 : &quot; &lt;&lt; s.price &lt;&lt; endl;
    cout &lt;&lt; &quot;유통기한 : &quot; &lt;&lt; s.year &lt;&lt; &quot;년 &quot; &lt;&lt; s.mon &lt;&lt; &quot;월 &quot; &lt;&lt; s.day &lt;&lt; &quot;일 &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;할인율 : &quot; &lt;&lt; s.discount &lt;&lt; &quot;%&quot; &lt;&lt; endl;
    return;
}

int leap_check(int num) {
    if (num % 4 != 0) {
        return 0;
    }
    else {
        if (num % 100 != 0) {
            return 1;
        }
        else {
            if (num % 400 == 0) {
                return 1;
            }
            else {
                return 0;
            }
        }
    }
}

int tot_days(int y, int m, int d) {
    int sum = 0;
    int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    for (int i = 1900; i &lt; y; i++) {
        if (leap_check(i) == 1) {
            sum += 366;
        }
        else {
            sum += 365;
        }
    }
    if (leap_check(y) == 1) {
        if (m &lt;= 2) {
            for (int i = 0; i &lt; (m - 1); i++) {
                sum += month[i];
            }
            sum += d;
        }
        else {
            for (int i = 0; i &lt; (m - 1);i++) {
                sum += month[i];
            }
            sum += d + 1;
        }
    }
    else {
        for (int i = 0;i &lt; (m - 1);i++) {
            sum += month[i];
        }
        sum += d;
    }
    return sum;
}

int errorCheck(int *num) {
    int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    if (num[1] &gt;= 1 &amp;&amp; num[1] &lt;= 12) {
        if (leap_check(num[0]) == 1) {
            if (num[1] == 2) {
                if (num[2] &gt;= 1 &amp;&amp; num[2] &lt;= 29) return 1;
            }
            else {
                if (num[2] &gt;= 1 &amp;&amp; num[2] &lt;= month[num[1] - 1]) return 1;
            }
        }
        else {
            if (num[2] &gt;= 1 &amp;&amp; num[2] &lt;= month[num[1] - 1]) return 1;
        }
    }
    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[2019-01-30]]></title>
            <link>https://velog.io/@hyeonu_chun/2019-01-30</link>
            <guid>https://velog.io/@hyeonu_chun/2019-01-30</guid>
            <pubDate>Mon, 21 Jun 2021 03:55:44 GMT</pubDate>
            <description><![CDATA[<h1 id="hw7">HW7</h1>
<pre><code>#include &lt;iostream&gt;
using namespace std;

struct Savings {
    int w500;
    int w100;
    int w50;
    int w10;
};

void init(Savings &amp;s);
void input(int &amp;unit, int &amp;cnt);
void save(Savings &amp;s, int unit, int cnt);
int total(Savings &amp;s);
void my_flush();

int main() {
    struct Savings s;
    int unit, cnt, sum;
    while (1) {
        init(s);
        while (1) {
            input(unit, cnt);
            if (unit == -1) break;
            save(s, unit, cnt);
        }
        cout &lt;&lt; &quot;총 저금액 : &quot; &lt;&lt; total(s) &lt;&lt; endl &lt;&lt; endl;
    }
    return 0;
}

void init(Savings &amp;s) {
    s.w500 = 0;
    s.w100 = 0;
    s.w50 = 0;
    s.w10 = 0;
}

void input(int &amp;unit, int &amp;cnt) {
    while (1) {
        cout &lt;&lt; &quot;동전의 금액 : &quot;;
        cin &gt;&gt; unit;
        if (cin.fail()) {
            my_flush();
            unit = -1;
            return;
        }
        switch (unit) {
        case 10:;
        case 50:;
        case 100:;
        case 500: {
            cout &lt;&lt; &quot;동전의 개수 : &quot;;
            cin &gt;&gt; cnt;
            return;

        }
        default: break;
        }
    }

}

void save(Savings &amp;s, int unit, int cnt) {
    switch (unit) {
    case 10: s.w10 += cnt; break;
    case 50: s.w50 += cnt; break;
    case 100: s.w100 += cnt; break;
    case 500: s.w500 += cnt; break;
    }
}

int total(Savings &amp;s) {
    int sum = 0;
    sum += 10 * s.w10;
    sum += 50 * s.w50;
    sum += 100 * s.w100;
    sum += 500 * s.w500;
    return sum;
}

void my_flush() {
    cin.clear();
    while (cin.get() != &#39;\n&#39;);
}</code></pre><h1 id="hw8">HW8</h1>
<pre><code>#include &lt;iostream&gt;
using namespace std;

void swap_ptr(const char* &amp;, const char* &amp;);

int main() {
    const char *ap = &quot;apple&quot;;
    const char *bp = &quot;banana&quot;;

    cout &lt;&lt; &quot;바꾸기 전의 문자열 : &quot; &lt;&lt; ap &lt;&lt; &quot; &quot; &lt;&lt; bp &lt;&lt; endl;
    swap_ptr(ap, bp);
    cout &lt;&lt; &quot;바꾼 후의 문자열 : &quot; &lt;&lt; ap &lt;&lt; &quot; &quot; &lt;&lt; bp &lt;&lt; endl;

    return 0;
}

void swap_ptr(const char* &amp;ap, const char* &amp;bp) {
    char *tp;
    //tp = new char[len + 1];
    //strcpy(tp,)
    tp = (char*)ap;
    ap = (char*)bp;
    bp = tp;
}</code></pre>]]></description>
        </item>
    </channel>
</rss>