#include "infint.h"
using namespace std;
Infint::Infint(){
Inf_num="0";
}
Infint::Infint(int i_num){//int to string
stringstream sstr;
sstr<<i_num;
Inf_num=sstr.str();
}
Infint::Infint(string s_num){
Inf_num = s_num;
}
//Infint::~Infint(){}
/*********************Get**************/
int Infint::GetInt() const {
int temp = stoi(Inf_num);
return temp;
}
string Infint::GetInf_num()
{
return Inf_num;
}
/*******************Set*******************/
void Infint::SetNum(int i)
{
stringstream sstr;
sstr<< i;
Inf_num = sstr.str();
}
Infint& Infint::operator+(int i_num)
{
SetNum(GetInt()+i_num);
return *this;
}
Infint& Infint::operator+(string s_num)
{
int temp = stoi(s_num);
SetNum(GetInt()+temp);
return *this;
}
Infint& Infint::operator+(const Infint& Inf_o)
{
SetNum(GetInt() + Inf_o.GetInt());
return *this;
}
void Infint::operator=(int i_num)
{
SetNum(i_num);
}
void Infint::operator=(const Infint& Inf_o)
{
SetNum(Inf_o.GetInt());
}
void Infint::operator+=(int i_num)
{
SetNum(GetInt()+i_num);
}
void Infint::operator+=(string s_num)
{
int temp = stoi(s_num);
SetNum(GetInt()+temp);
}
void Infint::operator-=(int i_num)
{
SetNum(GetInt()-i_num);
}
void Infint::operator-=(string s_num)
{
int temp = stoi(s_num);
SetNum(GetInt()-temp);
}
void Infint::operator-=(const Infint& Inf_o)
{
SetNum(GetInt()-Inf_o.GetInt());
}
void Infint::operator++(int)
{
SetNum(GetInt()+1);
}
void Infint::operator--(int)
{
SetNum(GetInt()-1);
}
ostream& operator<<
(ostream& os, const Infint& Inf_o)
{
cout<<Inf_o.GetInt();
return os;
}
'C++ > 학교 숙제' 카테고리의 다른 글
string 문자열 덧셈계산 (0) | 2018.04.14 |
---|---|
session_4_ex infint.h(객체 맴버변수가 string 일때) (0) | 2018.04.11 |
session_4_ex infint.cpp(객체 맴버변수가 int일때) (0) | 2018.04.10 |
session_4_ex infint.h(객체 맴버변수가 int일때) (0) | 2018.04.10 |
session_4_ex (연산자 오버로딩)_문제 (0) | 2018.04.10 |
댓글