Data Types Declarations Expressions Data storage C++ Basics.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CS 117 Spring 2002 Basic Program Elements Chapter 2.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
A First Book of ANSI C Fourth Edition
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Numeric Types, Expressions, and Output ROBERT REAVES.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
Arithmetic in Pascal A Short Glance We will learn the followings in this chapter Arithmetic operators Order of precedence Assignment statements Arithmetic.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
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 Syntax, Errors, and Debugging Fundamentals of Java.
Copyright © – Curt Hill Types What they do.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 4.
is a specific set of data values along with a set of operations on those values. Review * Data type.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Computer Programming BCT 1113
Chapter 2: Introduction to C++
Data Types, Variables & Arithmetic
BASIC ELEMENTS OF A COMPUTER PROGRAM
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CSE 100 Data Types Declarations Displays.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Review Data type is a specific set of data values along with a set of operations on those values. *
Chapter 2: Introduction to C++.
Module 2 Variables, Data Types and Arithmetic
Programming Fundamental-1
Presentation transcript:

Data Types Declarations Expressions Data storage C++ Basics

Data Types Integers – ordinal numbers Integers – ordinal numbers Floating – real numbers Floating – real numbers Address – memory location Address – memory location Structured - aggregates Structured - aggregates

Integer Data Types char 256 possibilities; enclosed in single quotes char 256 possibilities; enclosed in single quotes int no decimal points no commas no special signs ($, ¥, ‰) int no decimal points no commas no special signs ($, ¥, ‰) Characters can be treated as integers -- a legacy from C cout << ‘B’ – 1 << ‘\n’

Int Data Types Int -- Signed vs. Unsigned short 65,536 numbers -32,768 to 32,767 short 65,536 numbers -32,768 to 32,767 long 4,294,967,296 numbers  2,147,483,648 long 4,294,967,296 numbers  2,147,483,648 enum – a collection of symbolic related constants enum – a collection of symbolic related constants *

Real Number Data Types Floating point numbers: signed or unsigned with decimal point Floating point numbers: signed or unsigned with decimal point Types: differ in amount of storage space; varies with machine Types: differ in amount of storage space; varies with machine  float (single precision)  double  long double  float (single precision)  double  long double Use sizeof ( ) to find amount of storage space used. See pages in text Use sizeof ( ) to find amount of storage space used. See pages in text * * * Floating point Floating point numbers:

Data Types Address pointer value is an actual address reference - an alias for another variable CONFUSING, don’t use (yet) Structured array - an ordered list of like items Address pointer value is an actual address reference - an alias for another variable CONFUSING, don’t use (yet) Structured array - an ordered list of like items strings are a type of an array struct – unordered heterogeneous set class – the basis of OO in C++ strings are a type of an array struct – unordered heterogeneous set class – the basis of OO in C++

Constants Literal typed directly into the program as needed ex. y = 23.4pi = Symbolic (Named) similar to a variable, but cannot be changed after it is initialized Syntax: const type VAR = value Symbolic (Named) similar to a variable, but cannot be changed after it is initialized Syntax: const type VAR = value Ex: const int CLASS_SIZE = 87; const double PI = ; Ex: const int CLASS_SIZE = 87; const double PI = ; * can change can NOT change

Operators An operator is a symbol that causes the compiler to take an action. An operator is a symbol that causes the compiler to take an action. * Categories: mathematical assignment boolean / logical etc.

Arithmetic Operators addition+ addition+ subtraction - subtraction - multiplication * multiplication * division / division / modulus( remainder ) % modulus( remainder ) % Unary (minus) operator Unary (minus) operator x = -3; x = -3; y = -x; y = -x;

Arithmetic Expressions Syntax operand operator operand Example * / % 3 Example * / % 3 *

Modulus 12/3 14/3 12%3 14%3 The modulus operator yields the remainder of integer division. The modulus operator yields the remainder of integer division. *

A Glimpse of Operator Overloading Operator overload Using the same symbol for more than one operation. Operator overload Using the same symbol for more than one operation. type int / type int 9 / 5 operator performs int division type double / type double 9.0 / 5.0 operator performs double division *

Modulus The modulus operator yields the remainder of integer division. The modulus operator yields the remainder of integer division. 18 % 4 is 2 13 % 4 is 1 17 % 3 is 2 35 % 47 is % 6 is 0 24 % 4 is 0 4 % 18 is 4 0 % 7 is 0 18 % 4 is 2 13 % 4 is 1 17 % 3 is 2 35 % 47 is % 6 is 0 24 % 4 is 0 4 % 18 is 4 0 % 7 is 0 12 % 2.5 error 6.0 % 6 error 12 % 2.5 error 6.0 % 6 error Requires floating point division, NOT the same Requires floating point division, NOT the same * * *

Mixed-Mode Expressions Operator overload Same operator will behave differently depending upon the operands. Operands of the same type give results of that type. Operator overload Same operator will behave differently depending upon the operands. Operands of the same type give results of that type. In mixed-mode, floating point takes precedence. In mixed-mode, floating point takes precedence. *

Integer Division int a, b; a = 8; b = 3; cout << “The result is “ << a / b << endl; The result is 2 int a, b; a = 8; b = 3; cout << “The result is “ << a / b << endl; The result is 2 8 / 3 is 2 and not The result must be an integer. The result is truncated to 2. *

Order of Operations * 4 is ? * 4 is ? Show associativity to clarify. ( ) * 4 is ( 3 * 4 ) is 20 Without parentheses, * 4 is 20 Show associativity to clarify. ( ) * 4 is ( 3 * 4 ) is 20 Without parentheses, * 4 is 20 * P E M D A S from left to right

Order of Operations Expression Value 10 / 2 * 3 10 % / * 2.0 / 4.0 * * 2.0 / (4.0 * 2.0) / (4.0 * 2.0) Expression Value 10 / 2 * 3 10 % / * 2.0 / 4.0 * * 2.0 / (4.0 * 2.0) / (4.0 * 2.0) * * * * *

Evaluation Trees i i 10 / 2 * 3 * 10 % / 2 i i i 5.0 * 2.0 / 4.0 * 2.0 r r r 5 * 2 / (4.0 * 2.0) i r r

Evaluation Trees 5.0 * 2.0 / 4.0 * / (4.0 * 2.0) (5 + 2) / (4.0 * 2.0) i r r r r r r r r

Those who fail to plan, plan to fail