Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
Chapter 2: Input, Processing, and Output
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 2: Introduction to C++.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 3: Expressions and Interactivity.
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;
Basic Elements of C++ Chapter 2.
Chapter 1: An Introduction to Computers and Programming Prelude to Programming Concepts and Design Copyright © 2001 Scott/Jones, Inc.. All rights reserved.
COMPUTER SCIENCE I C++ INTRODUCTION
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Chapter 2 Overview of C++. 2 Overview  2.1 Language Elements  2.2 Reserved Words & Identifiers  2.3 Data Types & Declarations  2.4 Input/Output 
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
Chapter 2 Variables.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake An Introduction to Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
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.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
What Actions Do We Have Part 1
Basic Elements of C++.
Variables, Expressions, and IO
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Chapter 2 Variables.
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Chapter 3: Selection Structures: Making Decisions
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition
Chapter 3: Selection Structures: Making Decisions
An Introduction to Programming
Presentation transcript:

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 1: Introduction to Programming

What is Programming? A program is a list of instructions that is executed by a computer to accomplish a particular task. Creating those instructions is programming Program development cycle: –Analyze the problem –Design a program to solve the problem –Code the program –Test the program

Basic Programming Concepts A simple programming problem: convert a price from British pounds into U.S. dollars. Pseudocode Input the price of the item, PoundPrice, in pounds Compute the price of the item in dollars: Set DollarPrice = 1.62 * PoundPrice Write DollarPrice –Variables used: PoundPrice and DollarPrice –Constants: 1.62

1-4 BASIC and C++ Code BASIC Code: DIM PoundPrice As Double DIM DollarPrice As Double INPUT PoundPrice LET DollarPrice = 1.62 * PoundPrice PRINT DollarPrice END C++ Code: void main(void) { float PoundPrice, Dollar Price; cout << “Enter price in Pounds.”; cin >> PoundPrice; DollarPrice = 1.62 * PoundPrice; cout << DollarPrice; }

1-5 Data Input Input operations get data into the programs A user is prompted for the data to be entered –This text uses the word Write to indicate a prompt for input –The word Input indicates that a user has entered a value –Example: Write “Enter the price in pounds” Input PoundPrice

1-6 Variables and Constants Data is input into a program variable. A variable is a named piece of memory whose value can change during the running of the program. Example: Write “Enter the price in pounds” Input PoundPrice The variable is PoundPrice. A value which cannot change is a constant. In this example, the constant is 1.62

1-7 Naming Variables All variable names must be one word Spaces are never allowed Variables cannot begin with a number Names should be meaningful Long names are allowed but names should be as short as possible, yet still be meaningful

1-8 Variable Name Examples Some examples: Miles_traveled is fine Miles Traveled is not (space) TaxRate_1 is fine 1_TaxRate is not (begins with a number) Variable1 is fine but not meaningful What’s wrong with these? My Number 2_4_6_8_go CowWhoJumpedOverTheMoon

Data Processing and Output  Set DollarPrice = 1.62 * PoundPrice The above statement is a processing statement. Take the value in the variable PoundPrice, multiply it by 1.62, and set the value of the variable DollarPrice to the result of the multiplication.  Write DollarPrice Output the value in DollarPrice to the monitor. Assignment statements change the value in a variable  Set counter = counter + 1 Take the value of counter, add 1, and store the result back in the same variable.

1-10 Arithmetic Operations +Addition2 + 3=5 -Subtraction7 – 3=4 *Multiplication5 * 4=20 /Division12 / 3=4 ^Exponentiation2 ^ 3=8 %Modulus14 % 3= 2

1-11 Hierarchy of Operations 1st: perform operations inside parentheses (from inside out if more than one) 2nd: perform exponentiation 3rd: do multiplications, divisions, and modulus from left to right (if there are more than one) 4th: do additions and subtractions from left to right (if there are more than one)

1-12 Example of Hierarchy of Operations 3 * (6 + 2) / 12 – (7 – 5) ^ 2 * 3 = ? ( ) first: = 3 * 8 / 12 – 2 ^ 2 * 3 ^ next: = 3 * 8 / 12 – 4 * 3 Leftmost * next: = 24 / 12 – 4 * 3 Division next:= 2 – 4 * 3 Multiply next: = 2 – 12 Subtract last: = -10

1-13 Data Output Data that is sent from the program to the screen, printer, or to a file is output. In pseudocode, the following statement will display the value of the variable to the screen and send the cursor to the next line: Write DollarPrice Given the following statement: Write “The price of the item is”, DollarPrice, “ dollars” The output will look like this: The price of the item is 162 dollars Note that the text inside the “ ” is output to the user as is, and it is the value in the variable that is output.

1-14 Annotate the Output If the output consists of numbers or any data that has no explanatory text with it, you should annotate your output – this means to add some text so the user knows what the output means. Example: if Test1 and Test2 are 2 exam scores for a student: Average = (Test1 + Test2) / 2 Write “The student’s average is: “  annotated Write Average

Types of Data Numeric Data –Integer data (whole numbers) –Real (Floating point) data (numbers that have a decimal point) –Note: 5 and 5.0 are stored differently in a computer even though they have the same value. The first, 5 is an Integer but the second, 5.0 is a Real number. Character data (alphanumerics) –All the characters you can type at the keyboard –The type is String or Character

1-16 The Declare Statement Variables should be declared to identify what the type is. We use the following: –Declare MyWholeNumber As Integer –Declare MyDecimalNumber As Real –Declare MyText As String

1-17 Exponential Notation Scientific notation: 680,000 = 6.8 x ,502,000,000 = x = 6.8 x = x Exponential notation: 680,000 = 6.8E+5 1,502,000,000 = 1.502E = 6.8E = 1.502E-5

1-18 Character String Data Character: any symbol that can be typed at the keyboard Character string: a sequence of characters Character and String Data Types: –Declare MyInitial As Character declares a variable named MyInitial as a Character type –Declare MyName As String declares a variable named MyName as a String type

1-19 Concatenation Concatenation takes two strings and joins them to create a string result The concatenation operator is symbolized, in pseudocode, with a + sign Example: if: String1 = “yellow” and String2 = “duckie” then the statement: Set MyFriend = String1 + String2 results in: MyFriend = “yellow duckie”

1-20 Pseudocode Language (Ch 1) Our pseudocode language will be expanded throughout the text. In this chapter we learned how to input, output, assign values to variables, and perform arithmetic calculations. InputAssignment Input Variable Set Variable = 10 Set Variable = AnotherVariable OutputArithmetic Operations Write “literal text” Write Variable ( ) ^ * / % + - Write “literal text”, Variable