Top Banner
Unit 2: Logical Thinking Development Activity 1.1: Data Containers
20

U2_A1.1_DataContainers

Jan 20, 2016

Download

Documents

Daniel Marquez

Teach variables and data containers for basic programming languages
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: U2_A1.1_DataContainers

Unit 2:Logical Thinking

Development

Activity 1.1: Data Containers

Page 2: U2_A1.1_DataContainers

Hardware: Physical components that make up a computer. A system of devices, where each device has a specific function.

Software: Instructions that make a

computer work. Programs that run in a computer and that make a computer useful to the user.

Computer Systems: Hardware and Software

Page 3: U2_A1.1_DataContainers

3

Hardware

CPU

RAM MEMORY

INPUT DEVICES

SECONDARY STORAGE

OUTPUT DEVICES

Page 4: U2_A1.1_DataContainers

4

Where is the data needed to perform an operation stored? The computer memory stores

the information. Data is kept in storage

locations in computer memory The memory is divided in

addresses, in which the data is stored.

Memory

Page 5: U2_A1.1_DataContainers

5

Memory locations (computer´s working area) that store data whose contents can vary over time, but that hold just one value at any given time.

Normally a name is given to them to identify them easily.

In programming language are known as variables and they represent a location in the computer´s RAM memory.

A variable is declared depending on the type of data that is going to store.

Data containers

Page 6: U2_A1.1_DataContainers

6

Data types determine how a data is represented on the computer and the type of processing that the computer can perform over that data.

Computers deal with two basic types of data text and numeric.

Depending on the computer language the name given to the data type changes, but in general they can be classified in: oNumericoStringoBoolean

Data types

Page 7: U2_A1.1_DataContainers

7

Some languages allow several types of numeric data, a general classification may be (they can be more….). Integer: Positive or negative numbers

without fractional part, whole numbers. o Examples: 4, -125, 15000, -79, 365

Real: Positive or negative numbers with a whole part and a fractional part, (contain a decimal point). o Examples: -3.56, 765.2342, -56.9, 8.0

Numeric

Page 8: U2_A1.1_DataContainers

8

Data that holds a group of letters, numbers or special symbols.

To assign a value data must be enclosed in quotation marks (single or double).

Examples:o “Hello World!”o “John Doe”o “Broadway 451”o “8151-4300”

String

Page 9: U2_A1.1_DataContainers

9

Data type that can hold one of two possible values: True or False.

Used to select alternative actions (selection). o Named after George Boole (1815-1864) a famous

English mathematician that described a logical system using variables with only one of two different values.

Boolean

Page 10: U2_A1.1_DataContainers

10

Depending on the computer language the rules for naming the data containers change, but in general they consider the following rules o Start with a lettero Do not include spaces or special characters.

It´s also important to use representative names, with a meaning of the data that is being stored.

o Baseo TotalPaymento IdNumber.

Naming the containers (variables)

Page 11: U2_A1.1_DataContainers

11

To give a value to a data container an assignment symbol (=) must be used followed with the value to assign, that can be an expression.

While another value is not assigned, the data container will maintain its original value.

Examples:o velocity= distance/ timeo tax = salary * .15o double = number * 2o score = 100o name = “George Washington”

Assigning values

Page 12: U2_A1.1_DataContainers

12

Page 13: U2_A1.1_DataContainers

13

Which of the following options is NOT a valid name of a variable in any computer language? a) semestral gradeb) summer2009_gradec) my_graded) califFinCIS100

Review Question 1

Page 14: U2_A1.1_DataContainers

14

A broad classification of data types is: a) Internal and Externalb) Volatile, constant and temporalc) Numeric, string and booleand) Permanent and temporal

Review Question 2

Page 15: U2_A1.1_DataContainers

15

Assuming that address is a string variable, which of the following options is a legal assignment statement? a) address = “23Elm”b) “23Elm” = addressc) address = 23 Elmd) address = 23e) address = Elm

Review Question 3

Page 16: U2_A1.1_DataContainers

16

Assuming that salary is a numeric variable, which of the following opitons is a legal assignment statement? a) salary = “not enough”b) 25 = salaryc) salary = “23.45”d) salary = 23.45e) None of these

Review Question 4

Page 17: U2_A1.1_DataContainers

17

Which of the following names seem like good variable names to you? If a name doesn´t seem like a good variable name explain why not.a) cb) costc) CostAmountd) Cost Amounte) cstofdngbsnsf) CostOfDoingBusinessThisFiscalYearg) cost2004

Review Question 5

Page 18: U2_A1.1_DataContainers

18

If Age and Rate are numeric variables, and Department is a string variable, which of the following statements are valid assignments. Why? a) Age = 23b) Age = Ratec) Age = Departamentd) Age =“departament” e) 42 = Age f) Rate = 3.5

Review Question 6

X

X

X

Page 19: U2_A1.1_DataContainers

19

If Age and Rate are numeric variables, and Department is a string variable, which of the following statements are valid assignments. Why? a) Rate = Ageb) Rate = Departament c) 6.91 = Rated) Departament = Personal e) Departament = “Personal”f) Departament = 413 g) Departament = “413”h) “413” = Departament

Cont…Review Question 6

X

XX

X

X

Page 20: U2_A1.1_DataContainers

20

Farrell, J. An Object-Oriented Approach to Programming Logic and Design. 2nd ed. Boston, MA:Thomson. 2008.

Gladis, T. and Irvine, K. Starting out with Visual Basic ® 2008. 4th ed. Boston, MA: Addison Wesley. 2009.

Schenider, D. I. An Introduction to Programming Using Visual Basic® 2008. 7th ed. Boston, MA: Pearson Prentice Hall. 2009

Bibliography