Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, this is for programming in C++ . Please please please please FOLLOW the assignment below. I have several errors and I just dont know

Hello, this is for programming in C++. Please please please please FOLLOW the assignment below. I have several errors and I just dont know how to do this, please oh please help. I included the default programs that are included with this assignment at the bottom that need work as per the assignment instructs. Please follow the instructions. Use only what this assignment states please. I really really need help, Thank you sooooo very much, seriously.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Below are the default programs given for the assignment. they are as follow and are separated by dash symbols:
stack.cpp, stack.h, and dsexceptions.h.
-------------------------------------------------------------------------------------------------------------------------------
//stack.cpp
/**
* Construct the stack.
*/
template
Stack::Stack( int capacity ) : theArray( capacity )
{
topOfStack = -1;
}
/**
* Test if the stack is logically empty.
* Return true if empty, false otherwise.
*/
template
bool Stack::isEmpty( ) const
{
return topOfStack == -1;
}
/**
* Test if the stack is logically full.
* Return true if full, false otherwise.
*/
template
bool Stack::isFull( ) const
{
return topOfStack == theArray.size( ) - 1;
}
/**
* Make the stack logically empty.
*/
template
void Stack::makeEmpty( )
{
topOfStack = -1;
}
/**
* Get the most recently inserted item in the stack.
* Does not alter the stack.
* Return the most recently inserted item in the stack.
* Exception Underflow if stack is already empty.
*/
template
const Object & Stack::top( ) const
{
if( isEmpty( ) )
throw Underflow( );
return theArray[ topOfStack ];
}
/**
* Remove the most recently inserted item from the stack.
* Exception Underflow if stack is already empty.
*/
template
void Stack::pop( )
{
if( isEmpty( ) )
throw Underflow( );
topOfStack--;
}
/**
* Insert x into the stack, if not already full.
* Exception Overflow if stack is already full.
*/
template
void Stack::push( const Object & x )
{
if( isFull( ) )
throw Overflow( );
theArray[ ++topOfStack ] = x;
}
/**
* Return and remove most recently inserted item from the stack.
* Return most recently inserted item.
* Exception Underflow if stack is already empty.
*/
template
Object Stack::topAndPop( )
{
if( isEmpty( ) )
throw Underflow( );
return theArray[ topOfStack-- ];
}
--------------------------------------------------------------------------------------------------------------------------------------
//stack.h
#include "dsexceptions.h"
#include
using namespace std;
// Stack class -- array implementation
//
// CONSTRUCTION: with or without a capacity; default is 10
//
// ******************PUBLIC OPERATIONS*********************
// void push( x ) --> Insert x
// void pop( ) --> Remove most recently inserted item
// Object top( ) --> Return most recently inserted item
// Object topAndPop( ) --> Return and remove most recently inserted item
// bool isEmpty( ) --> Return true if empty; else false
// bool isFull( ) --> Return true if full; else false
// void makeEmpty( ) --> Remove all items
// ******************ERRORS********************************
// Overflow and Underflow thrown as needed
template
class Stack
{
public:
explicit Stack( int capacity = 10 );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
private:
vector theArray;
int topOfStack;
};
#include "stack.cpp"
------------------------------------------------------------------------------------------------------------------------------------------------
//dsexceptions.h
#ifndef _DSEXCEPTIONS_H_
#define _DSEXCEPTIONS_H_
class Underflow { };
class Overflow { };
class OutOfMemory { };
class BadIterator { };
class DataError { };
class DivisionByZero { };
#endif
-----------------------------------------------------------------------------------------------------------------------------------------------
This is the 6th time I posted this question, I Beg you, please follow the assignment I really need help
Objective Students will gain familiarity with using a user-created Stack class, exception handling, parsing algorithms, and working with postfix expressions. Assignment Summary Implement a simple stack-based calculator. It should work like dc. In Linur, dc is a reverse-polish (postfix) desk calculator. It reads from the standard input and sends output to the screen You are writing a client program whicl operations have already been implemented for you in stack.cpp. Exception handling should be provided for stack underflow, overflow, and any invalid operator which is entered by user h makes use of the stack operations in stack.h. These Name your client file dc.cpp and store it in a Prog2 directory of your class directory on your class account Calculator Operations Our version of dc will support integer arithmetic. To enter a negative number, begin with an u derscore (). The character cannot be used for this, as it is a binary operator for subtraction instead. To enter two numbers in succession, separate them with spaces or newlines. White space has no meaning as a command Your calculator should support the following operations p Prints the value on the top of the stack, without altering the stack. A newline is printed after the value n Prints the value on the top of the stack, pops it off, and does not print a newline after f Prints the entire contents of the stack without altering anything.A newline is printed after each value . c-Clears the stack, renderig t empty d Duplicates the value on the top of the stack, pushing another copy of i. Thus "4d*p" computes 4 squared and prints it r Reverses the order of (swaps) the top two values on the stack Pops two values off the stack, adds them, and pushes the result Pops two values, subtracts the first one popped from the second one popped, and pushes the result Pops two values, multiplies them, and pushes the result ./-Pops two values, divides the second one popped from the first one popped, and pushes the result % Pops two values, computes the remainder of the division that the / command would do. and pushes that Sample Run If the input is 2 3+ 4 6 P 4%p 2 100 3 4 5 f 5d*p rf2pc Then the output should be 23 5 4 3 102 3 25 5 25 4 3 102 3 Calculator Specifications 1. Don't set up your calculator to handle single digit integers only. Your calculator should be able to process all valid integers. Normally, of course, white space will separate two integers. The only exception could be if the user enters two consecutive negative integers. For example, 2.3 is valid input, and should push a -2 followed by a -3 onto the stack. 2. The user may attach operators to different integer operands. For example, is valid input. This should push a 2 onto the stack, pop the top two values from the stack and push their sum onto the stack, and then execute a printing of the top stack value 3. The user may also directly attach integer operands to operators. For example is valid input. This should pop the top two values and push their sum, print the top stack value, and then push a 2 onto the stack. 4. Use exception handling using the try, catch, and throw approach we studied in class with this program. Exceptions should be handled for stack underflow, stack overflow, and invalid calculator operators. Your stack.cpp file is already set up to throw stack underflow and overflow, and the file dsexceptions.h has already defined these exceptions for you. You just need to set up a try and catch block for them. You wll need to define your own exception for handling an invalid operator which is input or for division by zero. You should throw an exception when either occurs. A message should be printed to the user when any exception occurs, and the program should continue Client Program Notes 1. All strings in this program shoukd be implemented using string objects from the built-n string class. If the user enters a string that is all digits, you can easily convert a string of digits into its corresponding integer using the atoi function. For example string nyInput543" int numatoi (nyInput.cstrO) would assign integer 543 to num. The atoi function is defined in cstdlib. Do note that it is defined to accept an array of characters. If you wanted to convert a string object to an integer, you would need to use c strO operation. You may also find functions such as isdigit, isalpha, ete. from the cctype library very belpfal with this program To convert your underscore to a negative, you've got to treat it as a string first, change that underscore to a dash, then atoi it as seen below int inumber: t(sto]-) numberatoi (s.c.str) 2. To build a string up from scratch, you should make use of the oncatenation operator(+). Trying to build a string object up, by accessing the individual characters via the brackets does not work since the length() is never modified. 3. If the user enters a string that starts with a digit, but has operators attached to it, you are going to have to parse through this string, and chop off and save all characters after the last digit for later processing In addition, if they attach digits and operators following an operator, these characters must be saved for later processing. You should probably write functions to handle both of the scenarios just described 4. The calculator should continue executing until the end of file is reached on standard input No interactive prompts should be printed to user at start or finish except in the case of exception handling. 5. Use good, structured programming teclniques in the design of your elient program. There are a lot of different approaches you could take in coding this algorithm. Make sure your client program is as efficient as possible, your main function is clear and easy to follow, and every function in your client program incudes pre and post conditions

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

What does it mean to say that price elasticity of demand is 1.22?

Answered: 1 week ago

Question

Does it have correct contact information?

Answered: 1 week ago