Language Basics.

Slides:



Advertisements
Similar presentations
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Advertisements

COSC 120 Computer Programming
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
The Scratch Calculator You are all going to be real computer programmers!!!
Language Basics.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introduction to Programming. Our Book in CS Why Program? Lets watch a video
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Input, Output, and Processing
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
GCSE Computing: Programming GCSE Programming Remembering Python.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming Dr. Halla Abdel Hameed.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
CST 1101 Problem Solving Using Computers
Software Development.
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Topics Designing a Program Input, Processing, and Output
1-1 Logic and Syntax A computer program is a solution to a problem.
BASIC PROGRAMMING C SCP1103 (02)
Chapter 2: Input, Processing, and Output
Topic: Python’s building blocks -> Variables, Values, and Types
Chapter 1. Introduction to Computers and Programming
Variables, Expressions, and IO
Getting Started with C.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Computer science By/ Midhat Mohiey. Introduction to Programming using C ++ 2.
Chapter 1: Introduction to Computers and Programming
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Fill the screen challenge!
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Programming Right from the Start with Visual Basic .NET 1/e
Unit 1: Introduction Lesson 1: PArts of a java program
Topics Introduction Hardware and Software How Computers Store Data
Hello World! Syntax.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Tonga Institute of Higher Education IT 141: Information Systems
Topics Designing a Program Input, Processing, and Output
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 2: Input, Processing, and Output
Introduction to Python
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
Getting Started With Coding
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Language Basics

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

It is made of… Common elements in programming languages: Key Words Programmer-Defined Identifiers Operators Punctuation Syntax

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

Scratch https://scratch.mit.edu (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”.

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

Time for a Demo in class Will demo in class 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.

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

We will compare the following ideas in Scratch and a real C++ program Variables Keywords Operators Punctuation Syntax

This is our Program we will use Lets try it together on next slides This is our Program we will use You don’t know C++ But, try to read this C++ code. Read one line at a time --can you guess what it is doing just from reading it like English The comments can help DON’T WORRY – it will take us a few weeks to learn this –so relax

Variables

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.

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

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

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

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;

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.

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) The common name for hours, rate and pay in programming languages is VARIABLES

Keywords

Key Words Keywords tell us the definition of “things” in our program – we will learn what each of these do in the next few weeks

Operators

Operators Used to perform operations on data Many types of operators: Arithmetic - ex: +,-,*,/ Assignment – ex: = Some operators in Program1-1: << >> = * These are just like what you saw when you wrote math equations on paper --but, some like << and >> are new to programming –we will Learn them as we go

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

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

Punctuation

Punctuation Characters that mark the end of a statement, or that separate items in a list UNDERSTANDING Many but not ALL programming languages use the semi-colon ; to Indicate the end of a line of code. However, there are some languages like Python that just require each line of code to be on a separate line and don’t use semi-colons.

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

Punctuation in C++ WHY? Is it important to separate lines of code (in C++ with the semi-colon) --because the CPU/computer brain needs to process only one line at a time Commas = separate Semi-colons = end of line

Syntax

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)

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.

Program 1-1: lets look at it again comment too hard to guess –ignore for now Start of our program –the main “routine” These are variables –where we store values comment Asking user for hours-reading in value comment Asking user pay rate-reading in value DON’T WORRY – it will take us a few weeks to learn this –so relax comment Calculating the pay comment Print out to the user the pay

More about programming 

Input, Processing, and Output 1.5 Input, Processing, and Output

Input, Processing, and Output Three steps that a program typically performs: Gather input data: from keyboard (user types in) from files Process the input data Display the results as output: send it to the screen write to a file

The Programming Process 1.6 The Programming Process

The Programming Process

1.7 Procedural and Object-Oriented Programming ---- have you ever heard anyone say object oriented programming? How about procedural programming?

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 This class as your beginning C++ class focuses on Procedural Programming Scratch TIP: Our Sprites we saw in Scratch are like objects