Presentation is loading. Please wait.

Presentation is loading. Please wait.

Language Basics.

Similar presentations


Presentation on theme: "Language Basics."— Presentation transcript:

1 Language Basics

2 What is a Program Made of?
Chapter 1.4 What is a Program Made of?

3 Last lecture I said… Common elements in programming languages:
Key Words Programmer-Defined Identifiers Operators Punctuation Syntax

4 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++.

5 Scratch (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”.

6 Scratch Preview Panel- can view current game/animation here
Scripting Panel- THIS IS WHERE WE CREATE OUR CODE Toolkit Panel- where can get the operators of the Scratch LANGUAGE Sprite Panel—where you make your characters in your game

7 Time for a Demo in class Uses beginning project linked on our class website or see instructor. NOTE how the language statements SNAP together like Legos --- this is like writing good Syntax in a program – only certain statements can go with others in a language.

8 Lets compare concepts of real programs with Scratch to really Learn what these ideas mean

9 We will compare the following ideas in Scratch and a real C++ program
Programmer-Defined Identifiers --- variables Operators Punctuation Syntax

10 This is our Program we will use

11 Programmer-Defined Identifiers --Variables
Names made up by the programmer Not part of the programming language Used to represent various things: variables (memory locations), functions, etc.

12 Variables in Scratch Scratch we have character’s named Sprites --- we can define variables about them.

13 Variables in a Program A variable is a named storage location in the computer’s memory for holding a piece of data.

14 Variables in C++ example
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

15 Variable Definitions To 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;

16 Variable Definitions There 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.

17 Variable Definitions Once 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)

18 Operators Used to perform operations on data Many types of operators:
Arithmetic - ex: +,-,*,/ Assignment – ex: =

19 Operators in Scratch Lets look at addition in Scratch
When Cat moves lets change location by +10 each time.

20 Operators in C++ example (<< >> = * )

21 Punctuation Characters that mark the end of a statement, or that separate items in a list

22 Scratch – no punctuation –but end of line is visible
Here each line of code has its own “shaped box”

23 Punctuation in C++ Commas = separate Semi-colons = end of line

24 Syntax The 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 by Only allowing certain commands to “SNAP” together. Here we see the “if” statement does something (turns 15 degrees) when the (distance to Sprite1 is < 20)

25 Example Syntax in C++ Regular statements must end with a Semi- colon ---this signifies the end of the statement We will learn more of the C++ sytnax rules as we go through the class.

26 Procedural and Object-Oriented Programming
---- what did I mean in last lecture --- can Scratch help us?

27 Procedural and Object-Oriented 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


Download ppt "Language Basics."

Similar presentations


Ads by Google