CS 135 Lab Assignments Week 1

Similar documents
CS 135 Lab Assignments Week 12

CS 135 Lab Assignments Week 13

Lecture 2: Variables & Assignments

DOWNLOAD PDF BIG IDEAS MATH VERTICAL SHRINK OF A PARABOLA

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Chapter 1: Foundations for Algebra

Chapter 12: Quadratic and Cubic Graphs

Midterms Save the Dates!

Only to be used for arranged hours. Order of Operations

Here redirection. Case statement. Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March 5, 2004

Welcome to CS 115 (Winter 2019)

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra


Operators. Lecture 3 COP 3014 Spring January 16, 2018

Welcome to CS 115 (Winter 2018)

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Project 2: How Parentheses and the Order of Operations Impose Structure on Expressions

Expressions and Casting

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #23 Loops: Precedence of Operators

LECTURE 3 C++ Basics Part 2

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

BIG IDEAS. A.REI.D.10: Interpret Graphs as Sets of Solutions. Lesson Plan

CS1 Lecture 3 Jan. 18, 2019

Lesson Plan -- Multiplying and Dividing Integers

Lecture 2. Variables & Assignment

2.2 Order of Operations

CS1 Lecture 3 Jan. 22, 2018

Excel Functions & Tables

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

Chapter 4: Basic C Operators

Math 1525: Lab 4 Spring 2002

Welcome to 5 th Grade Math Review Properties of Operations

Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto

Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore

Introduction to the workbook and spreadsheet

CSI Lab 02. Tuesday, January 21st

2 Unit Bridging Course Day 2 Linear functions I: Gradients

VARIABLES & ASSIGNMENTS

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

CMSC201 Computer Science I for Majors

1.8 Intro to Variables, Algebraic Expressions, and Equations

Programming Lecture 3

Logical Operators and switch

(Refer Slide Time: 00:03:51)

COMP Primitive and Class Types. Yi Hong May 14, 2015

AP Computer Science Summer Work Mrs. Kaelin

Algebra 2 Semester 1 (#2221)

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Use the Associative Property of Multiplication to find the product.

Microsoft Excel 2010 Handout

More Complicated Recursion CMPSC 122

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Introduction and Functions

Lesson 6: Manipulating Equations

Functions and Families

Lab 7 1 Due Thu., 6 Apr. 2017

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Math 3 Coordinate Geometry Part 2 Graphing Solutions

Operators And Expressions

Think: 5 5 5, or 25. Think: Think: Evaluate Multiply. So, when s 2, the value of. 5(s 3) is 125. Then divide.

State the domain and range of the relation shown in the graph. Is the relation a function? You try: A relation is represented by

Exponential Notation

Department of Computer Science

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Summer Math Assignments for Students Entering Algebra II

Teachers Teaching with Technology (Scotland) Teachers Teaching with Technology. Scotland T 3. Matrices. Teachers Teaching with Technology (Scotland)

SEQUENCES AND SERIES Sequences CC Standard

Assessment of Programming Skills of First Year CS Students: Problem Set

ECE Object-Oriented Programming using C++ and Java

Welcome back! Sit down and work on the warm up!

Lab 4 Projectile Motion

Summer Math Assignments for Students Entering Integrated Math

Operators & Expressions

Dealing with Output. Producing Numeric Output CHAPTER 3. Task. Figure 3-1. The program in action

Technical Arts 101 Prof. Anupam Saxena Department of Mechanical engineering Indian Institute of Technology, Kanpur. Lecture - 7 Think and Analyze

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 14: OCT. 25TH INSTRUCTOR: JIAYIN WANG

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

4. Write sets of directions for how to check for direct variation. How to check for direct variation by analyzing the graph :

CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS112 Lecture: Making Choices

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

DECIMALS are special fractions whose denominators are powers of 10.

Section 1.2 Fractions

Bits, Words, and Integers

CSCI 204 Introduction to Computer Science II. Lab 6: Stack ADT

Coefficient Constant Equivalent expressions Equation. 3 A mathematical sentence containing an equal sign

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

CS1110 Lab 1 (Jan 27-28, 2015)

Perl: Arithmetic, Operator Precedence and other operators. Perl has five basic kinds of arithmetic:

Mathematical Reasoning. Lesson 37: Graphing Quadratic Equations. LESSON 37: Graphing Quadratic Equations

Section 1.1 Definitions and Properties

Marketing Research Participation for BUAD 307

In math, the rate of change is called the slope and is often described by the ratio rise

Section we will not cover section 2.11 feel free to read it on your own

Transcription:

CS 135 Lab Assignments Week 1 Professor: Matt B. Pedersen This handout is the assignment that you must finish for the lab portion of the course in week 1. You must finish the assignments yourself; if you need any help ask the TA or the professor. You may not work together with other students in solving the assignments. The weekly assignments must be handed in on a piece of paper, typed neatly (spell checked etc.) and look nice. The assignments are due in the the professor s mailbox labeled Matt Pedersen in TBE-A211 the following Wednesday before the computer science office closes at 5pm. All lab assignments must be handed in if you wish to attend the final exam. Late assignments are not accepted for any reason except sickness or family emergencies, and the former requires a doctors notice. 1 Question 1 Consider a simple expression in everyday arithmetic like 1+2. Using the rules of arithmetic we can calculate its value, which is 3. Let us call expressions that consist of only one operator and two operands for simple. What about a more complicated expressions like 4+2+1 (i.e., one that is not simple)? What is its value? It is well known that parentheses can be placed in such a way that, if evaluated according to the rules of arithmetic, all expressions are simple when they are evaluated. For example, 4+2+1 can be written as 4+(2+1) or if you like (4+2)+1. Either way if we evaluate the expression we get: 4+(2+1) = 4+3 = 7 or (4+2)+1 = 6+1 = 7. When the operand is + the placement of the parentheses does not matter, but what if the expression was 4-2-1? (4-2)-1 is not the same as 4-(2-1). The former evaluates to (4-2)-1 = 2-1 = 1 and the latter to 4-(2-1) = 4-1 = 3. The same problem arises when we use division (/): the placement of the parentheses matter. Which one is the correct one? (4-2)-1 is. Therefore, the correct answer is 1. The arithmetic we use is left associative if we do not use parentheses. Be careful though, because some operators like * and / take 1

precedence over others like + and -. For example, 4-8/2 is not the same as (4-8)/2, because / has higher precedence than -. The correct expression with parentheses is 4-(8/2). Using parentheses, convert the following non-simple expressions into expressions using parentheses such that when we evaluate it, we only evaluate simple expressions. The parentheses should be placed such that the value of the converted expressions is the same as the value of the expressions without the parentheses. For example, 4/2-3 has the value -1, so the correct way to convert this expressions is (4/2)-3. Also state what the value of the expression is. 4-5-7+4-1*8/4 1+2+3-4-5-6 16/4/2+1 2 Question 2 Expressions can also contain variables. You know this from math when we have expressions like x + 2. The value of x + 2 depends on the value of x. If x has the value 5 then x + 2 is equal to 5+2=7. If x has the value 4 and y has the value 5 what is the value of the expressions x + 2 y? Using parentheses, transform x + 2 y like we did in question 1. What should the value of x be for the expressions x/y 2 to be equal to 3 if y is equal to 5? 2

Find at least 2 sets of values for x and y such that the expression x y/2 is equal to 0. 3 Question 3 In math you will have seen expressions like y = 2 x 1 We can determine the value of y if we know the value of x (and if we draw a graph, then we get a straight line with a slope of 2 crossing the y-axis at -1. y gets a new value every time we evaluate the expression on the right (2 x 1). Consider the following more complex equation: y = x 2 + 2 x 3 and fill in the correct values for y in the table below with the given values for x. 4 Question 4 x -5-3 0 2 4 As mentioned earlier, different operators have different precedences, for example in the non-parenthesized expression x y 2 the multiplication has higher precedence than subtraction. Some operators like + and - have the same precedence. y b + b 2 4 a c 2 a in this rather complex expression (which you will probably recognize as the positive solution of the quadratic equation) we have used both + and - as well as * and /; furthermore, we have used a unary minus (in front of the b; this could have been written as (0-b)) as well as exponentiation (b 2, which 3

of course could have been written as (b b)). Write out the expression using parentheses (and only simple expressions) such that when evaluated it produces the same result as in the expression above. Also list the operators used in order of precedence from highest to lowest. 5 Question 5 I am going to invent a new operator which we will call gets the value of, and its use looks like this: x 5 and it reads x gets the value of 5. After evaluating and expressions using this operator, the value of the expression on the right will be placed in the variable on the left. Naturally the following is illegal: and so is 5 6 7 x + 6 as you cannot change the value of a number! The following is legal though: x 5 1 y x + 2 After the first expression has been evaluated, x has the value of 5-1 (i.e., 4), and when we subsequently evaluate x + 2 we get 4-2 which is 2 and that becomes the value of y. Consider this sequence of expressions: x 2 y x 5 x y 2 What is the value of x and the value of y once we have evaluated all three expressions? After the first expressions clearly x has the value 2! At this point we cannot say anything about the value of y. To evaluate the second expression we need to evaluate the expression x 5, which is 10 (as x was 4

2), and we now know that y is 10 and x has not changed (we only used the value of x on the right hand side of the second expression, not changed it!), so it remains 2. But what happens after the third expression? The right hand side of the this expression is y 2 which is 10-2 which is 8, so x get the value of 8 (changing it from its old value of 2). So in the end, y is 10 and x is 8. What is the value of x, y and z after the following expressions have been evaluated (always evaluate expressions in order starting from the top and then move down, one at a time remembering the values of variables already given values): x 4 y 5 x 2 x y 2 z x + y When evaluating expressions with the operator it is important to think of the right hand side as something that evaluates to a value (by using arithmetic and remembering what values were stored in any variables used in the expression) and the left hand side (which is always a variable) as a container that can hold a single value, which can change only when using the operator. The way an expression with the is evaluated is always Compute the value of the right hand side using arithmetic and by using the values of any variables, and once you have a single value, that value now gets given to the variable on the left. With this in mind we can write something like this: x 1 x x + 1 What is the value of x after these two expressions? 5