General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
General Computer Science for Engineers CISC 106 Lecture 01 James Atlas Computer and Information Sciences 9/2/2009.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Chapter 2: Input, Processing, and Output
Chapter 2: Introduction to C++.
Variables, Constants and Built-in Data Types Chapter 2: Java Fundamentals.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
General Computer Science for Engineers CISC 106 Lecture 01 James Atlas Computer and Information Sciences 6/8/2009.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Variables, Expressions and Statements
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 2/13/2009.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
A Sample Program #include using namespace std; int main(void) { cout
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Introduction to Python Lesson 2a Print and Types.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
Fundamentals 2.
Topic: Python’s building blocks -> Variables, Values, and Types
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
IDENTIFIERS CSC 111.
2.1 Parts of a C++ Program.
Unit-1 Introduction to Java
Chapter 2: Java Fundamentals
Chapter 2: Java Fundamentals
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
General Computer Science for Engineers CISC 106 Lecture 03
Use a variable to store a value that you want to use at a later time
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010

Course Overview Explain lab00.py on computer Show it running. Add errors. Atomic data and variables Sample Function Function composition

Atomic Data : Numbers and Strings - Numbers : floats, integers Can use “type” to find out the data type of something. type(5) # int type (5.0) # float -Strings Some examples : “hello” and ‘hello’ type(“hello”) # str “hello” + “world” # plus symbol concatenates two strings

Atomic Data (cont’d) # Can mix and match numbers >>> # Cannot mix numbers and strings “hello” + 3 # Builtin convert between types str(100) int(“5”)

Variables Concept: A variable is a name that represents a value stored in the computer’s memory. Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Variables (cont’d) Creating Variables with Assignment Statements Assignment Statement variable = expression >>> age = 25 where, variable name of the variable = assignment operator expression value or piece of code that results in a value The age variable references the value 25 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Variables Naming Rules Can not use Python key words Can not contain spaces First character must be one of the letters a through z, A through Z, or an underscore character(_) After the first character use letters a through z, A through Z, digits 0 through 9, or underscore Uppercase and lowercase characters are distinct Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Variable Naming Conventions For readability use one of the below styles for multiword variable name: Use the underscore character to represent a space gross_pay hot_dogs_sold_today camelCase naming convention grossPay hotDogsSoldToday Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Same Variables Names Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

circleArea function def circleArea(radius) : “”” computes the area of a circle radius – number return – number “”” PI = # constant variable (use caps) return PI * radius ** 2 assertEqual(circleArea(4), )

Now, what if we want to calculate area of a ring A ring of two concentric circles we can use our circleArea function = -

Area of a ring pi * (r1) ** 2 – pi * (r2) ** 2 first circle second circle circleArea(r1) - circleArea(r2) Note: Can create a function called ringArea that takes two parameters and calls circleArea twice!

ringArea function def ringArea(r1, r2) : “”” calculates area of ring given outer r1 and inner r2 r1 – number r2 – number return – number “”” return circleArea(r1) – circleArea(r2)