반응형
//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);
};
반응형
'교재 및 CS공부 > 명품C++Programming' 카테고리의 다른 글
[명품C++Programming] 4장 연습 문제 (0) | 2023.05.02 |
---|---|
[명품C++Programming] 3장 실습문제 (0) | 2023.04.21 |
[명품C++Programming] 3장 연습 문제 (0) | 2023.04.20 |
댓글
veganwithbacon님의
글이 좋았다면 응원을 보내주세요!
이 글이 도움이 됐다면, 응원 댓글을 써보세요. 블로거에게 지급되는 응원금은 새로운 창작의 큰 힘이 됩니다.
응원 댓글은 만 14세 이상 카카오계정 이용자라면 누구나 편하게 작성, 결제할 수 있습니다.
글 본문, 댓글 목록 등을 통해 응원한 팬과 응원 댓글, 응원금을 강조해 보여줍니다.
응원금은 앱에서는 인앱결제, 웹에서는 카카오페이 및 신용카드로 결제할 수 있습니다.