UMBC CMSC 104 – Section 01, Fall 2016

Slides:



Advertisements
Similar presentations
CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
Advertisements

1 ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Solving Equations Medina1 With Decimal & Fractions.
A First Book of ANSI C Fourth Edition
General Programming Introduction to Computing Science and Programming I.
ORDER OF OPERATIONS x 2 Evaluate the following arithmetic expression: x 2 Each student interpreted the problem differently, resulting in.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
7 th grade Mathematics - 5 Order of Operation 7 th grade Mathematics - 5 Order of Operation.
Lecture 41 Arithmetic Clauses The ROUNDED clause –Place ROUNDED after the variable that holds the result ADD A TO B ROUNDED. ADD A TO B GIVING C ROUNDED.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
Doing math In java.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
1 Variables and Arithmetic Operators in JavaScript.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
1-2 Order of Operations Objective: Use the order of operations to evaluate expressions.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Chapter Sections 1.1 – Study Skills for Success in Mathematics
Introduction to Computing Science and Programming I
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
UMBC CMSC 104 – Section 01, Fall 2016
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions
BASIC ELEMENTS OF A COMPUTER PROGRAM
Lecture 3: Operators, Expressions and Type Conversion
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Revision Lecture
Assignment and Arithmetic expressions
Variables and Arithmetic Operators in JavaScript
Computer Science 101 While Statement.
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Relational & Logical Operators
Lecture 3 Expressions Richard Gesick.
Arithmetic Operators in C
Arithmetic Expressions in C
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Variables and Arithmetic Operators in JavaScript
Arithmetic Operators in C
Arithmetic Expressions & Data Conversions
Chapter 2 Variables.
Introduction to C Topics Compilation Using the gcc Compiler
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
UMBC CMSC 104 – Section 01, Fall 2016
CS150 Introduction to Computer Science 1
Core Objects, Variables, Input, and Output
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
Algorithms computer as the tool process – algorithm
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
CS150 Introduction to Computer Science 1
INC 161 , CPE 100 Computer Programming
Data Types and Expressions
Topics Designing a Program Input, Processing, and Output
Introduction to C Topics Compilation Using the gcc Compiler
Topics Designing a Program Input, Processing, and Output
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Unit 3: Variables in Java
Chapter 2 Variables.
Chapter 2, Part III Arithmetic Operators and Decision Making
Data Types and Expressions
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Presentation transcript:

UMBC CMSC 104 – Section 01, Fall 2016 Arithmetic Ops

Notes & Announcements Project 3 Grades posted to website tonight Class average was 72%, or 79.5% without zeros. Review grading guidelines in a moment… Exam Grades posted to website tonight Class average was 72%, or 75.2% without zeros. Review in a moment… Project 4 posted tonight! Due November 1st Project 5 to be posted Thursday! You might want to get a head start on Project 4… CSEE Department is distributing Mid-semester surveys Please respond!

The Survey

Project 3 Grading Guidelines

C Program Grading Breakdown Per the Syllabus C Program Grading Breakdown 15% Style 15% Documentation 20% Correctness 50% Execution

Problem 1 - Cube Problem 1 (15 pts total) ------------------------ Documentation: 2 points - 1pt Header (take all points if it doesn't match the template, or description bad) - 1pt Comments (-1 if no comments or if comments inadequate) Style: 2 points (round up) - .5pt proper whitespace usage (2-4 spaces indentation) - .5pt brackets match one of acceptable styles - .5pt followed naming conventions (including all uppercase for #define) - .5pt consistency Execution: 8 points - Lose ALL points if code does not compile - 1pt - Used #define for constants - 3pt - Used floats where appropriate (-3 if used all integers) - 1pt - Floats printed properly (and decimal values not truncated) - 3pt - Proper error checking (-2pt if some exists, but possible to bypass) Correctness: 3 points - 3pt - Calculations are correct, including decimal values

Problem 2 - Box Problem 2 (30 pts total) ------------------------ Documentation: 4 points - 2pt Header (take all points if it doesn't match the template, or description bad) - 2pt Comments (-2 if no comments included, -1 if comments inadequate) Style: 4 points - 1pt proper whitespace usage (2-4 spaces indentation) - 1pt brackets match one of acceptable styles - 1pt followed naming conventions (including all uppercase for #define) - 1pt consistency Execution: 15 points - Lose ALL points if code does not compile - 2pt - All 3 input variables are error checked - 5pt - Used floats where appropriate (-5 if used all integers) - 3pt - Floats printed properly (and decimal values not truncated) - 5pt - Proper error checking (-3pt if some exists, but possible to bypass) Correctness: 7 points - 7pt - Calculations are correct, including decimal values

Problem 3 - Cake Problem 3 (30 pts total) ------------------------- Documentation: 4 points - 2pt Header (take all points if it doesn't match the template, or description bad) - 2pt Comments (-2 if no comments included, -1 if comments inadequate) Style: 4 points - 1pt proper whitespace usage (2-4 spaces indentation) - 1pt brackets match one of acceptable styles - 1pt followed naming conventions (including all uppercase for #define) - 1pt consistency Execution: 15 points - Lose ALL points if code does not compile - 2pt - Used #define for constants - 5pt - Used floats where appropriate (-5 if used all integers) - 3pt - Floats printed properly (to TWO DECIMAL PLACES!) - 5pt - Proper error checking (-3pt if some exists, but possible to bypass) Correctness: 7 points - 2pt - Total number of people displayed - 5pt - Calculations are correct, including decimal values

Exam 1 Review

Current Grade Distribution

Switching Gears We’ve spent a lot of time laying groundwork What makes a computer, what is an algorithm, how to use Linux, etc. From here on out, the focus is mostly on programming in C, as well as problem solving Keep thinking like a computer! Take a minute to think about how far we’ve come. Keep up the good work!

Arithmetic Operators in C Name Operator Example Addition + num1 + num2 Subtraction - initial – spent Multiplication * fathoms * 6 Division / sum / count Modulus % m % n

Division If both operands of a division expression are integers, you will get an integer answer. The fractional portion is thrown away. Examples : 17 / 5 = 3 4 / 3 = 1 35 / 9 = 3

Division & Floating Points Review Division where at least one operand is a floating point number will produce a floating point answer. Examples : 17.0 / 5 = 3.4 4 / 3.2 = 1.25 35.2 / 9.1 = 3.86813 What happens? The integer operand is temporarily converted to a floating point, then the division is performed.

Division By Zero Division by zero is mathematically undefined. If you allow division by zero in a program, it will cause a fatal error. Your program will terminate execution and give an error message. Non-fatal errors do not cause program termination, just produce incorrect results.

Modulus The expression m % n yields the integer remainder after m is divided by n. Modulus is an integer operation -- both operands MUST be integers. Examples : 17 % 5 = 2 6 % 3 = 0 9 % 2 = 1 5 % 8 = 5

Uses for Modulus Used to determine if an integer value is even or odd 5 % 2 = 1 odd 4 % 2 = 0 even If you take the modulus by 2 of an integer, a result of 1 means the number is odd and a result of 0 means the number is even. The Euclid’s GCD Algorithm (done earlier)

Rules of Operator Precedence Operator(s) Precedence & Associativity ( ) Evaluated first. If nested (embedded), innermost first. If on the same level, left to right. * / % Evaluated second. If there are several, evaluated left to right. + - Evaluated third. If there are several, evaluated left to right. = Evaluated last, right to left.

a + b * c Would multiply b * c first, then add a to the result. Using Parentheses Use parentheses to change the order in which an expression is evaluated. a + b * c Would multiply b * c first, then add a to the result. If you really want the sum of a and b to be multiplied by c, use parentheses to force the evaluation to be done in the order you want. (a + b) * c Also use parentheses to clarify a complex expression.

Practice With Evaluating Expressions Given integer variables a, b, c, d, and e, where a = 1, b = 2, c = 3, d = 4, evaluate the following expressions: a + b - c + d a * b / c 1 + a * b % c a + d % b - c e = b = d + c / b - a

Project 4

Questions?