CONCRETE BASICS Man Made Rock · For more information visit: 303-369-1115
Language Basics. Chapter 1.4 What is a Program Made of?
-
Upload
ronald-obrien -
Category
Documents
-
view
228 -
download
0
Transcript of Language Basics. Chapter 1.4 What is a Program Made of?
![Page 1: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/1.jpg)
Language Basics
![Page 2: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/2.jpg)
Chapter 1.4Chapter 1.4What is a Program Made of?
![Page 3: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/3.jpg)
Last lecture I said…Last lecture I said…Common elements in
programming languages:◦Key Words◦Programmer-Defined Identifiers◦Operators◦Punctuation◦Syntax
![Page 4: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/4.jpg)
Wow!!!Wow!!!I am overwhelmed ---what does
all of this mean.
Don’t worry---lets play a bit and learn a little bit about these idea with a fun tool called Scratch before we learn about C++.
![Page 5: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/5.jpg)
ScratchScratch
(scratch.mit.edu)Application to teach concepts of
Programming that is language independent and geared for children
What is it really = a visual editor where you don’t have to worry about language syntax and you can create games/animations that others can “play”.
![Page 6: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/6.jpg)
ScratchScratch
Sprite Panel—whereyou make your characters inyour game
Preview Panel- can view currentgame/animation here
Scripting Panel- THIS IS WHERE WE CREATE OUR CODEToolkit
Panel- where can get the operators of the Scratch LANGUAGE
![Page 7: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/7.jpg)
Time for a Demo in classTime for a Demo in classUses beginning project linked on our
class website or see instructor.
NOTE how the language statements SNAP together like Legos --- this is like writing goodSyntax in a program – only certain statements can go with others in a language.
![Page 8: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/8.jpg)
Lets compare concepts of Lets compare concepts of real programs with Scratch real programs with Scratch to really Learn what these to really Learn what these ideas meanideas mean
![Page 9: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/9.jpg)
We will compare the We will compare the following ideas in Scratch following ideas in Scratch and a real C++ programand a real C++ program
◦Programmer-Defined Identifiers --- variables
◦Operators◦Punctuation◦Syntax
![Page 10: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/10.jpg)
This is our Program we will This is our Program we will useuse
![Page 11: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/11.jpg)
Programmer-Defined Programmer-Defined Identifiers --VariablesIdentifiers --VariablesNames made up by the
programmerNot part of the programming
languageUsed to represent various things:
variables (memory locations), functions, etc.
![Page 12: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/12.jpg)
Variables in ScratchVariables in Scratch
Scratch we have character’s named Sprites --- we can define variables about them.
![Page 13: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/13.jpg)
Variables in a ProgramVariables in a ProgramA variable is a named storage
location in the computer’s memory for holding a piece of data.
![Page 14: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/14.jpg)
Variables in C++Variables in C++exampleexample
In Program 1-1 we used three variables:◦The hours
variable was used to hold the hours worked
◦The rate variable was used to hold the pay rate
◦The pay variable was used to hold the gross pay
![Page 15: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/15.jpg)
Variable DefinitionsVariable DefinitionsTo create a variable in a program
you must write a variable definition (also called a variable declaration)
Here is the statement from Program 1-1 that defines the variables:
double hours, rate, pay;
![Page 16: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/16.jpg)
Variable DefinitionsVariable DefinitionsThere are many different types of
data, which you will learn about in this course.
A variable holds a specific type of data.
The variable definition specifies the type of data a variable can hold, and the variable name.
![Page 17: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/17.jpg)
Variable DefinitionsVariable DefinitionsOnce again, line 7 from Program
1-1:
double hours, rate, pay;
The word double specifies that the variables can hold double-precision floating point numbers. (You will learn more about that in Chapter 2)
![Page 18: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/18.jpg)
OperatorsOperatorsUsed to perform operations on
dataMany types of operators:
◦Arithmetic - ex: +,-,*,/◦Assignment – ex: =
![Page 19: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/19.jpg)
Operators in ScratchOperators in Scratch
Lets look at addition in Scratch
When Cat moves lets change location by +10 each time.
![Page 20: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/20.jpg)
Operators in C++Operators in C++example (example (<< >> = * )<< >> = * )
![Page 21: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/21.jpg)
PunctuationPunctuationCharacters that mark the end of
a statement, or that separate items in a list
![Page 22: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/22.jpg)
Scratch – no punctuation –Scratch – no punctuation –but end of line is visiblebut end of line is visibleHere each
line of code hasits own “shapedbox”
![Page 23: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/23.jpg)
Punctuation in C++Punctuation in C++Commas = separateSemi-colons = end of line
![Page 24: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/24.jpg)
SyntaxSyntaxThe rules of grammar that must
be followed when writing a program
Controls the use of key words, operators, programmer-defined symbols, and punctuation
Scratch TIP: controls syntax remember byOnly allowing certain commands to “SNAP” together. Here we see the “if” statement does something (turns 15 degrees)when the (distance to Sprite1 is < 20)
![Page 25: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/25.jpg)
Example Syntax in C++Example Syntax in C++Regular statements must end
with a Semi-colon ---this signifies the end of the statement
We will learn more of theC++ sytnax rules as we go through the class.
![Page 26: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/26.jpg)
Procedural and Object-Oriented Programming---- what did I mean in last lecture --- can Scratch help us?
![Page 27: Language Basics. Chapter 1.4 What is a Program Made of?](https://reader034.fdocuments.net/reader034/viewer/2022051114/56649e025503460f94aec2be/html5/thumbnails/27.jpg)
Procedural and Object-Procedural and Object-Oriented ProgrammingOriented Programming
Procedural programming: focus is on the process. Procedures/functions are written to process data.
Object-Oriented programming: focus is on objects, which contain data and the means to manipulate the data. Messages sent to objects to perform operations.
Scratch TIP: Our operations like when we are close to Sprite1 then turn 15 degrees is a procedure
Scratch TIP: Our Sprites we saw in Scratch are like objects