C++

명품 C++ 3장 오픈챌린지

Hs’s Coding vlog 2023. 1. 3. 19:01
//메인함수 파트
#include <iostream>
using namespace std;
#include "Exp.h"

int main(){
    Exp a(3,2);
    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;
}
//헤더파일 파트
#ifndef EXP_H
#define EXP_H
//클래스 헤더 파일은 선언부만 적어주기
class Exp
{
private:
int base;//멤버변수 선언부,베이스
int jisoo;//지수
int res;
    
public:
Exp();
Exp(int x);
Exp(int x, int y);
int getValue();//멤버함수 선언부
int getBase();
int getExp();
bool equals(Exp x);
};

#endif
//헤더파일 구현부
#include "Exp.h"
#include <math.h>

//클래스 구현부
Exp::Exp(){
    base =1;
    jisoo =1;
}
Exp::Exp(int x){
    base =x;
    jisoo =1;
}
Exp::Exp(int x, int y){
    base =x;
    jisoo =y;
}

int Exp::getValue(){
    res = pow(base,jisoo);
    return res;
}

int Exp::getBase(){
    return  base;
}

int Exp::getExp(){
    return jisoo;
}

bool Exp::equals(Exp X){
    if(X.getValue() == res){
        return true;
    }

}

'C++' 카테고리의 다른 글

명품 C++ 실습문제 4장 오픈챌린지  (0) 2023.01.04
명품 C++ 실습문제 3장 12번  (0) 2023.01.03
명품 C++ 실습문제 3장 10번  (0) 2023.01.03
명품 C++ 실습문제 3장 8번  (0) 2023.01.03
명품 C++ 실습문제 3장 7번  (0) 2023.01.03