Chapter 2 Flashcards
What do data types describe
- what values can be held by the item
- how the item is stored in memory
- what operations can be performed on the item
what are two data types that are supported by all programming languages
- Numeric
- Strings
what are the two types of constants
- numeric constant (numbers that don’t change)
- string constant (alphanumeric values) - contain numbers and characters and enclosed in question marks
declaration
a statement that provides a variable’s data type, identifier (variables name) and maybe and initial value
string variables can hold text, letters, and
special characters (punctuation etc)
type - safety prevents
assigning values of an incorrect data type
what are the rules for creating identifier’s (variable names)
- reserved keywords are not allowed
- must be one word
- must start with a letter
- should have appropriate meaning
Camel casing
variable names have a “hump” in the middle (hourlyWage)
pascal casing
variable names have the first letter in each word uppercase (HourlyWage)
Hungarian notation
form of camel casing in which the data type is part of the name (numhourlyWage)
snake casing
parts of variable names are separated by underscores (hourly_wage)
mixed case with underscores
all letters uppercase with underscores in between each letter (Hourly_Wage)
kebob case
parts of variable names are separated by dashes (hourly-wage)
assignment statement
statement that assigns variable to number (set myAnswer = myNumber * 2)
assignment operator (equal sign)
- binary operator - it requires two operands, one on each side
- right associativity - operates from right to left
- lvalue - result to the left of assignment operator
initializing a variable
giving the variable a start value
garbage
a variable’s unknown value
named constant
similar to a variable that’s assigned a value once
magic number
unnamed constant
rules of precedence
order of operations
remainder operator (modulo operator or modulus operator)
contains the remainder of a division operation
modules
subunit of programming problem
call a module
use its name to invoke the module, causing it to execute
modularization (functional decomposition)
breaking down large program into modules
abstraction
paying attention to the important stuff and ignoring not important stuff
why is modularization popular
- easier to divide the task among various people
- its faster to write the program
- reusable (allows other modules to be used in other applications)
- reliable (ensures every module has been tested)
Modularizing a program
- main program or mainline logic (basic steps of program)
- name module (similar to naming variable)(module names are followed by set of parentheses)
what to include in a module
module header, body, and return statement
when a main program wants to use a module it
“calls” the modules name
symbol used to call a module (flowchart)
rectangle with bar across the top
encapsulated
statements taken out of a main program and put into a module
global variables and constants are declared at which level
the program level (visible and usable in all modules called by the program)
mainline logic for every program is
- declare global variables and constants
- housekeeping tasks (steps performed at beginning of program to get ready for rest of program)
- detail loop tasks (core work of program)
- end of job tasks (steps you take to finish the application)
hierarchy chart
shows overall pic of how modules are related to another (shows which modules exist in a program and which modules call others)
programming comments
explantation of program that isn’t apart of program code
flowchart symbol for comments
annotation symbol
self-documenting
using meaningful names
data dictionary
list of variables
temporary variable (work variable)
1.not used for input/output
2. working variable used during a program’s execution
prompt
message displayed on monitor to ask user for a response
echoing input
repeating input back to a user in a subsequent prompt/input