Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Problem: *** Be sure to use both public and private classes, and be sure have the user input the positive value. *** Example Code:

The Problem:

image text in transcribed

*** Be sure to use both public and private classes, and be sure have the user input the positive value. ***

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

}

*** main driver file:

#include #include #include "int_stack.h" using namespace std; int main() { int_stack istk; int item; random_device rd; for (int i = 0; i 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_2

Step: 3

blur-text-image_3

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

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

=+37-2 Explain how some needs are more compelling than others.

Answered: 1 week ago

Question

1. What is called precipitation?

Answered: 1 week ago

Question

1.what is dew ?

Answered: 1 week ago

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

5. Describe the visual representations, or models, of communication

Answered: 1 week ago