CMPE 180A Data Structures and Algorithms in C++ Spring 2018

Similar documents
CMPE 180A Data Structures and Algorithms in C++ Spring 2018

CMPE 180A Data Structures and Algorithms in C++ Spring 2018 Instructor: Ron Mak

CMPE Data Structures and Algorithms in C++ Spring 2018

CMPE 180A Data Structures and Algorithms in C++ Spring 2018

CMPE 180A Data Structures and Algorithms in C++

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

CMPE 152 Compiler Design

CMPE 152 Compiler Design

CMPE 152 Compiler Design

CS/SE 153 Concepts of Compiler Design

Lecture 3 Tao Wang 1

CS/SE 153 Concepts of Compiler Design

Chapter 2, Part III Arithmetic Operators and Decision Making

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

The simplest way to search for and enroll in classes is to do so via the Enrollment Shopping Cart.

San José State University College of Science/Department of Computer Science CS 152, Programming Language Paradigms, Section 03/04, Fall, 2018

CS 211 Programming Practicum Fall 2018

Instructor Feedback Location and Printing. Locating Instructor Feedback When Available within Canvas

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Tips from the experts: How to waste a lot of time on this assignment

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

IT 374 C# and Applications/ IT695 C# Data Structures

MATH 2221A Mathematics Laboratory II

CMPE/SE 135 Object-Oriented Analysis and Design

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

CS2110 Assignment 2 Lists, Induction, Recursion and Parsing, Summer

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Advanced Web 2. Course Information. Instructor Information. Course Objectives

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

INFS 2150 (Section A) Fall 2018

EECE.2160: ECE Application Programming Spring 2019

CS 330 Homework Comma-Separated Expression

a f b e c d Figure 1 Figure 2 Figure 3

CISC 3130 Data Structures Spring 2018

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Tips from the experts: How to waste a lot of time on this assignment

Only to be used for arranged hours. Order of Operations

Full file at C How to Program, 6/e Multiple Choice Test Bank

3. When you process a largest recent earthquake query, you should print out:

Taskstream Terminology

Lab 7 1 Due Thu., 6 Apr. 2017

San José State University Computer Science CS 122 Advanced Python Programming Spring 2018

CS 2604 Minor Project 1 DRAFT Fall 2000

Final Project. This assignment demonstrates your understanding of the concepts from the CMIS 141 class.

Web Programming Spring 2010

CS 200, Section 1, Programming I, Fall 2017 College of Arts & Sciences Syllabus

CMPE 280 Web UI Design and Development

JOHNSON COUNTY COMMUNITY COLLEGE COURSE SYLLABUS WEB CRN Web Scripting: JavaScript I

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Programming. C++ Basics

Departmental Schedule Validator (DSV) Procedure Manual

San José State University Department of Computer Science CS-174, Server-side Web Programming, Section 2, Spring 2018

Welcome to CS 135 (Winter 2018)

CpSc 1111 Lab 5 Formatting and Flow Control

Computer Science 1321 Course Syllabus

A Simple Syntax-Directed Translator

CS 2604 Minor Project 1 Summer 2000

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

Course: Honors AP Computer Science Instructor: Mr. Jason A. Townsend

Art 645 Introduction to Web Site Design Los Angeles City College

Departmental Schedule Validator (DSV) Procedure Manual

Departmental Schedule Validator (DSV) Procedure Manual

CSCI 4000 Assignment 4

Lecture 5 Tao Wang 1

1 Lexical Considerations

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CMPE 280 Web UI Design and Development

Welcome to CS 135 (Fall 2018) Themes of the course. Lectures. cs135/

CS112 Lecture: Making Choices

CSCI 3300 Assignment 6

Spring 2017 CMSC 140 Programming Project 7: Payroll

Introduction to Programming System Design CSCI 455x (4 Units)

Chapter 4: Control Structures I (Selection)

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

ITP454 Enterprise Resource Planning, Design, and Implementation

Assignment Manager. Change Edit Mode to On if it is not already by clicking on the option at the top right of the window.

South Portland, Maine Computer Information Security

15-110: Principles of Computing, Spring 2018

Computer Programming CS F111

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Problem Solving with C++

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

ITP489 In-Memory DBMS for Real Time Analytics

Introduction to Programming

CISC 3130 Data Structures Fall 2018

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Learning the Language - V

Chapter 7 Arithmetic

The following expression causes a divide by zero error:

CSCI 201L Syllabus Principles of Software Development Spring 2018

Assignment 1. Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do

Finally, a receipt is printed on the screen and, after a pause, the process repeats for the next customer.

Rochester Institute of Technology Golisano College of Computing and Information Sciences Department of Information Sciences and Technologies

Programming Assignment 2 ( 100 Points )

San José State University Department of Computer Science CS 166 / SE 166, Information Security, Section 4, spring, 2017

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Spring 2018

Transcription:

San José State University Department of Computer Engineering CMPE 180A Data Structures and Algorithms in C++ Spring 2018 Assigned: Thursday, April Due: Thursday, April 12 at :30 PM Canvas: Assignment #10. Calculator Points: 100 with extra credit Calculator Instructor: Ron Mak Assignment #10 This assignment will give you practice with mutual recursion. Write a Calculator class that prompts for and evaluates arithmetic expressions and then prints their results. An expression contains numbers and the operators + - * and /. An expression can also contain parenthesized subexpressions nested arbitrarily deeply. Syntax diagrams Use these syntax diagrams to help you design your Calculator member functions. An expression is either a single term, or a term followed by more terms separated by + or operators. A term is either a single factor, or a factor followed by more factors separated by * or / operators. A factor is either a number or a parenthesized expression. Expressions can be nested arbitrarily deep. A number is a C++ double that can be read by >> Require each expression end with an = sign. Ignore blanks in the expressions. 1

Precedence rules Your program must abide by the normal precedence rules: Operators * and / have higher precedence than + and -. Evaluate parenthesized subexpressions first, and when there are nested parentheses, evaluate the innermost subexpressions first. If your program follows the syntax diagrams, it will implement the precedence rules correctly. If there are several consecutive operators at the same precedence level and there are no parentheses, evaluate from left to right. Therefore, for 1 + 2 + 3 + 4 add 3 to the sum of 1 and 2 and then add 4 to that sum. Error handling Your calculator should catch syntax errors such as invalid operators or unbalanced parentheses. It should catch attempts to divide by zero. Print an appropriate error message, ignore the rest of the expression, and prompt for the next expression. Sample output Here is a sample interaction with the calculator program. You choose what expressions to enter, but they should show off the capabilities of your program. Include expressions that contain errors. Expression? 42 = 42 Expression? 2*(42-42e-1) = 7.6 Expression? 12/(.*(17 + 0.00314E+3)) = 0.108333 Expression? 6%2 = 6 ***** Unexpected % Expression? 12/(.*(17 + 0.00314E+3) = ***** Missing ) Expression? ((((())))) = Expression? ()) + 2 = ***** Unexpected ) Expression? /(6-2*3) = ***** Division by zero Expression?. Done! 2

Program design Create a Calculator class with appropriate member functions expression, term, and factor. Write the main in a separate file. No CodeCheck This program is interactive, and you choose the expressions to give it and the format of its prompts and answers. Therefore, you will not use CodeCheck for this assignment. This also means that you will write the program in its entirety. Submission into Canvas Cut and paste into a text file a sample run of your program with a good sample of expressions. Zip this text file along all your C++ source files. Name the zip file after yourself and submit it into Canvas: Assignment #10. Calculator. Rubric Your program will be graded according to these criteria: Criteria Good program execution User interaction (prompts for expressions, etc.) Correct evaluation of expressions Good examples of program capabilities (all operators, nested parenthesized subexpressions, etc.) Error handling (invalid operator, division by zero, etc.) Good program design Class Calculator Member functions expression, term, and factor Separate calculator test program (with main) Good program style Descriptive variable names. Meaningful comments. Follow the coding style (formatting, braces, indentation, function declarations before the main, etc.) of the Savitch textbook. Max points 40 30 30 3

Extra credit #1 (up to 10 points) Allow a leading - (minus) sign to negate a value. Examples: - -2*3 -(4+) For completeness, you should also allow a leading + sign which will have no effect. You should not allow an operator next to a leading + or - sign (blanks don t count as separators). Examples of invalid expressions: 2*-3 6--2 7/+3 Tip: You only need to modify one of the syntax diagrams to allow the optional leading + or - sign. Extra credit #2 (up to 2 points) Implement exponentiation with the ^ operator. For example, 2^3 is 2 3. Add member function power. Exponentiation has the highest precedence. For example, evaluate 1+2*3^4 as 1+(2*(3^4)) Consecutive exponentiation in the absence of parentheses is evaluated right to left. Therefore evaluate 2^3^4 as 2^(3^4), i.e., 2 "! Modify the syntax diagrams to accommodate the exponentiation operator. Your new diagrams should give the ^ operator the highest precedence and show that it is evaluated right to left. Example output with both extra credits: Expression? -= - Expression? += Expression? -2*3= -6 Expression? 4*(-+2)= -12 Expression? -(2+3)= - Expression? +(-3)= 2 Expression? 6--3= Expression? 3*-2= Expression? 3/ +2= 4

Expression? 2^3= 8 Expression? 2^3^4= 2.4178e+24 Expression? (2^3)^4= 4096 Expression? 64^0.= 8 Expression? 26^(1/4)= 4 Expression? 26^(-1/4)= 0.2 Expression?. Done! Tip: Look up the C++ pow function. Academic integrity You may study together and discuss the assignments, but what you turn in must be your individual work. Assignment submissions will be checked for plagiarism using Moss (http://theory.stanford.edu/~aiken/moss/). Copying another student s program or sharing your program is a violation of academic integrity. Moss is not fooled by renaming variables, reformatting source code, or re-ordering functions. Violators of academic integrity will suffer severe sanctions, including academic probation. Students who are on academic probation are not eligible for work as instructional assistants in the university or for internships at local companies.