본문 바로가기
C++/학교 숙제

session_4_ex infint.cpp(객체 맴버변수가 string 일때)

by Beijing_KingGod 2018. 4. 11.

#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;
}

댓글