please follow the steps carfully and i dont want you to do it your way i need it
ID: 661124 • Letter: P
Question
please follow the steps carfully and i dont want you to do it your way i need it the way the project wants it , thank you.
PART 1: Design and implement a linked Stack class.
PART2: Write a program that uses stacks to evaluate an arithmetic expression.
The program takes as input a numeric expression, such as 3+4*2, and outputs the result.
1) Operators are +, -, *, /
2) Assume that the expression is formed correctly so that each operation has two arguments.
3) The expression can have parenthesis, for example: 3*(4-2)+6.
4) The expression can have negative numbers.
5) The expression can have spaces in it, for example: 3 * (4-2) +6 .
Here are some useful method that you may need:
char cin.peek() -- returns the next character of the cin input stream ( without reading it)
bool isdigit(char c) -- returns true if c is one of the digits
Explanation / Answer
#include #include #include #include #include using namespace std; double midpointCalc(double point_a, double point_b); double distanceCalc(double xa, double xb, double ya, double yb); int main(void) { const char holder = 'x'; // inputs double xa; double ya; double xb; double yb; char t; bool errmes1 = false; bool errmes2 = false; bool errmes3 = false; char yes_no; double midx; // outputs double midy; double distance; cout yes_no; cin.ignore(INT_MAX, ' '); while ( toupper(yes_no) == 'Y' ) { errmes1 = false; errmes2 = false; errmes3 = false; cout > ws; // get whitespace t = cin.peek(); //find out what's after whitespace if (!isdigit(t) && // if its not a number or a + or - t != '-' && t != '+') { cin >> t; // then we'll take it } else { t = holder; // if a number has been entered fill t up with a value errmes1 = true; // turn on condition for error message later } cin >> xa; // then actually read the number cin >> ws; // repeat t = cin.peek(); if (!isdigit(t) && t != '-' && t != '+') { cin >> t; } else { t = holder; errmes2 = true; } cin >> ya; while (cin.peek() != ' ' && isspace(cin.peek())) { cin.ignore(); } if (cin.peek() != ' ') { cin >> t; } else { t = holder; errmes3 = true; } if (errmes1 == true) { cerr t; } else { t = holder; errmes1 = true; } cin >> xb; cin >> ws; t = cin.peek(); if (!isdigit(t) && t != '-' && t != '+') { cin >> t; } else { t = holder; errmes2 = true; } cin >> yb; while (cin.peek() != ' ' && isspace(cin.peek())) { cin.ignore(); } if (cin.peek() != ' ') { cin >> t; } else { t = holder; errmes3 = true; } if (errmes1 == true) { cerrRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.