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.
74 lines
2.4 KiB
74 lines
2.4 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Converter.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */
|
|
/* Updated: 2022/08/18 08:54:04 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "Converter.hpp"
|
|
using std::cout;
|
|
using std::endl;
|
|
|
|
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 (isnan(_d))
|
|
cout << "Impossible" << endl;
|
|
else if (!std::isprint(_c))
|
|
cout << "Not Printable" << endl;
|
|
else
|
|
cout << "'" << _c << "'" << endl;
|
|
}
|
|
cout << "Integer: ";
|
|
_i = static_cast<int>(_d);
|
|
if (_d < std::numeric_limits<int>::min() ||
|
|
_d > std::numeric_limits<int>::max())
|
|
cout << "Off limits -> ";
|
|
if (std::isnan(_d))
|
|
cout << "Impossible" << endl;
|
|
else
|
|
cout << _i << endl;
|
|
_f = static_cast<float>(_d);
|
|
if (_d == 0 || _d / static_cast<int>(_d) == 1) {
|
|
cout << "Double: " << std::setprecision(1) << std::fixed << _d<< endl;
|
|
cout << "Float: " << std::setprecision(1) << std::fixed << _f << "f" << endl;
|
|
}
|
|
else
|
|
{
|
|
cout << "Double: " << _d << endl;
|
|
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;
|
|
}
|
|
|