
Hello, I need help with this c++ program.
Arithmetic.cpp
#include <cstdlib>
#include <iostream>
#include "ArrayStack.h"
float eval(std::string);
// The following main function should not be modified
int main(void) {
std::string expression = "Continue";
do {
std::cout << "Enter an arithmetic expression on a single line ('q' to end): ";
getline(std::cin, expression);
if (expression[0] != 'q') {
float result = eval(expression);
std::cout << expression << " = " << result << std::endl;
}
} while (expression[0] != 'q');
return 0;
}
float eval(std::string expr)
{ // To be implemented
// Any number of support functions may also be added
std::cout << "eval function not implemented" << std::endl;
return 0;
}
ArrayStack.cpp
#include <cassert>
#include "ArrayStack.h"
#include "StackException.h"
template <class T>
ArrayStack<T>::ArrayStack() : top(-1) {
// top = -1;
}
//ArrayStack::ArrayStack(const ArrayStack& orig) {
//}
//
//ArrayStack::~ArrayStack() {
//}
template <class T>
bool ArrayStack<T>::isEmpty() const {
return (top < 0);
}
template <class T>
T ArrayStack<T>::peek() const {
//If isEmpty(), what do I return?
//use precondition, if it fails program halts
assert(!isEmpty());
return items[top];
}
template <class T>
bool ArrayStack<T>::pop() {
bool result = false;
// if (!isEmpty()) {
// top--;
// result = true;
// }
// return result;
if (!isEmpty())
top--;
else
throw StackException("Pop called on an empty stack");
return result;
}
template <class T>
bool ArrayStack<T>::push(const T& newItem) {
bool result = false;
if (top < SIZE -1) {
top++;
items[top] = newItem;
result = true;
} else {
throw StackException("Push called on a full stack");
}
return result;
}
ArrayStack.h
#ifndef ARRAYSTACK_H
#define ARRAYSTACK_H
#include "StackADT.h"
const int SIZE = 50;
template <class T>
class ArrayStack : StackADT<T> {
public:
ArrayStack();
// ArrayStack(const ArrayStack& orig);
// virtual ~ArrayStack();
//interface methods
bool isEmpty() const;
bool push(const T& newItem);
bool pop();
T peek() const;
private:
// static const int SIZE = 50;
T items[SIZE];
int top;
};
#include "ArrayStack.cpp"
#endif /* ARRAYSTACK_H */
Main.cpp
#include <cstdlib>
#include <iostream>
#include "ArrayStack.h"
#include "StackException.h"
#include <stdexcept>
using namespace std;
/*
*
*/
int main() {
ArrayStack<int> intStack;
cout << "Beginning " << boolalpha << intStack.isEmpty() << endl;
for (int i=1; i<=5; i++) {
// try {
intStack.push(i);
// } catch (StackException e) {
// cout << e.what() << endl;
// }
}
cout << "After push " << boolalpha << intStack.isEmpty() << endl;
//check copy constructor
ArrayStack<int> numStack(intStack);
cout << "Copied item: " << numStack.peek() << endl;
intStack.pop();
cout << "Copied item: " << intStack.peek() << endl;
cout << "Copied item: " << numStack.peek() << endl;
cout << "Contents: ";
int sum = 0;
while (!intStack.isEmpty()) {
cout << intStack.peek() << " ";
sum += intStack.peek();
try {
intStack.pop();
} catch (StackException e) {
cout << e.what() << endl;
}
}
cout << endl << "Sum: " << sum << endl;
ArrayStack<string> strStack;
strStack.pop();
cout << "Did a problem occur with pop? " << endl;
// intStack.peek();
// cout << "Did a problem occur with peek? " << endl;
return 0;
}
StackADT.h
#ifndef STACKADT_H
#define STACKADT_H
template <class T>
class StackADT {
public:
virtual bool isEmpty() const = 0;
virtual bool push(const T& newItem) = 0;
virtual bool pop() = 0;
virtual T peek() const = 0;
};
#endif /* STACKADT_H */
StackException.cpp
#include <string>
#include "StackException.h"
StackException::StackException(const std::string& msg) : logic_error (msg) {
}
StackException.h
#ifndef PUSHEXCEPTION_H
#define PUSHEXCEPTION_H
#include <stdexcept>
#include <string>
class StackException : public std::logic_error {
public:
StackException(const std::string& msg = "");
private:
};
#endif /* PUSHEXCEPTION_H */



Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- C++languagearrow_forward#include <iostream> #include <cmath> using namespace std; // declare functions void display_menu(); void convert_temp(); double to_celsius(double fahrenheit); double to_fahrenheit(double celsius); int main() { cout << "Convert Temperatures\n\n"; display_menu(); char again = 'y'; while (again == 'y') { convert_temp(); cout << "Convert another temperature? (y/n): "; cin >> again; cout << endl; } cout << "Bye!\n"; } // define functions void display_menu() { cout << "MENU\n" << "1. Fahrenheit to Celsius\n" << "2. Celsius to Fahrenheit\n\n"; } void convert_temp() { int option; cout << "Enter a menu option: "; cin >> option; double f = 0.0; double c = 0.0; switch (option) { case 1: cout << "Enter degrees Fahrenheit: "; cin >> f; c =…arrow_forwardCode in c++ pleasearrow_forward
- Create a flowchart for this program in c++, #include <iostream>#include <vector> // for vectors#include <algorithm>#include <cmath> // math for function like pow ,sin, log#include <numeric>using std::vector;using namespace std;int main(){ vector <float> x, y;//vector x for x and y for y float x_tmp = -2.5; // initial value of x float my_function(float x); while (x_tmp <= 2.5) // the last value of x { x.push_back(x_tmp); y.push_back(my_function(x_tmp)); // calculate function's value for given x x_tmp += 1;// add step } cout << "my name's khaled , my variant is 21 ," << " my function is y = 0.05 * x^3 + 6sin(3x) + 4 " << endl; cout << "x\t"; for (auto x_tmp1 : x) cout << '\t' << x_tmp1;//printing x values with tops cout << endl; cout << "y\t"; for (auto y_tmp1 : y) cout << '\t' << y_tmp1;//printing y values with tops…arrow_forwardGiven the following set of code, select all C++ expressions: 4₁ #include #include #include #include "grocery_list_lib.h" // Returns an array of pair objects of item and amount std::array, 5> create_grocery_list (){ std::array, 5 grocery_list; std::string item; std::string item_amount; F3 double amount; for(int i = 0; i > amount grocery_list[i].second = amount; } return grocery_list; } grocery_list[i].first std::string item; item_amount return grocery_list; "Enter item: $ 4 4) R Q Search DII % 5 T F5 6 LO F6 Y F7 & 7 U BO PrtScn F8 8 Home F9 9 End F10 Po 0arrow_forward// LargeSmall.cpp - This program calculates the largest and smallest of three integer values. #include <iostream> using namespace std; int main() { // This is the work done in the housekeeping() function // Declare and initialize variables here int largest; // Largest of the three values int smallest; // Smallest of the three values // Prompt the user to enter 3 integer values // Write assignment, add conditional statements here as appropriate // This is the work done in the endOfJob() function // Output largest and smallest number. cout << "The largest value is " << largest << endl; cout << "The smallest value is " << smallest << endl; return 0; }arrow_forward
- This is C++ Please i need it ASAP I will give you thumbs uparrow_forward#include <iostream> #include <cmath> using namespace std; // declare functions void display_menu(); void convert_temp(); double to_celsius(double fahrenheit); double to_fahrenheit(double celsius); int main() { cout << "Convert Temperatures\n\n"; display_menu(); char again = 'y'; while (again == 'y') { convert_temp(); cout << "Convert another temperature? (y/n): "; cin >> again; cout << endl; } cout << "Bye!\n"; } // define functions void display_menu() { cout << "MENU\n" << "1. Fahrenheit to Celsius\n" << "2. Celsius to Fahrenheit\n\n"; } void convert_temp() { int option; cout << "Enter a menu option: "; cin >> option; double f = 0.0; double c = 0.0; switch (option) { case 1: cout << "Enter degrees Fahrenheit: "; cin >> f; c =…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





