Question: *** I need help identifying and commenting my incoming parameters, outgoing parameters, return values, mutator functions, and accessor functions in the C++ code below. There

*** I need help identifying and commenting my incoming parameters, outgoing parameters, return values, mutator functions, and accessor functions in the C++ code below. There are 4 files in the code below. Use the header files as a reference, but only label in the cpp files. Should one of the outgoing parameters not exist, just put N/A. ****

char_stack.h header file:

#ifndef CHAR_STACK_H #define CHAR_STACK_H

const char STACKSIZE = 100;

class char_stack { public: char_stack(); bool pop(char& item); bool push(char item);

private: bool isEmpty() const; bool isFull() const;

int top; char stk[STACKSIZE]; };

#endif

char_stack.cpp file:

#include "char_stack.h"

//--------------------------------------------------------------------------- /* The stack is initially empty and the top variable is designed to reference * the topmost valid item on the stack. The stack is implemented as a fixed * size character array. When the stack is empty, top must be set to -1. */

char_stack::char_stack() { top = -1; }

//--------------------------------------------------------------------------- /* We can only pop an item off if the stack is not empty. */

bool char_stack::pop(char& item) { bool success = false;

if (!isEmpty()) { item = stk[top--]; success = true; }

return success; }

//--------------------------------------------------------------------------- /* We can only push an item when the stack is not full. */

bool char_stack::push(char item) { bool success = false;

if (!isFull()) { stk[++top] = item; success = true; }

return success; }

//--------------------------------------------------------------------------- /* The top variable represents the index of the element that is currently * holding the topmost item. The stack is implemented as a fixed size array. * Therefore, when the stack is empty, top must be -1. */

bool char_stack::isEmpty() const { return (top == -1); }

//--------------------------------------------------------------------------- /* Since the stack is a fixed array of size STACKSIZE, the topmost element is * stored at index STACKSIZE minus 1. When top equals STACKSIZE minus 1, the * stack is full. */

bool char_stack::isFull() const { return (top == (STACKSIZE - 1)); }

convert.h header file:

#include #include "char_stack.h" #ifndef CONVERT_H #define CONVERT_H using namespace std;

class convertToNumeric { public: convertToNumeric(); // Default constructor

/* * Overloaded constructor that takes a string * and calls the convert method to convert into respective integer and decimal value */ convertToNumeric(string str); /* * Converting a string into its respective integer and decimal values * @param str - a string to convert * @return - a boolean value indicating whether conversion is successful or not */ bool convert(string str); /* * Returning the integer value of the string converted */ long int getIntValue();

/* * Returning the double value of the string converted */ double getDecValue();

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 };

#endif

convert.cpp file:

#include #include "convert.h" using namespace std;

convertToNumeric::convertToNumeric() { str = "123"; }

/* * Overloaded constructor that takes a string * and calls the convert method to convert into respective integer and decimal value */

convertToNumeric::convertToNumeric(string s) { str = s; if(convert(str)) { cout << "Conversion Successful!" << endl; }

else { cout << "Conversion failed." <

/* * Converting a string into its respective integer and decimal values * @param str - a string to convert * @return - a boolean value indicating whether conversion is successful or not */

bool convertToNumeric::convert(string s) { bool success = false; bool dotFound = false; /* * Looping through each character in string * and storing the integer portion in cstk1 * and decimal portion in cstk2 * Ex: If s = 123.45, cstk1 = 321 and cstk2 = 54 (since stack follows LIFO) */ int i; for(i = 0; i < s.size(); i++) { if(s[i] == '.') dotFound = true;

else if(dotFound) { cstk2.push(s[i]); }

else { cstk1.push(s[i]); } } /* * Popping out each value fom stack cstk1 and generating the integer value * Ex: s = 123.45 and cstk1 = 321, num = 0 * Iteration 1: num = 0 + (3 * 1) = 3 * Iteration 2: num = 3 + (2 * 10) = 23 * Iteration 3: num = 23 + (1 * 100) = 123 * Now intValue = 123 */ long int num = 0; int multiplyValue = 1; char val = '0'; while(cstk1.pop(val)) { int valInInt = val - '0'; num += (valInInt * multiplyValue); multiplyValue *= 10; }

intValue = num; /* * Popping out each value fom stack cstk2 and generating the decimal value * Ex: s = 123.45 and cstk2 = 54, num = 0, doubleValue = 123 (equated to integer value) * Iteration 1: num = 0 + (5 * 1) = 5 * Iteration 2: num = 5 + (4 * 10) = 45 * Iteration 3: num = 45 / 100 = 0.45 * Now doubleValue = 123 + 0.45 = 123.45 */

doubleValue = double(num); num = 0; multiplyValue = 1; while(cstk2.pop(val)) { int valInInt = val - '0'; num += (valInInt * multiplyValue); multiplyValue *= 10; }

doubleValue += (double(num) / multiplyValue); success = true; return success; }

/* * Returning the integer value of the string converted */

long int convertToNumeric::getIntValue() { return intValue; }

/* * Returning the double value of the string converted */

double convertToNumeric::getDecValue() { return doubleValue; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!