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.

63 lines
1.9 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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):_input(str){
startConv();
cout << "Converter parameter constructor called" << 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;
}
void Converter::startConv(void) {
if (_input[0] == '\'' || _input[0] == '"')
{
_c = _input[1];
_d = static_cast<double>(_c);
}
else
{
_d = std::strtod(_input.c_str(), 0);
_c = static_cast<char>(_d);
}
_i = static_cast<int>(_d);
_f = static_cast<float>(_d);
}
void Converter::display(void) {
cout << "Input: " << _input << endl;
cout << "Char: " << _c << endl;
cout << "Double: " << _d << endl;
cout << "Float: " << _f << endl;
cout << "Integer: " << _i << endl;
}