Chapter03.ppt
Document Details
![IndebtedOwl](https://quizgecko.com/images/avatars/avatar-4.webp)
Uploaded by IndebtedOwl
2017
Tags
Full Transcript
Chapter 3: Expressions and Interactivity Starting Out with C++ Early Objects Ninth Edition, Global Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Copyright © 2017 Pe...
Chapter 3: Expressions and Interactivity Starting Out with C++ Early Objects Ninth Edition, Global Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Copyright © 2017 Pearson Education, Ltd. Topics 3.1 The cin Object 3.2 Mathematical Expressions 3.3 Data Type Conversion and Type Casting 3.5 Named Constants Copyright © 2017 Pearson Education, Ltd. 3-2 Topics (continued) 3.6 Multiple and Combined Assignment 3.7 Formatting Output 3.8 Working with Characters and Strings 3.9 More Mathematical Library Functions Copyright © 2017 Pearson Education, Ltd. 3-3 3.1 The cin Object cin is the standard input object Like cout, requires iostream file Used to read input from keyboard Often used with cout to display a user prompt first Data is retrieved from cin with >>, the stream extraction operator Input data is stored in one or more variables Copyright © 2017 Pearson Education, Ltd. 3-4 The cin Object User input goes from keyboard to the input buffer, where it is stored as characters cin converts the data to the type that matches the variable int height; cout > height; Copyright © 2017 Pearson Education, Ltd. 3-5 The cin Object Can be used to input multiple values cin >> height >> width; Multiple values from keyboard must be separated by spaces or [Enter] Must press [Enter] after typing last value Multiple values need not all be of the same type Order is important; first value entered is stored in first variable, etc. Copyright © 2017 Pearson Education, Ltd. 3-6 3.2 Mathematical Expressions An expression is something that can be evaluated to produce a value. It can be a constant, a variable, or a combination of constants and variables combined with operators and grouping symbols We can create complex expressions using multiple mathematical operators Examples of mathematical expressions: 2 height a + b / c Copyright © 2017 Pearson Education, Ltd. 3-7 Using Mathematical Expressions Can be used in assignment statements, with cout, and in other types of statements Examples: This is an expression area = 2 * PI * radius; cout