Topic 2 Flashcards
When solving a programming problem, try to use a
Modular Approach
is a program consisting of interrelated statements arranged in logical and understandable form
modular program
is referred to as a small segment which is designed to perform a specific task
Module
is a symbolic identifier for a memory address where data can be held
variable
used to name storage locations
Variable
is a memory location whose contents can
vary, also called an identifier
variable
Name must be a __________,
but can be formed from several
words
single word
First character must be a ________
or _____________
letter, underscore
Only ______, ______, and ____________ may follow the initial letter ( no blanks or spaces allowed )
letters, digits, underscore
____________ cannot be used as
identifiers
Keywords
Variable names are ____ __________
case sensitive
Keywords are also referred to as ________ _____, for they cannot be used as variable names
reserved words
Conventions
- Use underscore to separate
words, for readability - Or, capitalize the first letter of
each word (Pascal Case) - Be mindful of using some characters:
Invalid Identifiers
- begins with a number
- contains a special character
- a keyword
: ordering of data types
by size
Data Hierarchy
: single symbol
*“A”, “7”
Character
: group of characters forming a
single data item
* “smith”
field
: a group of related fields
* Customer record containing name and
address fields
Record
: a group of related records
* Customer file, containing all customer
records
File
: collection of related files,
called tables, that serve the
information needs of the organization
Database
Two basic data types:
- text
- numeric
____________ stored by numeric
variables
Numeric data
stored by string, text, or
character variables
Text data
Values that do not change while the
program is running
constants
A specific numeric value that does not change.
Numeric Constant
String of characters enclosed within “ “.
String Constant
Do not have identifiers like variables do
Unnamed Constants
: whole numbers only
integer
: fractional numeric
values with decimal points
floating-point
Assignment statement :
- Assigns a value to a variable
- Variable must appear on the left side, value on the right side of the
assignment operator - Right side may be an expression that will be evaluated before storing the
value in the variable
Assignment operator :
: the equal sign (=) in most languages
*Always operates from right to left.
Used to store a value into a
variable
Assignment statement
Specifies the data type and identifier of a variable. It sets up the memory location
Declaration Statement
Common Programming errors
- Substituting letter O for zero (0) and vice versa
- Failing to declare ALL variables
- Storing incorrect data type into a variable
- Attempting to use a variable with no value
- Dividing integer values incorrectly
- Mixing data types in the same expression
holds digits and perform mathematical operations on it, also decimals and +/-.
Numeric Variable
can hold text, letters of the alphabet, and special characters like “!”.
String variable
only if it is the correct type.
Assign Data to a variable
Similar to a variable and can only be assigned a value once. A useful name should be assigned to a value that will never change throughout the execution
Named Constant
An unnamed constant with no immediate apparent purpose. Should be avoided.
Magic Number