교재 및 CS공부/명품C++Programming
[명품C++Programming] 3장 OpenChallenge : 지수 표현 클래스 만들기
veganwithbacon
2023. 4. 19. 16:56
반응형
//main.cpp
#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;
}
//Exp.h
#include "Exp.h"
Exp::Exp(int a, int b){base=a; jisu=;}
Exp::Exp(int a){base=a; jisu=1;}
Exp::Exp(){base=1; jisu=1;}
int Exp::getValue(){
int count=base;
for(int i=1;i<base;i++){
count*=base;
}
return count;
}
int Exp::getBase(){
return base;
}
int Exp::getExp(){
return jisu;
}
bool equals(Exp b){
if(getValue()==b.getValue())return true;
else return false;
}
//Exp.h
class Exp{
int num1;
int num2;
public:
Exp(int a,int b);
Exp(int a);
Exp();
int getValue();
int getBase();
int getExp();
bool equals(Exp b);
};
반응형