Integer Arithmetic. Operator Priority Real Number Arithmetic.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Type Conversion. C provides two methods of changing the type of an expression: Type conversion (done implicitly) Cast expressions (done explicitly) Examples.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Variables: Named Storage Locations Variables must be defined or declared before they can be used so that appropriate memory storage can be allocated for.
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
1 9/17/07CS150 Introduction to Computer Science 1 Type Casting.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
CS150 Introduction to Computer Science 1
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Primitive Types, Strings, and Console I/O Chapter 2.1 Variables and Values Declaration of Variables Primitive Types Assignment Statement Arithmetic Operators.
Object-Oriented Programming Using C++ Third Edition Chapter 2 Evaluating C++ Expressions.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
1 CSC103: Introduction to Computer and Programming Lecture No 6.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Unit 3 Lesson 4 How Data Types Affect Calculations Dave Clausen La Cañada High School.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
CPS120: Introduction to Computer Science Operations Lecture 9.
Mathematical Calculations in Java Mrs. G. Chapman.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
Pointers A pointer is a variable that contains a memory address as it’s value. The memory address points to the actual data. –A pointer is an indirect.
C++ Programming, Namiq Sultan1 Chapter 3 Expressions and Interactivity Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin.
Introduction to Java Primitive Types Operators Basic input and output.
Data Types Declarations Expressions Data storage C++ Basics.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
Mathematical Calculations in Java Mrs. C. Furman.
GUJARAT KNOWLEDGE VILLAGE Faculty Name:- Prof H.M.Patel Students Name:- SONI VISHAL THAKKER BHAVIN ZALA JAYDIP ZALA.
is a specific set of data values along with a set of operations on those values. Review * Data type.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Copyright Curt Hill Casts What are they? Why do we need them?
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double. Sample variable declarations: int i, j, k; float numberOne,
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
1 CS161 Introduction to Computer Science Topic #6.
1 Primitive Types n Four integer types:  byte  short  int (most common)  long n Two floating-point types:  float  double (most common) n One character.
Introduction to Programming Lesson 3. #include #include main ( ) { cout
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Introduction to programming in java Lecture 21 Arrays – Part 1.
ISBN Chapter 7 Expressions and Assignments Statements.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Primitive Types Four integer types: Two floating-point types:
Variables Mr. Crone.
Chapter 2 Assignment and Interactive Input
What are they? Why do we need them?
Type Conversion, Constants, and the String Object
C++ Arrays.
Arithmetic Operator Operation Example + addition x + y
OPERATORS (1) CSC 111.
Examples of Primitive Values
Review Data type is a specific set of data values along with a set of operations on those values. *
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
Other types of variables
OPERATORS in C Programming
DATA TYPES AND OPERATIONS
OPERATORS in C Programming
Programming Fundamental-1
Presentation transcript:

Integer Arithmetic

Operator Priority

Real Number Arithmetic

Mixed-Mode Arithmetic When the operands are of the same type, the result is also of that type When the operands are of different types, the result is of the more inclusive type double int char More inclusive

Assignment Statement Form: = ; Example: x = y * z; 3 y 4 z 7 x Variables are names for memory locations

Mixed-Mode Assignment When the variable is of a more inclusive type, the value copied to it is promoted to that type When the variable is of a less inclusive type, the value copied to it is truncated and information may be lost

Mixed-Mode Assignment int i; double d; i = 2; d = i; // d contains 2.0

Mixed-Mode Assignment int i; double d; d = 3.56; i = d; // i contains 3

Type Cast Operations int i; double d; d = 3.56; i = d; // i contains 3 i = int(d); // same effect as above Form: ( )

Compound Assignment Statement

Interactive Input double payRate, hoursWorked, weeklyPay; cout << "Enter the pay rate: "; cin >> payRate; cout << "Enter the hours worked: "; cin >> hoursWorked; weeklyPay = hoursWorked * payRate; cout << "Weekly pay = " << weeklyPay << endl;

The ASCII Character Set 41 = ')'

Using apstring: Input and Output #include "apstring.h" apstring name; cout << "Enter your last name: "; cin >> name; cout << "Your last name is " << name << endl; >> reads a word up to a space or newline character

Using apstring: getline #include "apstring.h" apstring name; cout << "Enter your full name: "; getline(cin, name); cout << "Your full name is " << name << endl; getline reads an entire line, including blanks, up to a newline character

Using >> Before getline #include "apstring.h" apstring name; int age; cout << "Enter your age: "; cin >> age; cout << "Enter your full name: "; getline(cin, name); cout << "Your age is " << age << endl; cout << "Your full name is " << name << endl; getline encounters the trailing newline after the age, stores an empty string in name, and does not wait for user input

Put >> After getline, or Do This #include "apstring.h" apstring name; int age; cout << "Enter your age: "; cin >> age; cin.ignore(); // consume \n cout << "Enter your full name: "; getline(cin, name); cout << "Your age is " << age << endl; cout << "Your full name is " << name << endl;

Library Constants

Math Library Functions

apstring Member Functions