OC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
 
#include "OC.h"
 
int main() {
    Exp a(32);
    Exp b(9);
    Exp c;
 
    cout << a.getValue() << ' ' << b.getValue() << ' ' << c.getValue() << endl;
    cout << "a의 베이스 " << a.getBase() << ',' << "지수 " << a.getExp() << endl;
 
    if (a.equals(b)) {
        cout << "same" << endl;
    }
    else {
        cout << "not same" << endl;
    }
}
cs


OC.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
class Exp {
    int result;
    int base;
    int exponent;
public:
    Exp() { base = 1; exponent = 1; }
    Exp(int a) { base = a; exponent = 1; }
    Exp(int a, int b) { base = a; exponent = b; }
    int getValue();
    int getBase() { return base; }
    int getExp() { return exponent; }
    bool equals(Exp b);
};
 
int Exp::getValue() {
    result = 1;
    for (int i = 1; i <= exponent; i++) {
        result *= base;
    }
    return result;
}
 
bool Exp::equals(Exp b) {
    if (b.getValue() == result)return true;
    return false;
}
cs


+ Recent posts