#include<iostream>
#include<cstring>
#include<cmath>
#include "kira.h"
using namespace fakap;
using namespace std;
Kira::Kira() //default constructor
{
//do nothing
}
Kira::Kira(char* s) //constructor
{
cout<<atoi(s)<<'\n';
}
Kira::~Kira()
{
cout<<"\ndel constructor\n"; //debugging purposes msg
}
int Kira::atoi(char* s)
{
total = 0;
int digit = 0;
for (int i = (strlen(s)-1); i >= 0; i--)
{
total += (s[i]-'0') * (int)(pow (10.0,digit));
digit++;
}
return total;
}
int Kira::atol (char* s)
{
total = 0;
int c =*s++;
while ( (c = chartodigit(c)) != -1 )
{
total = 10 * total + c; /* accumulate digit */
c = *s++; /* get next char */
}
return total;
}
int Kira::atox (char* s)
{
total = 0;
int digit = 0;
for (int i = (strlen(s)-1); i >= 0; i--)
{
if (s[i] >= '0' && s[i] <='9')
{
total += (s[i]-'0') * (pow (16.0,digit));
digit++;
}
else
if (s[i] >= 'A' && s[i] <='Z')
{
total += (s[i]-45) * (pow (16.0,digit));
digit++;
}
else
if (s[i] >= 'a' && s[i] <= 'z')
{
total += (s[i]-87) * (pow (16.0,digit));
digit++;
}
else
cerr << "wrong number format\n";
}
return total;
}
Tidak ada komentar:
Posting Komentar