P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 1.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 1 An Overview of Computers and Logic
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
CIS105 Chapter 1 Theory Review. Page 2 Hardware and Software are the two major components o any computer system Hardware is the set of physical devices.
Chapter 2: Input, Processing, and Output
An Overview of Computers and Logic
An Overview of Programming Logic and Design
JavaScript, Third Edition
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
Programming Logic and Design Fourth Edition, Introductory
An Overview of Computers and Programming
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
CS102 Introduction to Computer Programming
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Programming Logic and Design Fifth Edition, Comprehensive
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
An Overview of Computers and Logic
1 CSC103: Introduction to Computer and Programming Lecture No 2.
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
A Review of Programming and C++
CIS Computer Programming Logic
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Input, Output, and Processing
Introduction to Computer Systems and the Java Programming Language.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
P ROGRAMMING L OGIC AND D ESIGN S IXTH E DITION Chapter 1 An Overview of Computers and Programming.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Introduction to Programming with RAPTOR
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Programming Logic and Design Seventh Edition
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Algorithms and Pseudocode
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Computer Programming using Fortran 77.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Component 1.6.
DDC 1023 – Programming Technique
CS1001 Programming Fundamentals 3(3-0) Lecture 2
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Chapter 2 Variables.
T. Jumana Abu Shmais – AOU - Riyadh
Boolean Expressions to Make Comparisons
Chapter 4: Writing and Designing a Complete Program
Programming Logic and Design Eighth Edition
Presentation transcript:

P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 1

Computer Components and Operations 1 Planning Logic 2 Pseudo Statements 3 Week 1

Variables 4 Data types 5 Keywords 6

Learning Objectives Explain how scripts are included, handled and processed by browsers

Computer components & operations Your computer is composed of the hardware, or computer equipment, and the software, the instructions that tells the hardware what to do Software programs are instructions written by programmers

Computer components & operations Generally, there are two types of software: – Application or task software like Word or PhotoShop – System software, the programs that manage your computer like your operating system of Windows We will focus on the logic in writing application programs. The instructions you will write is called program code.

Computer components & operations Computers perform 3 major operations – Input – keyboard and mice entry of data – Processing – Organizing, checking, perhaps performing mathematical operations, on the data, performed by the central processing unit or CPU – Output – the bits of entered data is processed into information, usable by people to see, interpret and use via a monitor, printer, or other output device

Computer components & operations Our software instructions are written in a programming language, such as Java or C+ Rules for writing is called the syntax Computers need you to be exact when you write instructions If the syntax isn’t perfect, the computer won’t understand

Computer components & operations Computers operate on circuitry that consists of millions of on/off switches Each programming language uses a piece of software to translate your statements into object code, or machine language Machine language is a series of 0s and 1s, called binary form

Computer components & operations The software that translates your statements into binary form is called a compiler or interpreter It will issue a message warning if you had made a syntax error, such as misspelled a word or used incorrect punctuation Syntax errors are relatively easy to find and fix

Computer components & operations The compiler highlights the errors and your program will not run until the error is fixed There are different compilers and interpreters but generally their function is to translate your programming statements into code the computer can understand The program runs and executes a program’s instructions

Computer components & operations If there are no syntax errors, the program will run However, it may still not give correct information

Computer components & operations To work right, the instructions need to go to the computer in a specific sequence No instruction can be left out You may not add extraneous instructions …in other words, you develop the logic of the computer program

Computer components & operations Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups flour

Computer components & operations Though the instructions were written in correct English spelling and grammar, the instructions were out of sequence, some instructions were missing, and some instructions belonged to a different procedure. These are logical errors, and they are more difficult to find than syntax errors.

Computer components & operations While compilers stop at a syntax error until it is fixed, errors in logic cannot be as easily located by the compiler. It usually needs to execute the program before errors can be found. Logic is the same across all the different languages you can write

Computer components & operations Write a program that takes a number (input) Double it (processing) Tell the answer (output) Input originalNumber. Compute calculatedAnswer = originalNumber times 2. Output calculatedAnswer.

Computer components & operations Input originalNumber is an example of an input operation. The computer knows to interpret the instructions using an input device to obtain a number and store it in memory named originalNumber You would tell the computer what input device to use, but by default it’s the keyboard These are processing steps

Programming process Understanding the problem Plan the logic Code the program Translate the program into machine language Test the program Put program into production Maintain the program

Programming process Understanding the problem – Give me a list of students who are over 25 years of age with 25 or more college credits All students, AI students, currently attending? 25 years of age to no limit? Credits earned at this college? How does the information need to be delivered? What data is currently available? ?????

Programming process Plan the logic – Plan the steps of your program, decide what actions to include and their order – Called developing an algorithm – Algorithm is a sequence of steps to solve a problem – Flowcharts and pseudocode are common planning tools to plan and show all necessary steps – Writing out the steps on paper is called desk-checking

Programming process Code the program – After the developing the logic, a language is chosen to handle the type of operation the programmer wants – Then using the correct syntax can be employed – The prior planning step is actually more difficult than writing correct syntax code since now you are translating – There are many programming languages, but computers only understand one: machine language

Programming process Code the program – Machine language is understood by the computer because the computer is made of the same system of 1s and 0s, thousands of tiny electrical switches turned on (1) and off (0) state – Languages like Java are used because someone wrote a translator (compiler or interpreter) program that turns the high-level programming language into low- level machine language

Programming process Code the program – Writing your program with misspelled, missing or “illegal” grammar will cause the translator program to issue an error message identifying a syntax error – It will not execute a program that contains even one syntax error

Programming process Code the program – Usually you will write some code and then submit it, troubleshoot any errors, and repeat – An executable program is created only when there are no syntax errors

Programming process Test the program – No syntax errors does NOT mean no logical errors – When the program is syntax error free, the programmer executes the program with some sample data to find if results are logically correct – If not, maybe the program has logic errors that need to be corrected – Programs should be tested with many sets of data

Programming process Put program into production – Upon completing the production and testing of a program, it is put into use – If it is a simple program like providing a list, it might just be ran once as needed – If it is a large company-wide program, there may be months or years of feedback and training as a conversion to the new program occurs

Programming process Maintain the program – Maintenance involves updating the program as needed after it is put into use – Writing clear code, commenting your steps, using reasonable identifiers for values, and documentation will all make this process easier for you or whoever takes over the program implementation

Pseudocode statements & flowchart symbols Pseudocode is an English-like listing of the logical steps it would take to solve a problem. It means false code A flowchart is the pictorial representation of the same thing start input originalNumber compute calculatedAnswer as originalNumber times 2 output calculatedAnswer stop

Pseudocode statements & flowchart symbols A flowchart is the pictorial representation of the same thing start input originalNumber compute calculatedAnswer as originalNumber times 2 output calculatedAnswer stop

Pseudocode statements & flowchart symbols Programmers usually use either pseudocode or a flowchart, not usually both. Pseudocode is similar to step by step instructions, while a flowchart is like a map

L AB : V ARIABLES AND D ATA TYPES

Using and naming variables We ask the computer to store our program in variables Variables are named memory locations originalNumber is stored in a location as a variable, and its content can vary One memory location can be used many times, with different values

Using and naming variables You can write program instructions once but use for thousands of separate calculations This is what makes programming valuable The ability of memory variables to change in value makes computers and programming valuable

Using and naming variables A variable name is called an identifier Each programming language has its own set of rules for creating identifiers Most allow bot letters and digits Some allow hyphens (-), while others allow underscores (_). Some do not allow either.

Using and naming variables Some languages, like php, allow dollar ($) signs, and others foreign alphabet characters Different languages put different limits on the length of variables but in general, newer languages allow longer names

Using and naming variables Newest versions of C++, C#, and Java, allow almost unlimited identifier names These languages are case sensitive Camel casing is when programmers use an uppercase letter for the second word, like hourlyWage Pascal casing is when the first letter is uppercase, as in HourlyWage

Using and naming variables Logic works with any language so there are only two rules when naming a variable: – Variable names must be one word – Variable names must have meaning The first is a rule: no programming language allows spaces with a name. The second is a best practice, making your logic more useful

Assigning value to variables Assignment statements involve two actions: – The computer calculates the arithmetic value – The computed value is stored in memory In pseudocode this could be written as: Compute calculatedAnswer as originalNumber times 2 An assignment statement would be written like this: calculatedAnswer = originalNumber * 2 The assignment operator is the equal (=) sign = means assignment not equivalency

Named constants Most programming languages allow creating named constants You would use a constant when you want a value that doesn’t change Unlike a variable, a constant would not have different values over time Giving an appropriate name in uppercase and underscores is naming the constant, instead of leaving unnamed (called a magic number) that maybe isn’t apparent

Named constants Example: If a program needs the sales tax included, you could declare the named constant: num SALES_TAX = 0.06 Then write the program statement: finalPrice = price + price * SALES_TAX Named constants are declared differently among programming languages. We are using a standard convention

Arithmatic operations + (plus sign) addition - (minus sign) subtraction * (asterisk) multiplication / (slash) division Most modern languages also include a remainder operator, represented by a percent sign (%), to represent a remainder after a division operation

Arithmetic operations You can combine arithmetic statements, each operator following rules of precedence Rules of precedence dictates the order the operations are carried out Multiplication and division always takes precedence over addition and subtraction. a + b * c In this expression, you would multiply b and c, then add a

Arithmetic operations In arithmetic statements, the rules of precedence can be overridden by using parentheses * 4 rules of precedence says the answer is 14 (2 + 3) * 4using parentheses gives 20 as the answer Forgetting to add parenthesis or the rules of precedence can lead to logical errors hard to find in a program when you’re troubleshooting Choose to use parenthesis to help make your intention clear as needed

Data types and declaring variables Computers use two basic types of data – Numeric with a specific numeric value called a numeric constant. 43 is always 43 and you write using the digits, no quotation marks – A string constant, or text, is enclosed within quotation marks, unnamed and literal “Amanda”

Data types and declaring variables A variable’s data type describes kind of value – A numeric variable can have math operations performed on it – A string variable can hold alphabet and special characters like punctuation marks. It is text Computers handle the two types differently, so you’re distinguishing the two when you declare the variable

Data types and declaring variables When you declare the variable you let the computer know the data type and an identifier to expect You must declare the variable first string lastName num salary then you can assign value, send to output, or perform an operation allowed for its data type

Data types and declaring variables You add a sentinel value to end a program, to prevent situations like an infinite loop Computers are binary so you could give a dummy value that is not real data but signals stop, and in a flowchart, would be represented by a decision symbol shaped like a diamond There would be only two mutually exclusive answers, yes or no, true or false

Data types and declaring variables originalNumber = 0? for “Is the value of originalNumber equal to 0?” Many programming languages use the term eof for “end of file” to refer to a marker automatically stored at the end of data This acts as a more efficient sentinel value

Case Study Create the logic for a Mad Lib program that displays a message asking the user to provide five words And then accepts those words and creates and displays a short story or nursery rhyme using them Require two nouns, an adjective, and a past-tense verb

Discussion What are you going to use, pseudocode or flowchart? What data type? What are the sequence of steps? How would you signify the sentinel value?

Homework Assignment Develop the logic for your favorite recipe. Due the night before the next class, in the dropbox for week 1