Programming Fundamentals/Variables/Data Types

From Wikiversity
Jump to navigation Jump to search

A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, including integer, real, character or string, and Boolean.[1] This activity introduces data types. This activity will help you understand how and when to use different data types in a program.

Objectives[edit | edit source]

  • Understand data types.
  • Understand how data types are specified in a program.
  • Understand how data literals specify data types.

Prerequisites[edit | edit source]

  • Review Wikipedia: Data type.
  • An integer data type represents whole numbers with no fractional parts.[2]
  • A real or floating-point data type represents fractional numbers with decimal points.[3]
  • A string data type represents a sequence of characters.[4]
  • A Boolean data type represents logical true or false.[5]
  • An operator is a character or symbol used to perform an arithmetic, logical, or bitwise operation on one or more operands.[6]
  • String concatenation is the joining of character strings end-to-end.[7]
  • An assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable.[8]

Introduction[edit | edit source]

Data types
Data types

Review the flowchart example on the right.

Questions[edit | edit source]

  • What flowcharting symbol is used to indicate the beginning and ending of a program?
  • What flowcharting symbol is used to indicate annotations or comments?
  • What flowcharting symbol is used to indicate variable declaration?
  • What flowcharting symbol is used to indicate input or output?
  • What flowcharting symbol is used to indicate a process, calculation, or assignment?
  • What key word is used to declare an integer variable?
  • What key word is used to declare a real or floating-point variable?
  • What key word is used to declare a string variable?
  • What key word is used to declare a Boolean variable?
  • How can you tell the difference between an integer literal value and a real or floating-point literal value?
  • How can you tell the difference between a numeric literal value and a string literal value?
  • What operator is used for assignment?
  • What operator is used for string concatenation?

Activity[edit | edit source]

With a partner, perform the following:

  1. Using a visual programming language, create a program matching the flowchart on the right.
  2. Save the program.
  3. Test the program to verify that it works correctly.
  4. Trade places, so that both partners have an opportunity to "drive" the visual programming environment.
  5. Copy the program and change it so that different values are used for each data type.
  6. Save the program.
  7. Test the program to verify that it works correctly.
  8. Working together, create a list of examples for which you would use each of the different data types in a program. Include at least three examples for each data type.
    • integer
    • real or floating-point
    • string
    • Boolean

Applications[edit | edit source]

  • Identify the data types necessary for processing data to meet given program requirements.
  • Discuss your activity experience with your classmates. What surprised you? What have you learned that you can apply to your own school or work environment?

References[edit | edit source]