Data Types and Expressions

Slides:



Advertisements
Similar presentations
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.
Advertisements

Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
C# Programming: From Problem Analysis to Program Design1 3 Data Types and Expressions C# Programming: From Problem Analysis to Program Design 2 nd Edition.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
C# Programming: From Problem Analysis to Program Design1 Data Types and Expressions C# Programming: From Problem Analysis to Program Design 3rd Edition.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
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.
Objectives You should be able to describe: Data Types
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
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)
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3: Assignment, Formatting, and Interactive Input.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
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.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
© 2016, Mike Murach & Associates, Inc.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 3: Understanding C# Language Fundamentals
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
C# Programming: From Problem Analysis to Program Design
Lecture 3 Expressions Richard Gesick.
Data Types and Expressions
Chapter 2: Basic Elements of Java
Introduction to Java, and DrJava part 1
A First Book of ANSI C Fourth Edition
Chapter 2 Variables.
Data Types and Expressions
Introduction to Java, and DrJava
Data Types and Expressions
Chapter 7 Expressions and Assignment Statements.
Topics Designing a Program Input, Processing, and Output
Relational Operators.
Topics Designing a Program Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition
Primitive Types and Expressions
Introduction to Java, and DrJava part 1
Chapter 2 Variables.
Chapter 2 Primitive Data Types and Operations
DATA TYPES There are four basic data types associated with variables:
PRESENTED BY ADNAN M. UZAIR NOMAN
Data Types and Expressions
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

Data Types and Expressions 2 C# Programming: From Problem Analysis to Program Design 4th Edition C# Programming: From Problem Analysis to Program Design

Compound Operations Accumulation Variable on left side of equal symbol is used once the entire expression on right is evaluated Table 2-13 Compound arithmetic operators C# Programming: From Problem Analysis to Program Design

Basic Arithmetic Operations (continued) Order of operations Order in which the calculations are performed Example answer = 100; answer += 50 * 3 / 25 – 4; 50 * 3 = 150 150 / 25 = 6 6 – 4 = 2 100 + 2 = 102 C# Programming: From Problem Analysis to Program Design

Order of Operations Associatively of operators Left Right Table 2-14 Operator precedence Associatively of operators Left Right C# Programming: From Problem Analysis to Program Design

Order of Operations (continued) Figure 2-13 Order of execution of the operators C# Programming: From Problem Analysis to Program Design

Mixed Expressions Implicit type coercion Changes int data type into a double No implicit conversion from double to int double answer; answer = 10 / 3; // Does not produce 3.3333333 int value1 = 440, anotherNumber = 70; double value2 = 100.60; value2 = value1; // ok here – 440.0 stored in value2 C# Programming: From Problem Analysis to Program Design

Mixed Expressions int value1 = 440; double value2 = 100.60; value1 = value2; // syntax error as shown in Figure 2-14 Figure 2-14 Syntax error generated for assigning a double to an int C# Programming: From Problem Analysis to Program Design

Mixed Expressions (continued) Explicit type coercion Cast (type) expression examAverage = (exam1 + exam2 + exam3) / (double) count; int value1 = 0, anotherNumber = 75; double value2 = 100.99, anotherDouble = 100; value1 = (int) value2; // value1 = 100 value2 = (double) anotherNumber; // value2 = 75.0 C# Programming: From Problem Analysis to Program Design

Formatting Output You can format data by adding dollar signs, percent symbols, and/or commas to separate digits You can suppress leading zeros You can pad a value with special characters Place characters to the left or right of the significant digits Use format specifiers C# Programming: From Problem Analysis to Program Design

Formatting Output (continued) Table 2-15 Examples using format specifiers C# Programming: From Problem Analysis to Program Design

Numeric Format Specifiers Table 2-16 Standard numeric format specifiers C# Programming: From Problem Analysis to Program Design

Numeric Format Specifiers (continued) Table 2-16 Standard numeric format specifiers (continued) C# Programming: From Problem Analysis to Program Design

Custom Numeric Format Specifiers Table 2-17 Custom numeric format specifiers C# Programming: From Problem Analysis to Program Design

Custom Numeric Format Specifiers (continued) Table 2-17 Custom numeric format specifiers (continued) C# Programming: From Problem Analysis to Program Design

Width Specifier Useful when you want to control the alignment of items on multiple lines Alignment component goes after the index ordinal followed by a comma (before the colon) If alignment number is less than actual size, it is ignored If alignment number is greater, pads with white space Negative alignment component places spaces on right Console.WriteLine("{0,10:F0}{1,8:C}", 9, 14); 9 $14.00 //Right justifies values C# Programming: From Problem Analysis to Program Design

Coding Standards Naming conventions Spacing conventions Identifiers Spacing conventions Declaration conventions C# Programming: From Problem Analysis to Program Design

Resources Naming Guidelines for .NET – http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx Writing Readable Code – http://software.ac.uk/resources/guides/writing-readable-source-code#node-131 C# Video tutorials – http://www.programmingvideotutorials.com/csharp/csharp-introduction Visual Studio 2012 – C# – http://msdn.microsoft.com/en-us/library/kx37x362(V=VS.110).aspx C# Programming: From Problem Analysis to Program Design

Chapter Summary Memory representation of data Bits versus bytes Number system Binary number system Character sets Unicode C# Programming: From Problem Analysis to Program Design

Chapter Summary (continued) Memory locations for data Relationship between classes, objects, and types Predefined data types Integral data types Floating-point types Decimal type Boolean variables Strings C# Programming: From Problem Analysis to Program Design

Chapter Summary (continued) Constants Assignment statements Order of operations Formatting output C# Programming: From Problem Analysis to Program Design