COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Manipulating Data Concepts Covered: Literal values, variables and Types Variables.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Chapter 2 Data Types, Declarations, and Displays
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Computer Science 1620 C++ - Basics. #include using namespace std; int main() { return 0; } A very basic C++ Program. When writing your first programs,
COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Iterative Statements Concepts Covered: Iterative Statements (counter-based) Iterative.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
CIS Computer Programming Logic
Chapter 1: Introduction to Computers and Programming.
Input & Output: Console
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CS161 Computer Programming Instructor: Maria Sabir Fall 2009 Lecture #1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Fundamental Programming: Fundamental Programming Introduction to C++
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Data as the computer sees it 1.  Number systems Number systems  Data storage Data storage  Glossary Glossary 2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
C OMPUTER P ROGRAMMING 1 Input and Variables. I/O S TATEMENTS : I NPUT & V ARIABLES Input is the term used to describe the transfer of information from.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1: Introduction to Computers and Programming.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Topics Designing a Program Input, Processing, and Output
BASIC ELEMENTS OF A COMPUTER PROGRAM
Topic: Python’s building blocks -> Variables, Values, and Types
ITEC113 Algorithms and Programming Techniques
Object Oriented Programming
Revision Lecture
Variables, Expressions, and IO
Variables ,Data Types and Constants
IDENTIFIERS CSC 111.
Microsoft Visual Basic 2005 BASICS
Chapter 2 Edited by JJ Shepherd
Language Basics.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Primitive Types and Expressions
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Getting Started With Coding
Presentation transcript:

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Manipulating Data Concepts Covered: Literal values, variables and Types Variables declarations Variables assignments Input / Output operations Statements Part 1 Module 1

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 2 Manipulating Data Concept: Literal values

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 3 Give me some examples of values you might use in everyday life:

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 4 These are possible answers to the previous question… 20ft 32˚F cm "Alessio Gaspar" "COP 2510 Programming Concepts" We can easily categorize them: –Numerical value, Strings, … –This leads us to the concept of data type

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 5 Manipulating Data Concept: Data Types

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 6 Numerical  Integer numbers in base 10  Integer numbers in other bases (octal, hexadecimal, binary)  Floating point numbers in decimal notation  Floating point numbers in scientific notation Strings 20ft 32˚F cm "COP 2510 Programming Concepts" Values belong to different TYPES

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 7 Numerical –Integer numbers in base 10 –Integer numbers in other bases (octal, hexadecimal, binary) –Floating point numbers in decimal notation –Floating point numbers in scientific notation Strings Values belong to different TYPES

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 8 Value String Numerical Integer Floating Point Numerical  Integer numbers in base 10  Integer numbers in other bases (octal, hexadecimal, binary)  Floating point numbers in decimal notation  Floating point numbers in scientific notation Strings Values belong to different TYPES

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 9 Value String Numerical Integer Floating Point This view of types is a little “raw” Numerical –Integer numbers in base 10 –Integer numbers in other bases (octal, hexadecimal, binary) –Floating point numbers in decimal notation –Floating point numbers in scientific notation Strings Values belong to different TYPES

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 10 Value String Numerical Integer Floating Point This is closer to the kind of “types” we use everyday in real life Numerical –Temperatures –Distances –Duration –Quantity Strings –Employee Last Name –Street Name –Whole Address Values belong to different TYPES

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 11 Valid Ranges –Smallest / biggest possible value –E.g. $1,000,000 in a bank account is suspicious for me –E.g Celsius degrees on your thermometer is suspicious too Encodings –0010 is binary for the decimal value 2 –3 is decimal for 0011 in binary –A is hexadecimal for 10 Value String Numerical Integer Floating Point (more about this later…) Values can have a meaning (“semantics”) which dictates characteristics such as:

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 12 Literal value: i.e. How do we write a value in a computer program? –10 vs –20.3 –“what are you doing in my swamp?” –0xA same as 10 s.a. 011 s.a Idea of type –Integer number: short, int, long… –Floating point number: float, double, long double… –Single character: ‘a’ –String: “this is a string” –Each with SYNTACTICAL notations and range values When manipulating data in a computer, we capture some of these everyday life practices “some” not “all” Values in a program are typed in a formal way We’ll see very soon why it is so…

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 13 Manipulating Data Summary: Literals and Data Types

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 14 What we have so far Literal values can be written in computer programs by following some syntactical conventions These values belong to data types which the programming language can manipulate and, as such, have characteristics such as the range of possible values, the lowest value, the highest value…

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 15 So… We can imagine that programming languages will allow us to write operations on these values E.g. Compute The results can be –Displayed / written to disk / sent over the internet to another program… But… what about applications which need to keep results of previous operations handy? –A word processor keeps the text you’re writing in memory somewhere until you close the application –A budget software will store your expenses, compute their sum, keep the value of your balance in memory We need to introduce another programming concept… variables

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 16 Manipulating Data Concept: Variables

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 17 What is the purpose of a variable? To Store data More specifically, each variable stores one value at a time This allows you to use the result of a computation later on

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 18 How do programming languages let you use variables in your programs? Assigning values to variables Here are examples of different syntax that have been used over the years in various languages: A := A  A = 2 + 3

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 19 How do programming languages let you use variables in your programs? Assigning values to variables Here are examples of different syntax that have been used over the years in various languages: Variable Name Assignment Operator Expression Resulting in a Value Generic Syntactical Diagram: A := A  A = 2 + 3

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 20 Doing i/o operations with variables Displaying the value of a variable on the screen Displaying the result of an expression combining variables and literal values on the screen Reading a value from the user (keyboard) and storing it in a variable How do programming languages let you use variables in your programs?

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 21 What is a variable in a computer program? The 2 last items relate to the idea of encoding An identifier (a name) to refer to it more easily than by having to specify the memory address at which it’s located A TYPE which determines - How much memory is needed to store the value - How to read this value Some space in memory to store a value in it –SIZE of this memory space –ADDRESS at which it’s located

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 22 All this can be specified when declaring variables The idea of TYPE is related to how values are stored in computer memory Declaring Variables

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 23 All variables we discussed so far can hold only a single value at a time We will discuss in an upcoming module how we can group values together in aggregate variables Going a little further: Grouping Variables?

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 24 Statements We saw some examples of statements: Declare a variable Assign a value to a variable Now what? Learning to program, regardless of the programming language, will require us to get familiar with typical available statements