Outline - Brigham Young University

Outline - Brigham Young University

1 Lab 05 Expressions Requirements Lab 05 - Expressions 2 Input is an expression string in infix notation. Expression: 43 + 2 * 19 Use an ExpressionManager class to hold your infix, postfix, (and prefix) expressions. Your class should be derived from the abstract interface class ExpressionManagerInterface.

Implement member functions: virtual int value(void); virtual string infix(void); virtual string postfix(void); virtual string prefix(void); Output the resulting infix, postfix, (prefix), and integer evaluation value of the expression. Your calculations should perform integer division and produce

integer results. Example Input / Output Lab 05 - Expressions 3 Input Expression: 2 + 3 - 5 Infix: Postfix: Prefix: Value: Expression: 43 + 2 * 19 Infix: Postfix: Prefix: Value:

Output Expression: Infix: Postfix: Prefix: Value: 43 + 43 + 43 2 + 43 81 2 * 19 2 * 19 19 * + * 2 19 Input Output Expression:

Infix: Postfix: Prefix: Value: 2 2 2 0 + + 3 + 3 3 + 2 5 3 5 5

5 Converting from Infix to Postfix 4 Lab 05 - Expressions Converting from Infix to Postfix 5 Lab 05 - Expressions Converting from Infix to Postfix 6 Lab 05 - Expressions ExpressionManagerInterface Lab 05 - Expressions 7 //YOU MAY NOT MODIFY THIS HEADER INTERFACE #ifndef EXPRESSION_MANAGER_INTERFACE_H #define EXPRESSION_MANAGER_INTERFACE_H

#include using std::string; class ExpressionManagerInterface { public: ExpressionManagerInterface(void) {}; virtual ~ExpressionManagerInterface(void) {}; ExpressionManagerInterface is an interface. DO NOT MODIFY! /** Return the integer value of the infix expression */ virtual int value(void) = 0; /** Return the infix items from the expression Throw an error if the expression 1) is not balanced. 2) the number of operators IS NOT one less than the number of operands. 3) there are adjacent operators. */ virtual string infix(void) = 0; /** Return a postfix representation of the infix expression */ virtual string postfix(void) = 0; ExpressionManager

/** (BONUS) Return a prefix representation of the infix expression */ virtual string prefix(void) { return "NOT IMPLEMENTED"; } /** Return the infix vector'd expression items */ virtual string toString() const = 0; }; #endif // EXPRESSION_MANAGER_INTERFACE_H ExpressionManagerInterface ExpressionManager Lab 05 - Expressions 8 class ExpressionManager : public ExpressionManagerInterface { private: string expression_; std::vector inFix_; Inherits from std::vector postFix_; ExpressionManagerInterface std::vector preFix_;

const string operators = "([{ -+ */% "; public: ExpressionManager() { } ExpressionManager(string exp) : expression_(exp), inFix_(NULL), postFix_(NULL), preFix_(NULL) { } ~ExpressionManager() { } virtual int value(void); /** Return the integer value of the infix expression */ virtual string infix(void); /** Return the infix expression / rejects invalid */ virtual string postfix(void); /** Return a postfix representation */ virtual string prefix(void); /** (BONUS) Return a prefix representation */ virtual string toString() const; /** Return the infix vector'd expression inFix to PreFix Lab 05 - Expressions 9 Given two operands a and b and an operator ,

The infix notation implies that will be placed in between a and b. When the operator is placed after both operands , it is called postfix notation. And when the operator is placed before the operands a b, the expression in prefix notation. Example: To convert (A + B) * C to prefix: 1. Reverse the infix expression (A+B)*C becomes C*(B+A). Note: while reversing each ( will become ) and each ) becomes (. 2. Obtain the postfix expression (almost) of the modified expression. Push operator on stack is greater than or equal. C*(B+A) becomes CBA+*. 3. Reverse the postfix expression. CBA+* becomes the prefix expression *+ABC.

Recently Viewed Presentations

  • Chlamydiosis Mammalian - Iowa State University

    Chlamydiosis Mammalian - Iowa State University

    In koalas, C. pneumoniae has been isolated from the respiratory tract, the eye and the urogenital tract. ... endemic herds C. felis Infections common in cats Conjunctivitis in kittens TRANSMISSION Life Cycle Elementary body (EB) Small, metabolically inert Stable in...
  • AP Statistics - Mrs. Wroblewski

    AP Statistics - Mrs. Wroblewski

    The distribution of hours of sleep is skewed left; more AP Statistics students at ChiArts get 6-7 hours of sleep than 3-4 hours of sleep. (no outliers) The median number of hours of sleep is 6, with a range of...
  • Minerals Information Team - USGS

    Minerals Information Team - USGS

    This period marked the redevelopment of the Japanese and West German economies. Indian copper smelters also had difficulty obtaining concentrate (London Mining Journal, 6Feb04). State-owned Minmetals bought 51% of the Sherwin, Texas alumina refinery (London Mining Journal, 30Apr04). Minmetals has...
  • By Jerry Niebaum Endacott Society Computer Study Group

    By Jerry Niebaum Endacott Society Computer Study Group

    By Jerry Niebaum Start here to compare costs of Prescription Drug Plans Enter your personal info here Then click here Then click here This is the one This is our choice for this example Lipitor Enter a drug name then...
  • Canadian Institute of Actuaries L'Institut canadien des actuaires

    Canadian Institute of Actuaries L'Institut canadien des actuaires

    Canadian Institute of Actuaries L'Institut canadien des actuaires 2008 General Meeting Assemblée générale 2008 Toronto, Ontario Report on CIA Group Committee Gen O8 - November 2008 Gary Walters CIA Group Committee Mandate The Group Committee will: Provide a resource on...
  • Water Treatment Wastewater Treatment

    Water Treatment Wastewater Treatment

    Removes pathogens and toxic elements to prepare water for use in homes and businesses. Makes water potable (drinkable) Steps for water treatment. ... (softens hard water) aeration (add O2) - removes odors to improve taste ... Water Treatment Wastewater Treatment
  • Information Theory and Pattern-based Data Compression

    Information Theory and Pattern-based Data Compression

    Times New Roman Arial Symbol Monotype Sorts Diseño predeterminado Microsoft Editor de ecuaciones 3.0 Information Theory and Pattern-based Data Compression Contents Information source Ergodic source Information The meaning Entropy Data Compression Huffman encoding Example Huffman codes Extensions of a source...
  • King Saud University College of Applied studies and

    King Saud University College of Applied studies and

    Array - One Dimensional Array. A one dimensional array is a list of related variables have the same data type and the same name . Represented as a group of consecutive memory locations . To refer to a particular location...