Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Problem: Example Code: *** int_stack.h file: #ifndef INT_STACK_H #define INT_STACK_H const int STACKSIZE = 100; class int_stack { public: int_stack(); bool pop(int& item); bool

The Problem:

image text in transcribed

Example Code:

*** int_stack.h file:

#ifndef INT_STACK_H #define INT_STACK_H

const int STACKSIZE = 100;

class int_stack { public: int_stack(); bool pop(int& item); bool push(int item);

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

int top; int stk[STACKSIZE]; };

#endif

*** int_stack.cpp file:

#include "int_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 integer array. When the stack is empty, top must be set to -1. */

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

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

bool int_stack::pop(int& 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 int_stack::push(int 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 int_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 int_stack::isFull() const { return (top == (STACKSIZE - 1));

Write a C++ class to convert a string representing a positive integer or positive decimal value into the long int and double numeric types. If the string value represents a decimal value, the converted integer version will be truncated. If the string value represents an integer, the converted decimal value will have a decimal portion of zero. Input string "123" "12.45" Integer conversion 123 12 Decimal conversion 123.0 12.45 Your code must use a character stack class in your conversion. You may use two stacks for the conversion if you wish. Your stack class must be based on the integer stack class in the example code below. Your "convert to numeric" class should have member functions for the following tasks: an overloaded constructor that accepts the string to convert a convert member function that accepts a string and returns a boolean success status a getintValue member function that returns the converted value as a long int a getDecValue member function that returns the converted value as a double Create a driver program to demonstrate your class. The driver will prompt the user and accept a string representing a positive integer or decimal, then use your class to convert it. Finally, demonstrate the converted value is useable with any type specific operation, both as a long int and double. Write a C++ class to convert a string representing a positive integer or positive decimal value into the long int and double numeric types. If the string value represents a decimal value, the converted integer version will be truncated. If the string value represents an integer, the converted decimal value will have a decimal portion of zero. Input string "123" "12.45" Integer conversion 123 12 Decimal conversion 123.0 12.45 Your code must use a character stack class in your conversion. You may use two stacks for the conversion if you wish. Your stack class must be based on the integer stack class in the example code below. Your "convert to numeric" class should have member functions for the following tasks: an overloaded constructor that accepts the string to convert a convert member function that accepts a string and returns a boolean success status a getintValue member function that returns the converted value as a long int a getDecValue member function that returns the converted value as a double Create a driver program to demonstrate your class. The driver will prompt the user and accept a string representing a positive integer or decimal, then use your class to convert it. Finally, demonstrate the converted value is useable with any type specific operation, both as a long int and double

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions

Question

b. Compute the variance. Pg45

Answered: 1 week ago