Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a C++ program that defines value-returning functions for the arithmetic

ID: 653683 • Letter: 1

Question

1. Write a C++ program that defines value-returning functions for the arithmetic integer binary operation plus, minus, multiply, and divide, You should alsp wrote a value-returning function for the unary operation negate. Use your function declarations to compare the folowing as a single expression:

-(((5-4*(8/2))+7)

Your main function should not declare a single variable, but it should print as output the result of computing this expression. Your implementation is correct if your output yields the value -11.

Explanation / Answer

using namespace std; #include #include #include // This function takes an input as RPN notation and outputs what it evaluates to. // It expects the input to be proper RPN notation (for the most part) // This was coded during and after an interview with Square on 10/26/12 // SOME OUTPUT EXAMPLES: 4 1 + = 5 // 4 8 * = 32 // 4 5 4 + - = (5-4) + 4 = 5 // 4 2 5 5 5 5 / + - + - = (4/(2+(5-(5+(5-5))))) = 2 // 1 1 + 3 - 8 * 6 + = -2 // NOTICE:--------------------------------------------------------------- // NOTICE: the operators we can take in as input are: +, -, /, x, '*', * // ERROR CHECKING-------- /* CHECK 1. Support for negative numbers as arguments CHECK 2. Checking for extra operators CHECK 3. Checking for extra operands (you might already have this one) CHECK 4. Checking for invalid input (e.g. ./rpn @) CHECK 5. Checking for division by 0 CHECK 6. Support for unary plus (e.g. ./rpn 3 + should output 3) CHECK 7. Support for unary minus (e.g. ./rpn 3 - should output -3) CHECK 8. Declaring your operators in only one place, i.e. I should be able to add ^ to do power (e.g. ./rpn 2 3 ^ should output 8) without having to change operator checks in multiple places */ // ---------------------- bool isInt(char *num); // REQURIES: an array of characters that are numbers // EFFECTS: returns true if the array is full of digits, therefore making it an integer bool isOp(char *op); // REQUIRES: an array of characters that are operators. each operator can only be one char // EFFECTS: returns true if this is not a number and it is a single character array. The // check for being a legal operator will be done in int operation(int x, int y, char op); // REQUIRES: this takes in two ints and a char. the two ints are the operands, and the char is an operator // that is a single character. This function will only work for operators that are defined within // it. All edits to operations that we should include will be here. Anything else will be classified // as an undefined operator. // EFFECTS: returns value given by two operands and a LEGAL operator. int main(int argc, char* argv[]) // REQUIRES: this function requires inputs (as arguments) from the terminal. This function is only // made to take in ints and the designated operators. It then evaluates the expression. // EFFECTS: Returns the value of the expression, given that the expression is valid. { vector operands; // start by declaring our input vector int add_to_end; for(int i = 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote