Exercise: Inventing Language

Similar documents
Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Exercise 1.1 Hello world

Unit 3. Constants and Expressions

Integer Data Types. Data Type. Data Types. int, short int, long int

CS242 COMPUTER PROGRAMMING

Exercise: Using Numbers

Variables and numeric types

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

CS201- Introduction to Programming Current Quizzes

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

Data Types & Variables

C++ Programming: From Problem Analysis to Program Design, Third Edition

Variables and Constants

Lecture 2 Tao Wang 1

IT 1033: Fundamentals of Programming Data types & variables

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

CSc Introduction to Computing

Getting started with C++ (Part 2)

The C++ Language. Arizona State University 1

BASIC ELEMENTS OF A COMPUTER PROGRAM

VARIABLES AND TYPES CITS1001

A First Program - Greeting.cpp

Review of Important Topics in CS1600. Functions Arrays C-strings

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Data Structures and Programming with C++

CS2141 Software Development using C/C++ C++ Basics

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

LECTURE 02 INTRODUCTION TO C++

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

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

Expressions and Casting

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

Homework #3 CS2255 Fall 2012

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

3. Simple Types, Variables, and Constants

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

CS Programming I: Primitives and Expressions

Objectives. In this chapter, you will:

Fundamentals of Programming CS-110. Lecture 2

1. In C++, reserved words are the same as predefined identifiers. a. True

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Fundamental Data Types

Pointers II. Class 31

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

UNIT- 3 Introduction to C++

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

a data type is Types

Basics of Java Programming

LECTURE 3 C++ Basics Part 2

CHAPTER 3 BASIC INSTRUCTION OF C++

Arrays. Lecture 9 COP 3014 Fall October 16, 2017

CSI33 Data Structures

Variables. Data Types.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Reference operator (&)

Sixth lecture; classes, objects, reference operator.

CHAPTER 3 Expressions, Functions, Output

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Differentiate Between Keywords and Identifiers

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS

Introduction to Programming EC-105. Lecture 2

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

C++ Programming for Non-C Programmers. Supplement

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Exam 3 Chapters 7 & 9

Chapter 2 Working with Data Types and Operators

CSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Computational Expression

Introduction to C An overview of the programming language C, syntax, data types and input/output

Declaration and Memory

CIS 130 Exam #2 Review Suggestions

Expressions, Statements, Variables, Assignments, Types

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

1007 Imperative Programming Part II

Final Labs and Tutors

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Pointers. Reference operator (&) ted = &andy;

Midterms Save the Dates!

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

These are reserved words of the C language. For example int, float, if, else, for, while etc.

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato,

Chapter 2 Basic Elements of C++

Transcription:

Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM)

Exercise: Inventing Language Get a separate (not your notes!) paper Discuss question 1 with your neighbor Write out possible answers to questions 2 & 3 (you re going to hand this paper in) Given that memory is a big place to store pieces of information: 1. How might you organize it? 2. What is a reasonable statement to tell the computer to store the number 68 somewhere? 3. What is a reasonable statement to get that number back out of storage and print it to the screen?

Addressing Memory Sequential locations where data can be stored Each location has an address (an integer) A computer with 1 Gigabyte of RAM has a billion 1-byte locations to store data The first location is at address 0 The last location is around address 999,999,999 Data is stored and retrieved by address Could use the actual location number Easier if we are able to name locations store this data at location stan get whatever data is a location stan

Allocating Space Before a program can store a piece of data, it has to allocate space in main memory This involves reserving memory at some location and giving that location a name That name is called a variable The program uses the variable to store and retrieve data This is done with a variable declaration statement Made up of a type and a name For example: int x; Where int is the type and x is the name

Every variable has a type Data Types Just like every piece of data (integer, real number, character, string) A variable can only store data of the same type Some C++ data types: int float char string Integer (whole number, positive or negative) Real number (includes decimal, positive or negative) Character String of characters

Identifiers (Variable Names) Consist of letters, digits, and the underscore character (_) Must begin with a letter or underscore C++ is case sensitive NUMBER is not the same as number

Identifiers (continued) The following are legal identifiers in C++: first conversion payrate C++ Programming: Program Design Including Data Structures, Fourth Edition

Assignment Operator The assignment operator (=) stores a piece of data in a memory location LHS argument: the variable where you want to store it RHS argument: the data to store For example, storing the number 4 (an integer) is a two-step process: First, allocate memory by declaring a variable of type integer int myvariable; Then, assign it the piece of data myvariable = 4; We say that myvariable has the value 4

Assignment and Expressions Remember that an operand can be any expression that evaluates to the right type of data So the RHS of an assignment can be an expression: int x; x = 5 + 6 7; The RHS of an assignment is always evaluated first, then the resulting value is stored

Using Stored Data Variable are used to store and retrieve data Up to this point we have used literal data in our expressions: cout << 41; Instead, we can use a stored piece of data: int x; x = 41; cout << x; A variable can go in any expression where a literal piece of data could go

Using Stored Data Variables are reusable Each assignment stores a new value and over writes the old int x; x = 5; cout << x; x = 6; cout << x; x = x + 10; cout << x;

Exercise (Still on that same sheet of paper) What gets printed on the screen when this code runs? int x; int y; cout << Hello ; cout << endl; x = 1 + 4 3; cout << x; cout << endl; y = x 1; y = y + 5; cout << y; cout << endl;

Exercise (yeah, same paper) Write C++ statements to do the following: Declare an integer variable called banana Declare an integer variable called hamster Assign banana the value 56 Assign hamster the value 22 added to the value of banana Print out the value of hamster

Function scope Variables are declared inside functions We say they have function scope Those variables are only valid inside the function they are declared in The name is meaningless outside Think of memory as being divided up between the functions Each function gets its own chunk of memory Variables declared in a function allocate memory in that chunk When the function is done, that chunk is erased