SOW_C++_CSO_Chapter_03_9e-1.ppt
Document Details
Uploaded by SelfSatisfactionRing
Full Transcript
STARTING OUT WITH C++ 9th Edition Chapter 3 Expressions and Interactivity Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved 3.1 The cin Object Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object Standard input object Like cout, requires iost...
STARTING OUT WITH C++ 9th Edition Chapter 3 Expressions and Interactivity Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved 3.1 The cin Object Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >> Input is stored in one or more variables Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object in Program 3-1 Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object cin converts data to the type that matches the variable: int height; cout > height; Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved Displaying a Prompt A prompt is a message that instructs the user to enter data. You should always use cout to display a prompt before each cin statement. cout > height; Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object Can be used to input more than one value: cin >> height >> width; Multiple values from keyboard must be separated by spaces Order is important: first value entered goes to first variable, etc. Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object Gathers Multiple Values in Program 3-2 Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved The cin Object Reads Different Data Types in Program 3-3 Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved 3.2 Mathematical Expressions Copyright © 2019, 2016, 2012 Pearson Education, Inc. All Rights Reserved Mathematical Expressions Can create complex expressions using multiple mathematical operators An expression can be a literal, a variable, or a mathematical combination of constants and variables Can be used in assignment, cout, other statements: area = 2 * PI * radius; cout