Chapter 3 The New Math.

Slides:



Advertisements
Similar presentations
Dale/Weems/Headington
Advertisements

Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 3 Expressions.
More Review, with Some New Chapter 3. Review C++ simple data types – Integral and float – Arithmetic operators Expressions and expression evaluation –
Numeric Types, Expressions, and Output ROBERT REAVES.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 4 Numeric Types.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
1 Chapter 3 Topics Constants of Type int and float l Evaluating Arithmetic Expressions l Implicit Type Coercion and Explicit Type Conversion l Calling.
1 Lecture 7 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Data Types, Expressions and Functions (part I)
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
1 Numeric Types, Expressions, and Output. 2 Chapter 3 Topics  Constants of Type int and float  Evaluating Arithmetic Expressions  Declaration for Numeric.
Numeric Types, Expressions, and Output 1. Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems.
1 Chapter 3 Numeric Types, Expressions, and Output CS185/09 - Introduction to Programming Caldwell College.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Numeric Types, Expressions, and Output ROBERT REAVES.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
1 Chapter 3 Numeric Types, Expressions, and Output.
Chapter 3 Arithmetic Expressions, Function Calls, and Output
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Chapter 3: Assignment, Formatting, and Interactive Input.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
C++ Data Types Check sample values of? ‘4’
Chapter 3 Numeric Types, Expressions, and Output.
Chapter 3 The New Math. C++ Data Types simple integral charshort intlong bool floating float double Long double enum address pointer reference structured.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
Chapter 3 Numeric Types, Expressions, and Output
Chapter 7: Expressions and Assignment Statements
BASIC ELEMENTS OF A COMPUTER PROGRAM
Relational Operations
Chapter 7: Expressions and Assignment Statements
Assignment and Arithmetic expressions
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
Operators and Expressions
Conversions of the type of the value of an expression
Chapter 2: Basic Elements of Java
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Data Types and Expressions
An Introduction to Programming with C++ Fifth Edition
Primitive Types and Expressions
Lecture 3 Expressions, Type Conversion, and string
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

Chapter 3 The New Math

C++ Data Types

Numeric Data Types char 1 byte short 2 bytes int 4 bytes long

More Numeric Data Types float 4 bytes double 8 bytes long double

Declarations Constant Examples Variable Examples const float PI = 3.14159; const float E = 2.71828; const int MAX_SCORE = 100; Variable Examples int studentCount; char grade; float averageGrade;

Simple Arithmetic Expressions Expressions are made up of constants, variables and operators Examples alpha + 2 rate – 6.0 4 – alpha rate alpha * num

Arithmetic Operators - Unary Minus + Unary Plus - Subtraction + Addition * Multiplication / Division % Modulus

Expression 3 + 6 3.4 – 6.1 2 * 3 8 / 2 8.0 / 2.0 8 / 8 8 / 9 8 / 7 8 % 8 8 % 9 8 % 7 0 % 7 5 % 2.3 Value 9 -2.7 6 4 4.0 1 8 error

Oh yeah, don’t forget Increment ++ Decrement --

Let’s Get Tricky Precedence Rules Highest: ++ -- Unary + Unary – Middle: * / % Lowest: + - See page 1056 Appendix B for complete list

Type Coercion and Type Casting The implicit (automatic) conversion of a value from one data type to another Type Casting The explicit conversion of a value from one data type to another

Examples float someFloat = 3.4 / 2; int someInt = 3.4 / 2;

Casting someFloat = (double) 3 / (double) 4; someFloat = <static_cast>(double) 3 / <static_cast> (double) 4;

Function Calls Example Function Call (Function Invocation) int someInt = Cube(27); Function Call (Function Invocation) The mechanism that transfer control to the function Argument List (Parameter List) A mechanism by which functions communicate with each other

Formatting Output setw() fixed showpoint setprecision() Tells how many characters the next item outputted should have fixed Force all subsequent floating-point output to appear in decimal notation showpoint Force decimal points in all subsequent floating-point output; even whole numbers setprecision() Tells how many decimal places all subsequent floating-point output should have

String Functions length() or size() find() substr()