© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,

Slides:



Advertisements
Similar presentations
Chapter 2 Part B CISS 241. Take a few moments and work with another student to develop an algorithm for a program that will add two whole numbers (integers)
Advertisements

Lecture 2 Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
 2008 Pearson Education, Inc. All rights reserved Introduction to C++ Programming.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Microsoft Visual Basic: Reloaded Chapter Three Memory Locations and Calculations.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Introduction to C++ Programming
Introduction to C++ Programming
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhancing the Wage Calculator Application Introducing Function Procedures and.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
 2008 Pearson Education, Inc. All rights reserved. 1 CISC 1600 – Computer Science I Fall 2010 Introduction to C++ Programming Chapters 1 and 2 (Deitel.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Week 1 Algorithmization and Programming Languages.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
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 
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
 2006 Pearson Education, Inc. All rights reserved Introduction to C++ Programming.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
 2008 Pearson Education, Inc. All rights reserved Introduction to C++ Programming.
Chapter 02 (Part II) Introduction to C++ Programming.
REEM ALMOTIRI Information Technology Department Majmaah University.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 of C++ How to Program, 10/e © by Pearson Education, Inc. All Rights Reserved.
© by Pearson Education, Inc. All Rights Reserved.
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
INPUT & OUTPUT scanf & printf.
Introduction to C++ Programming
Introduction to C++ Programming
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Presentation transcript:

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables, Input, Memory Concepts and Arithmetic Outline 3.1 Test-Driving the Inventory Application 3.2 Variables 3.3 Performing Stream Input Using cin 3.4 Performing a Calculation and Displaying the Result 3.5 Memory Concepts 3.6 Arithmetic 3.7 Using the Debugger: Breakpoints 3.8 Web Resources 3.9 Wrap-Up

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this tutorial, you will learn to: –Define variables. –Enable your applications to accept input that the user types at the keyboard. –Use arithmetic operators. –Use cin to store user input in an int. –Apply basic memory concepts using variables. –Use the precedence rules of arithmetic operators. –Set breakpoints to debug applications.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.1 Test-Driving the Inventory Application

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.1 Test-Driving the Inventory Application (Cont.) Figure 3.1 Inventory application with quantities entered.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.1 Test-Driving the Inventory Application (Cont.) Figure 3.2 Calculating the total in the Inventory application. Result of calculation

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.2 Variables Area of computer’s memory that holds data –Defining a variable Specify a variable type Can also specify an optional initialization value –Variable names Must be a valid identifier –Can contain letters, digits and underscores (Number_5 is valid) –Cannot begin with a digit (“4thVariable” is invalid) –Cannot be the same as a C++ reserved keyword (“true” is invalid) –Identifiers are case sensitive (“A” and “a” are different)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.2 Variables (Cont.) Figure 3.3 Defining variables in the main function. Variable definitions int type –Stores whole number values

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.2 Variables (Cont.)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.3 Performing Stream Input Using cin Stream input –Stream extraction operator >> –Input stream object cin –Use both together to retrieve input from the keyboard –Example: cin >> integer1 (“ cin inputs a value into integer1 ”)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.3 Performing Stream Input Using cin (Cont.) Figure 3.5 Prompt user for input and read value. Prompt user for number of cartons Place value entered by user in the cartons variable

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.3 Performing Stream Input Using cin (Cont.) Figure 3.6 Prompt user for input and store the value in the items variable. Prompt user for items per cartons Place value entered by user in the items variable

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.4 Performing a Calculation and Displaying the Result Figure 3.7 Using multiplication in the Inventory application. Multiplication operator * Assignment operator = Multiply the integer values and store the result in result

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.4 Performing a Calculation and Displaying the Result (Cont.) Figure 3.8 Displaying the result. Display the result Stream manipulator endl Displays a new line and flushes the output buffer Concatenating stream insertion operations Use multiple stream insertion operators in a single statement

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.4 Performing a Calculation and Displaying the Result (Cont.) Figure 3.9 Executing the completed Inventory application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Inventory.cpp (1 of 2) Use the int keyword to define variables inside a function Assigns user input to variable

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Inventory.cpp (2 of 2) Assigns user input to variable Calculate a result

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.5 Memory Concepts Figure 3.11 Memory location showing name and value of variable cartons. Every variable has a name, size, type and value

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.5 Memory Concepts (Cont.) Figure 3.12 Memory locations after assigning values to cartons and items. Writing to a memory location is destructive

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.5 Memory Concepts (Cont.) Figure 3.13 Memory locations after a multiplication operation. Reading a value from a memory location is nondestructive

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.6 Arithmetic x y + and – unary operators allow programmers to specify positive ( +9 ) and negative ( -19 ) numbers Numbers are positive by default ( 9 is the same as +9 ) Integer division truncates (discards the remainder) Arithmetic expressions must be written in straight-line form

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.6 Arithmetic (Cont.) Precedence is the order in which operators are applied Redundant parentheses make expressions easier to read

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints Logic errors (also called bugs) –Do not prevent code from compiling –Cause applications to produce erroneous results Breakpoint –Pauses execution before executing a specified line –If a breakpoint is placed on a non-executable line, execution is paused before the next executable line –Add a breakpoint by: Clicking inside the margin indicator bar or Right-clicking a line of code and selecting Insert Breakpoint

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.16 Setting Solution Configuration to Debug. Down arrow Solution Configuration ComboBox

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.17 Setting two breakpoints. Breakpoints Margin indicator bar Margin indicator bar is the gray bar left of the code field When the debugger pauses execution at a breakpoint, the application is said to be in break mode

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.18 Inventory application running.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.19 Title bar of the IDE displaying [break]. Title bar displays [break]

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.20 Application execution suspended at the first breakpoint. Yellow arrow Next executable statement The yellow arrow points to the line containing the next statement to execute

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.21 Displaying a variable value by placing the mouse pointer over a variable name. Quick Info box displays the result variable’s value

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.22 Setting a breakpoint at line 31 prevents the application from exiting immediately after displaying its result.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.23 Application output. When there are no more breakpoints, application will execute to completion

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Figure 3.24 Disabled breakpoint. Disabled breakpoint Disabling a Breakpoint Right-click the line of code and select Disable Breakpoint

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.7 Using the Debugger: Breakpoints (Cont.) Removing a Breakpoint –Click the maroon circle in the margin indicator bar or –Right-click the line of code and select Remove Breakpoint

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3.8 Web Resources msdn.microsoft.com/visualc