개발, 연습

[c++] 열혈 c++ 문제 4-X

Injel me 2020. 7. 1. 18:57
<Prob 04-2>
https://drive.google.com/open?id=15udvQpHWDpDA38AzSl6zncq1ksTmymYB

-main.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "header\class.h"
int main(int argc, char const *argv[])
{
    Ring r(114229);
    r.ShowRingInfo();
    return 0;
}
cs

-class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
class Point {
private:
    int xpos, ypos;
public:
    Point(const int x, const int y);
    ~Point();
    void ShowPointInfo() const;
};
class Circle {
private:
    Point * c;
    int r;
public:
    Circle(const int x, const int y, const int r);
    ~Circle();
    void ShowCircleInfo() const;
};
class Ring {
private:
    Circle inner;
    Circle outter;
public:
    Ring(const int x1, const int y1, const int r1,
        const int x2, const int y2, const int r2);
    ~Ring();
    void ShowRingInfo() const;
};
cs

-class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "header\class.h"
#include <iostream>
using std::cout;
using std::endl;
Point::Point(const int x, const int y) 
    : xpos(x),
    ypos(y)
{
}
Point::~Point() {}
void Point::ShowPointInfo() const {
    cout << "[" << xpos << ", " << ypos << "]" << endl;
}
Circle::Circle(const int x, const int y, const int r)
    :r(r)
{
    c = new Point(x, y);
}
Circle::~Circle() {
    delete c;
    c = nullptr;
}
void Circle::ShowCircleInfo() const {
    cout << "radious : " << r << endl;
    c->ShowPointInfo();
}
Ring::Ring(const int x1, const int y1, const int r1, const int x2, const int y2, const int r2)
    : inner(x1, y1, r1),
    outter(x2, y2, r2)
{
}
Ring::~Ring() {}
void Ring::ShowRingInfo() const {
    cout << "inner circle Info.." << endl;
    inner.ShowCircleInfo();
    cout << "outter circle Info.." << endl;
    outter.ShowCircleInfo();
}
cs



<Prob-04-3-2>
https://drive.google.com/open?id=1iQsBTTn_a_ysSx3FbRASvlkeSjCtTvDX

-main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include "header\namecard.h"
int main(int argc, char const *argv[])
{
    NameCard manClerk("Lee""ABCEng""010-1111-2222", COMP_POS::CLERK);
    NameCard manSenior("Hong""OrangeEng""010-2222-3333", COMP_POS::SENIOR);
    NameCard manAssist("Kim""SoGoodComp""010-5555-6666", COMP_POS::ASSIST);
    manClerk.show_namecard_info();
    manSenior.show_namecard_info();
    manAssist.show_namecard_info();
    
    return 0;
}
cs

-namecard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once
class NameCard {
private:
    char * name;
    char * company_name;
    char * phone_number;
    int rank;
public:
    NameCard(const char * name, const char * company_name,
        const char * phone_number, const int rank);
    ~NameCard();
    void show_namecard_info() const;
private:
    void selRank() const;
};
namespace COMP_POS {
    enum {
        CLERK = 100, SENIOR = 300, ASSIST = 400, MANAGER = 500
    };
}
cs


-namecard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "header\namecard.h"
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
NameCard::NameCard(const char * name, const char * company_name,
        const char * phone_number, const int rank)
    : rank(rank)
{
    this->name = new char[strlen(name) + 1];
    strcpy(this->name, name);
    this->company_name = new char[strlen(company_name) + 1];
    strcpy(this->company_name, company_name);
    this->phone_number = new char[strlen(phone_number) + 1];
    strcpy(this->phone_number, phone_number);
}
    NameCard::~NameCard() {
        delete[] name;
        delete[] company_name;
        delete[] phone_number;
        name = company_name = phone_number = nullptr;
    }
void NameCard::show_namecard_info() const {
    cout << "name : " << name << endl;
    cout << "company : " << company_name << endl;
    cout << "phone : " << phone_number << endl;
    cout << "rank : ";
    selRank();
    cout << endl << endl;
}
void NameCard::selRank() const {
    switch (this->rank) {
    case COMP_POS::CLERK:
        cout << "clerk"break;
    case COMP_POS::SENIOR:
        cout << "senior"break;
    case COMP_POS::ASSIST:
        cout << "assist"break;
    case COMP_POS::MANAGER:
        cout <<"manager"break;
    }
}
cs