What Is Programming?: Writing Games Writing Application Programs (Like Excel)
What Is Programming?: Writing Games Writing Application Programs (Like Excel)
What Is Programming?: Writing Games Writing Application Programs (Like Excel)
-Once the code (language) of a program has been written, it must be executed (run, started).
-You may need to type the name of the program to start it , or use a word like RUN and the
name of the program (in the old days, anyway).
-Some programming languages (like Java or C++) require the code to be compiled (translated
to binary) before it can be started.
-Others (like JavaScript) are interpreted, meaning that each command is translated separately
when the program is started.
-A set of rules that provides a way of telling a computer what operations to perform
-Languages that look like "machine code" (e.g., 82A8: jsr r5, @#82AE 82 AC: sob r0, 8296) are
used for...
~Writing games
-Other languages look like English ("high level," e.g., PRINT "HELLO")
~Logo
~JavaScript
-High-level program
-Low-level program
-Executable Machine E
HIGH-LEVEL LANGUAGES
~FORTRAN
* FORmula TRANslation
~COBOL
* Developed in 1959
~BASIC
* Developed as a simple language for students to write programs with which they could interact
through terminals.
~C
* Provides control and efficiency of assembly language while having third generation language
features.
* UNIX is written in C
~C++
* Graphical user interfaces can be developed easily with visual programming tools.
~JAVA
* An object-oriented language similar to C++ that eliminates lots of C++'s problematic features
* Allows a web page developer to create programs for applications, called applets that can be
used through a browser.
Markup Languages
~HTML
* Web page developer puts brief codes called tags in the page to indicate how the page should
be formatted
~XML
What is pseudocode?
Sample Pseudocode
-The pseudocode from the previous slide would look like this as a flowchart:
Start
Print Answer
Get 2 numbers
End
Add them
-START/END
Used at the beginning and end of each flowchart
-INPUT/OUTPUT
Shows when information/data comes into a program or is printed out.
-PROCESS
Used to show calculations, storing of data in variables, and other processes that
take place within a program.
-DECISION
Used to show that the program must decide whether something (usually
comparison between numbers) is true or false. YES and NO (or T/F) branches are
usually shown.
Start
Another Sample: Calculating Age
Get yr
-Pseudocode
Start
Calc age
Get year born
Calculate age
Print age
Print age
If age > 50 print OLD Y
End Age>50
OLD
End
Elements of a Program
Variables
-Variables are part of almost every program.
-A variable is a place to put data and is usually represented by a letter or a word. (Think of a
variable as a Tupperware container with a label on it.)
-Variable names cannot contain spaces.
-Some programming languages have very specific limits on variable names.
-Usually there are several ways to put information into a variable.
-The most common way is to use the equal sign (=).
-X = Y + 7 means take the value of Y, add 7, and put it into X.
-COUNT = COUNT + 2 means take the current value of COUNT, add 2 to it, and make it the
new value of COUNT.
-Sometimes you must specify the type of data that will be placed in a variable
-Here are some examples of data types:
Numeric (numbers of all kinds)
String (text, strings of letters)
Integer (whole numbers)
Long (large numbers)
Boolean (true/false)
-Variables may be classified as global or local
-A global variable is one that can be shared by all parts of a program including any functions or
subprograms.
-A local variable is one that is used only within a certain part of the program for example, only in
one function or subprogram.
Commands/Syntax
Loops
Decisions
Functions
-In most programming languages, small subprograms are used to perform some of the tasks.
-These may be called functions, subroutines, handlers, or other such terms.
-Functions often have names (e.g., getName or CALCTAX).
-A function generally gets information from the main program, performs some task, and returns
information back to the program.
-Functions follow the same rues of syntax, etc. as the main program.
-JavaScript code is primarily made of a series of functions.