Introduction to TURING

Similar documents
2.2 Order of Operations

Summer Assignment Glossary

Introduction to Programming in Turing. Input, Output, and Variables

Accuplacer Arithmetic Study Guide

Rules of Exponents Part 1[Algebra 1](In Class Version).notebook. August 22, 2017 WARM UP. Simplify using order of operations. SOLUTION.

CCBC Math 081 Order of Operations Section 1.7. Step 2: Exponents and Roots Simplify any numbers being raised to a power and any numbers under the

1-6 Order of Operations

ALGEBRA I Summer Packet

Unit 1 Integers, Fractions & Order of Operations

Any Integer Can Be Written as a Fraction

A. Incorrect! To simplify this expression you need to find the product of 7 and 4, not the sum.

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

Section A Arithmetic ( 5) Exercise A

Integers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not.

Unit 3: Multiplication and Division Reference Guide pages x 7 = 392 factors: 56, 7 product 392

Using Basic Formulas 4

Chapter 4 Section 2 Operations on Decimals

CHAPTER 1B: : Foundations for Algebra

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

The simplest way to evaluate the expression is simply to start at the left and work your way across, keeping track of the total as you go:

Section 1.1 Definitions and Properties

Lecture 2 Tao Wang 1

Lesson 1: Arithmetic Review

Math Glossary Numbers and Arithmetic

FUNDAMENTAL ARITHMETIC

Watkins Mill High School. Algebra 2. Math Challenge

Math 6 Unit 2: Understanding Number Review Notes

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Learning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties

>>> * *(25**0.16) *10*(25**0.16)

Example 2: Simplify each of the following. Round your answer to the nearest hundredth. a

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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

Chapter 4. Operations on Data

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

The Absolute Value Symbol

Ex: If you use a program to record sales, you will want to remember data:

Programming for Engineers Introduction to C

3.1 Using Exponents to Describe Numbers

PLT Fall Shoo. Language Reference Manual

1.1 Review of Place Value

Using Custom Number Formats

College Prep Algebra II Summer Packet

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Rev Name Date. . Round-off error is the answer to the question How wrong is the rounded answer?

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

(-,+) (+,+) Plotting Points

Calculations with Sig Figs

Math 171 Proficiency Packet on Integers

by Pearson Education, Inc. All Rights Reserved. 2

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Topic 2: Introduction to Programming

Working with Algebraic Expressions

Student Success Center Arithmetic Study Guide for the ACCUPLACER (CPT)

Solving Equations with Inverse Operations

Learning the Language - V

Rational numbers as decimals and as integer fractions

Chapter 1: Foundations for Algebra

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Chapter 1: Number and Operations

EXAMPLE 1. Change each of the following fractions into decimals.

Learning Log Title: CHAPTER 3: PORTIONS AND INTEGERS. Date: Lesson: Chapter 3: Portions and Integers

or 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.

GAP CLOSING. Grade 9. Facilitator s Guide

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Gateway Regional School District VERTICAL ALIGNMENT OF MATHEMATICS STANDARDS Grades 3-6

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

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

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left

Iron County Schools. Yes! Less than 90 No! 90 No! More than 90. angle: an angle is made where two straight lines cross or meet each other at a point.

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Full file at

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Algebra 1 Review. Properties of Real Numbers. Algebraic Expressions

Chapter 17. Fundamental Concepts Expressed in JavaScript

Lesson 1: Arithmetic Review

Basics of Java Programming

JME Language Reference Manual

TI-84+ GC 3: Order of Operations, Additional Parentheses, Roots and Absolute Value

Office 2016 Excel Basics 12 Video/Class Project #24 Excel Basics 12: Formula Types and Formula Elements

HOW TO DIVIDE: MCC6.NS.2 Fluently divide multi-digit numbers using the standard algorithm. WORD DEFINITION IN YOUR WORDS EXAMPLE

REVIEW. The C++ Programming Language. CS 151 Review #2

Arithmetic Operations

Evaluating Expressions Using the Order of Operations

Algebraic Expressions

SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Lecture 2 FORTRAN Basics. Lubna Ahmed

Get to Know Your Calculator!

Mini-Lectures by Section

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Only to be used for arranged hours. Order of Operations

CIV Module Unit Session Learning Objectives

Transcription:

Introduction to TURING Comments Some code is difficult to understand, even if you understand the language it is written in. To that end, the designers of programming languages have allowed us to comment our code. In Turing, this is done by placing the percent sign (%) before a comment. % This is a comment. Everything after the % on this line is ignored by the computer. Another way of commenting code is by using matching sets of "/*" and "*/" /* This is a comment. Everything after the forward-slash-asterisk but before the matching asterisk-forward-slash is ignored by the computer. */ Output We want to put some text on the screen, to prove that the link between us and the computer does in fact exist. Let me repeat that again: We want to put some text on the screen. In Turing, we do this by using the put command, followed by the text, contained in double quotes, that we want to output, like this: put "Hello World" Variable Types Strings: Characters: Integers: We have already encountered the string. Now let us answer the unrelenting question, "What is a string?" A string is a sequence of characters. The characters can be ordinary things such as letters and numbers, or they can be wacky things found in the ASCII chart such as the plus-minus sign (à ±). A string is bounded by quotation marks, as in "Yarr! I caught me aye fish!" A string can contain a maximum of 255 characters. A character is a single letter, number, or any wacky symbol that you can find in the ASCII chart. Characters are bound by quotation marks, as in 'Q'. Generally, strings use double quotes and characters use single quotes, though either type can use either style of quotation mark. We should all know what an integer is, given some fundamental math. Just to make sure, an integer is a whole number; it has no decimals; it is a fraction whose denominator is 1; it can be negative, zero, or positive. Real Numbers:

Boolean: Real numbers can contain decimal places. Turing supports up to 16 decimal places for real numbers. Real numbers contain the realms of the positive, the negative, and zero. The boolean (named after George Boole) variable type contains only two alternatives: true or false. We will look into these in greater depth later, particularly when learning about conditions or if statements. Returning to Output Now that we know our Hello World program output a string on the screen, let's experiment with the other variable types. Let's try outputting an integer, then a real number. put 7 % Outputs 7 put 8.19538032154 % Outputs 8.19538 Notice how the real number was rounded. Now I know everyone loves arithmetic, so it's about time we did some. Quickly now, (4 + 8) / 2 * (3-5) equals what? put (4 + 8) / 2 * (3-5) % Outputs -12 Turing does the math following the precedence rules, BEDMAS (Brackets, Exponents, Division and Multiplication, Addition and Subtraction). Now let's output the question and the answer: put "(4 + 8) / 2 * (3-5) = ", (4 + 8) / 2 * (3-5) % Output: (4 + 8) / 2 * (3-5) = -12 Notice the use of the comma (,). The comma separates one section from the next. The first section is a string, which shows us the question. The next section is an integer, which is the answer. Strings can be added together, a process called concatenation: we are taking one value and placing another value directly after it. put "Hello " + "Alan Turing." % Outputs "Hello Alan Turing." Turing 001 Put The put command is used to print information to the screen. put "Hello World!"...prints Hello World! (without the quotes) to the screen. Write a program that prints your first name to the screen. Save as "001.t". Turing 002 Put II

Type in the following program, then identify and fix any errors: put "Hi, I am a PENTIUM" "put Hi, I am a PENTIUM" put Hi, I am a PENTIUM Correct the errors and save as "002.t" Turing 003 Program Header All programs should include a program header. This header should, as a minimum, include a program description, the author s (programmer s) name, the date, and the filename. An example header is shown below: % author: Jane Doe % date: 2003-09-06 % filename: put2.t % description: prints user s name to the screen Note that a percent sign ( % ) is used before each of the header lines. These are used to tell the Turing program to ignore these lines and treat them like comments. For most programs written in this class, you may copy and paste my requirements into the "description" part of the program header. If it is too wide to fit on the screen, break it up into two or more lines. Add an appropriate program header to 001.t. Save as "003.t". Turing 004 Concatenation By appending two periods (.. ) to a put statement, the next put statement will print its output on the same line as the first statement. Example: put "tom".. put "boy"...prints "tomboy" on the screen. Add a line to 003.t that prints your last name after your first name. Be sure it prints on the same line. Add another line to your program so there is a space between your first name and your last name. Save as "004.t". Turing 005 Addition

The addition operator in Turing is the plus sign ("+"). The following statement adds the numbers 3 and 4: put 3 + 4 Write a program that prints the sum of 5, 6, and 7. Save as "005.t". Turing 006 Addition II Write a program that prints the sum of 5.123 and 6.29. Save as "006.t". Turing 007 Addition III Modify 006.t so that there are two put statements. The first puts the two values to be added, and the second does the math. The output should look similar to "The sum of and is. ". Save as "007.t". The subtraction operator in Turing is a hyphen ( - ). Turing 008 Subtraction The following statement subtracts the number 3 from 4: put 4-3 Write a program that subtracts 5 from 6. Save as "008.t". Turing 009 Multiplication

The multiplication operator in Turing is an asterisk ("*"). The following statement multiplies the numbers 3 and 4: put 3 * 4 Write a program that prints the product of 5 and 6. Save as "009.t". Turing 010 Division The division operator in Turing is a slash ( / ). The following statement divides the number 3 by 4: put 3 / 4 Write a program that prints the quotient of 5 divided by 6. Save as "010.t". Turing 011 Exponents The exponent operator in Turing is two asterisks ( ** ). The following statement calculates the square of 3 (3 2 ): put 3 ** 2 Write a program that prints the answer of 2 to the exponent 8. Save as "011.t".

Turing 012 Order of Operation Remember from math class that 3 + 2 X 5 = 13, not 25. The same holds true for Turing. Even though Turing will calculate algebraic equations properly, it is good programming practice to group items into their intended order of operation by surrounding them with parentheses (round brackets). For example, the above equation, written with a Turing put statement, is better written as: put 3 + (2 * 5) A more complex equation may be written as: put 12 + ( ( 4-6 ) / 3 ) Things to remembers: Turing uses '*' for multiplication, not 'x' Turing uses '**' for exponentiation Turing only uses parentheses (round brackets), not square brackets Brackets can be nested (inside each other), and it is strongly encouraged if it makes the statement clearer Write a program that prints the equivalent of each of the following algebraic statements to the screen: 2 + 4 x 5 2 x 6-4/2 8 + 2 (4+9/3) 3[(4+12)-2(3-1)] 23 + 42-6/3 Write each Turing statement so the output looks like the following: 2 + 4 x 5 = 22...where "22" is calculated with your programmed formula. Save as "012.t".