Question
Please separate the class in the code below into a header file called convertToNumeric.h and a file named convertToNumeric.cpp which contains main method to implement
Please separate the class in the code below into a header file called "convertToNumeric.h" and a file named "convertToNumeric.cpp" which contains main method to implement those header functions. I'm trying to separate the class from the main driver below the class. This is all in C++. Also please attempt to alter the code so that the "this" pointer isn't being used. I'd rather have a new name created for that string.
#include
class ConvertToNumeric { private: string str; long int intValue; double doubleValue; char_stack cstk1, cstk2; // 2 Character stacks - 1 for storing integer portion and the other for decimal portion of the string public: ConvertToNumeric() { // Default constructor str = "123"; } /* * Overloaded constructor that takes a string * and calls the convert method to convert into respective integer and decimal value */ ConvertToNumeric(string str) { this->str = str; if(convert(this->str)) { cout << "Conversion Successful" << endl; } else { cout << "Conversion failed" <
int main() { string str; cout << "Please enter a string representing a positive integer or decimal: "; // Taking user inuput cin >> str; ConvertToNumeric ctn(str); // Converting the string to its respective integer and decimal values long int integerValue = ctn.getIntValue(); // Getting the integer value double doubleValue = ctn.getDecValue(); // Getting the decimal value double integral; if (std::modf(doubleValue, &integral) == 0) { // If the string represents an integer value, adding decimal portion to the decimal value cout << "Integer Conversion: " << integerValue << endl; cout << "Decimal Conversion: " << std::fixed << std::setprecision(1) << integral <
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started