You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

62 lines
2.0 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Converter.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */
/* Updated: 2022/07/12 08:42:27 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "Converter.hpp"
Converter::Converter (void) {
cout << "Converter default constructor called " << endl;
}
Converter::Converter (string str){
if (str[0] == '\'' || str[0] == '"')
{
_c = str[1];
cout << "Char: " << _c << endl;
_d = static_cast<double>(_c);
}
else
{
cout << "Char: ";
_d = std::strtod(str.c_str(), 0);
_c = static_cast<char>(_d);
if (_d < 0 || _d > 255)
cout << "Invalid" << endl;
else if (std::isprint(_c))
cout << "Not Printable" << endl;
else
cout << _c << endl;
}
cout << "Double: " << _d << endl;
cout << "Integer: ";
_i = static_cast<int>(_d);
if (_d < std::numeric_limits<int>::min() || _d > std::numeric_limits<int>::max())
cout << "Off limits -> ";
cout << _i << endl;
_f = static_cast<float>(_d);
cout << "Float: " << _f << "f"<< endl;
}
Converter::Converter (Converter const & src) {
(void)src;
cout << "Converter copy constructor called" << endl;
}
Converter & Converter::operator= (Converter const & src) {
(void)src;
cout << "Converter assignment operator called" << endl;
return (*this);
}
Converter::~Converter (void) {
cout << "Converter default destructor called" << endl;
}