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.

75 lines
2.4 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Converter.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */
2 years ago
/* Updated: 2022/08/18 08:54:04 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#include "Converter.hpp"
2 years ago
using std::cout;
using std::endl;
3 years ago
2 years ago
Converter::Converter(void) {
cout << "Converter default constructor called " << endl;
3 years ago
}
2 years ago
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;
}
3 years ago
}
2 years ago
Converter::Converter(Converter const &src) {
(void)src;
cout << "Converter copy constructor called" << endl;
3 years ago
}
2 years ago
Converter &Converter::operator=(Converter const &src) {
(void)src;
cout << "Converter assignment operator called" << endl;
return (*this);
3 years ago
}
2 years ago
Converter::~Converter(void) {
3 years ago
2 years ago
cout << "Converter default destructor called" << endl;
3 years ago
}