Data Types and Expressions

Size: px
Start display at page:

Download "Data Types and Expressions"

Transcription

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

2 Chapter Objectives C# Programming: From Problem Analysis to Program Design 2

3 Chapter Objectives (continued) C# Programming: From Problem Analysis to Program Design 3

4 Chapter Objectives (continued) C# Programming: From Problem Analysis to Program Design 4

5 Data Representation 0/ C# Programming: From Problem Analysis to Program Design 5

6 Bits and Bytes 6

7 Decimal Number System 7

8 Decimal Number System M 100K 10K , = 203,465

9 Data Representation (continued) Table 2-1 Binary equivalent of selected decimal values C# Programming: From Problem Analysis to Program Design 9

10 Binary Number System (continued) Figure 2-2 Decimal equivalent of

11 Binary Number System = 36 Figure 2-1 Base-10 positional notation of 36 11

12 Binary Number System Figure 2-1 Base-10 positional notation of

13 Data Representation (continued) ' ' '\u20ac' 13

14 Data Representation (continued) ASCII Table

15 Data Representation (continued)

16 Data Representation (continued) Console.WriteLine('\u00D1');

17 Data Representation (continued) 17

18 Memory Locations for Data customername, productcode, addressline1, savingaccountbalance 18

19 Reserved Words in C# 19

20 Contextual Keywords Table 2-4 C# contextual keywords Never use these words as variable names It is a very bad idea!!! 20

21 Naming Conventions Eg: FirstName, LastName Eg: firstname, lastname, savingaccountbalance 21

22 Examples of Valid Names (Identifiers) Table 2-5 Valid identifiers 22

23 Examples of Invalid Names (Identifiers) Table 2-6 Invalid identifier 23

24 Variables type identifier = expression; 24

25 Types, Classes, and Objects int, string C# Programming: From Problem Analysis to Program Design 25

26 Type, Class, and Object Examples Table 2-7 Sample data types C# Programming: From Problem Analysis to Program Design 26

27 Predefined Data Types Common Type System (CTS) Divided into two major categories Figure 2-3.NET common types 27

28 Value and Reference Types Figure 2-4 Memory representation for value and reference types 28

29 Value Types Figure 2-5 Value type hierarchy 29

30 Value Types Integral: 123 Floating point: 1.57e+3 (same as 1570) Decimal: 1.23 Boolean true / false Struct class Person {name, age, sex } Enumerated enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; enum Months : byte { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }; Figure 2-5 Type Examples 30

31 Value Types (continued) 31

32 Integral Data Types byte & sbyte char int & uint long & ulong short & ushort 32

33 Data Types Table 2-9 Values and sizes for integral types 33

34 Examples of Integral Variable Declarations int studentcount; // number of students in the class int ageofstudent = 20; // age-originally initialized to 20 int numberofexams; // number of exams int coursesenrolled; // number of courses enrolled 34

35 Floating-Point Types Table 2-10 Values and sizes for floating-point types 35

36 Examples of Floating-Point Declarations double extraperson = 3.50; double averagescore = 70.0; double priceofticket; double gradepointaverage; float totalamount = 23.57f; // extraperson originally set // to 3.50 // averagescore originally set // to 70.0 // cost of a movie ticket // grade point average // note the f must be placed after // the value for float types 36

37 Decimal Types Table 2-11 Value and size for decimal data type Examples decimal endowmentamount = M; decimal deficit; 37

38 Boolean Variables false bool undergraduatestudent; bool moredata = true; 38

39 Strings string studentname; string coursename = "Programming I"; string twolines = "Line1\nLine2"; 39

40 Making Data Constant const const type identifier = expression; const double TAX_RATE = ; const int SPEED = 70; const char HIGHEST_GRADE = 'A'; 40

41 Assignment Statements variable = expression; 41

42 Examples of Assignment Statements int numberofminutes, count, minintvalue; numberofminutes = 45; count = 0; minintvalue = ; count = count + 1; numberofminutes = 10 + Delay(clerkId); 42

43 Examples of Assignment Statements char firstinitial, yearinschool, punctuation, enterkey, lastchar; firstinitial = 'B'; yearinschool = '1'; punctuation = ';'; enterkey = '\n'; lastchar = '\u005a'; eurosymbol= '\u20ac'; // newline escape character // Unicode character 'Z' // Unicode character ' ' 43

44 Examples of Assignment Statements (continued) double accountbalance, weight; bool isfinished; accountbalance = ; weight = 1.7E-3; //scientific notation may be used isfinished = false; //declared previously as a bool //Notice no quotes used 44

45 Examples of Assignment Statements (continued) decimal amountowed, deficitvalue; amountowed = m; // m or M must be suffixed to deficitvalue = M; // decimal data types 45

46 Examples of Assignment Statements (continued) string asaying, filelocation; asaying = "First day of the rest of your life!\n"; filelocation 46

47 Examples of Assignment Statements (continued) Figure 2-7 Impact of assignment statement 47

48 Arithmetic Operations resultvariable = operand1 operator operand2; 48

49 Basic Arithmetic Operations Figure 2-8 Result of 67 % 3 49

50 Basic Arithmetic Operations (continued) string result; string fullname; string firstname = "Daenerys"; string lastname = "Targaryen"; fullname = firstname + " " + lastname; //now fullname is "Daenerys Targaryen" 50

51 Concatenation Figure 2-9 String concatenation 51

52 Basic Arithmetic Operations (continued) num++; // num = num + 1; --value1; // value = value 1; int num = 100; Console.WriteLine(num++); // Displays 100 Console.WriteLine(num); // Displays 101 Console.WriteLine(++num); // Displays

53 Basic Arithmetic Operations (continued) Figure 2-10 Declaration of value type variables 53

54 Basic Arithmetic Operations (continued) Figure 2-11 Change in memory after count++; statement executed 54

55 Basic Arithmetic Operations (continued) int num = 100; Console.WriteLine(num++); //prints 100 Console.WriteLine(num); //prints 101 Console.WriteLine(++num); //prints 102 C# Programming: From Problem Analysis to Program Design 55

56 Basic Arithmetic Operations (continued) Figure 2-12 Results after statement is executed 56

57 Compound Operations 57

58 Basic Arithmetic Operations (continued) answer = 100; answer += 50 * 3 / 25 4; 50 * 3 = / 25 = = =

59 Order of Operations Table 2-14 Operator precedence 59

60 Order of Operations (continued) Figure 2-13 Order of execution of the operators 60

61 Mixed Expressions double answer; answer = 10 / 3; // Does not produce double answer2; answer2 = 10.0 / 3; // produces int value1 = 440, anothernumber = 70; double value2 = ; value2 = value1; // ok, stored in value2 61

62 Mixed Expressions int value1 = 440; double value2 = ; value1 = value2; // syntax error as shown in Figure 2-14 double int 62

63 Mixed Expressions (continued) (type) expression examaverage = (exam1 + exam2 + exam3) / (double) count; int value1 = 0, anothernumber = 75; double value2 = , anotherdouble = 100; value1 = (int) value2; // value1 = 100 value2 = (double) anothernumber; // value2 =

64 Mixed Expressions (continued) Convert int v1 = Convert.ToInt32(1.999); // v1 is 1 long v2 = Convert.ToInt64("5.7777"); // v2 is string v3 = Convert.ToString(1.999); // v3 is "1.999" char v4 = Convert.ToChar(65); // v4 is 'A' 64

65 Formatting Output 65

66 Formatting Output (continued) Table 2-15 Examples using format specifiers 66

67 Numeric Format Specifiers 67

68 Numeric Format Specifiers (continued) 68

69 Custom Numeric Format Specifiers Table 2-17 Custom numeric format specifiers 69

70 Custom Numeric Format Specifiers (continued) 70

71 Width Specifier Console.WriteLine("{0,10:F0}{1,8:C}", 9, 14); 9 $14.00 //Right justified values

72 Programming Example CarpetCalculator 72

73 Data Needs for the CarpetCalculator Table 2-18 Variables 73

74 Nonchanging Definitions for the CarpetCalculator Side Note: 1 yard = 3 feet 1 sqy = 9 sqf Table 2-19 Constants 74

75 CarpetCalculator Example 75

76 Algorithm for CarpetCalculator Example Figure 2-17 CarpetCalculator flowchart 76

77 Algorithm for the CarpetCalculator Example (continued) Figure 2-18 Structured English for the CarpetCalculator example 77

78 CarpetCalculator Example (continued) Figure 2-19 Class diagram for the CarpetCalculator example 78

79 CarpetCalculator Example (continued) Figure 2-20 Revised class diagram without methods 79

80 /* CarpetCalculator.cs Author: Doyle */ using System; namespace CarpetExample { class CarpetCalculator { static void Main( ) { const int SQ_FT_PER_SQ_YARD = 9; const int INCHES_PER_FOOT = 12; const string BEST_CARPET = "Berber"; const string ECONOMY_CARPET = "Pile"; int roomlengthfeet = 12, roomlengthinches = 2, roomwidthfeet = 14, roomwidthinches = 7; double roomlength, roomwidth, carpetprice, numofsquarefeet, numofsquareyards, totalcost; 80

81 roomlength = roomlengthfeet + (double) roomlengthinches / INCHES_PER_FOOT; roomwidth = roomwidthfeet + (double) roomwidthinches / INCHES_PER_FOOT; numofsquarefeet = roomlength * roomwidth; numofsquareyards = numofsquarefeet / SQ_FT_PER_SQ_YARD; carpetprice = 27.95; //per square yard totalcost = numofsquareyards * carpetprice; Console.WriteLine("The cost of " + BEST_CARPET + " is {0:C}", totalcost); Console.WriteLine( ); } } } carpetprice = 15.95; //per square yard totalcost = numofsquareyards * carpetprice; Console.WriteLine("The cost of " + ECONOMY_CARPET + " is " + "{0:C}", totalcost); Console.Read(); 81

82 Coding Standards C# Programming: From Problem Analysis to Program Design 82

83 Resources Naming Guidelines for.net Writing Readable Code C# Video tutorials Visual Studio 2012 C# 83

84 Chapter Summary C# Programming: From Problem Analysis to Program Design 84

85 Chapter Summary (continued) C# Programming: From Problem Analysis to Program Design 85

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

87 using System; using System.Globalization; using System.Resources; using System.Threading; Appendix 1 Formatting Numbers class Sample { public static void Main() { Console.WriteLine(String.Format("{0:0.00}", )); // Console.WriteLine(String.Format("{0:0.00}", 1.2)); // 1.20 Console.WriteLine(String.Format("{0:0.00}", 0.1)); // 0.10 Console.WriteLine(String.Format("{0:0.00}", 123.0)); // Console.WriteLine(String.Format("{0:0.00}", 123)); // Console.WriteLine(String.Format("{0:00.0}", ) ); // Console.WriteLine(String.Format("{0:00.0}", 1.99) ); // 02.0 Console.WriteLine(String.Format("{0:0,0.0}", )); // 12,345.7 Console.WriteLine(String.Format("{0:#.00}", 0.1) ); //.10 Console.WriteLine(String.Format("{0,10:0.0}", )); // Console.WriteLine(String.Format("{0,-10:0.0}", )); // Console.WriteLine(String.Format("Balance is ${0,-10:0.0}USD", )); // Balance is $123.5 USD Console.WriteLine(String.Format("{0:Balance is $0.0 USD}", )); // Balance is $123.5 USD Console.WriteLine(String.Format("{0:00000}", 123) ); // Console.WriteLine(String.Format("{0,5}", 123) ); // 123 Console.WriteLine(String.Format("{0,-5}", 123)); // 123 Console.WriteLine(String.Format("{0:(###) ###-####}", )); // (216) Console.WriteLine(String.Format("{0:(000) }", )); // (216) double decnum = 1.23; string strusa = decnum.tostring(cultureinfo.invariantculture.numberformat); // "1.23" string streurope = decnum.tostring(cultureinfo.getcultureinfo("es-es").numberformat); // "1,23" Console.WriteLine(strUSA ); // "1.23" Console.WriteLine(strEurope ); // "1,23" Console.ReadKey(); } } 87

88 using System; using System.Globalization; using System.Resources; using System.Threading; Appendix 2 Formatting Dates class DemoFormatDates { public static void Main() { //using other Culture values. See Link: // //Thread.CurrentThread.CurrentCulture = new CultureInfo("es-VE"); //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-UK"); //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //Thread.CurrentThread.CurrentCulture = new CultureInfo("el-GR"); CultureInfo ci = Thread.CurrentThread.CurrentCulture; Console.WriteLine(ci); // en-us DateTime dt = DateTime.Now; Console.WriteLine(dt); // 8 / 8 / :39:58 PM Console.WriteLine(String.Format("{0:y yy yyy yyyy}", dt)); // Console.WriteLine(String.Format("{0:M MM MMM MMMM}", dt)); // 8 08 Aug August Console.WriteLine(String.Format("{0:d dd ddd dddd}", dt)); // 8 08 Sat Saturday Console.WriteLine(String.Format("{0:h hh H HH}", dt)); // hour 12/24 Console.WriteLine(String.Format("{0:m mm}", dt)); // minutes Console.WriteLine(String.Format("{0:s ss}", dt)); // seconds Console.WriteLine(String.Format("{0:t tt}", dt)); // P PM A.M. or P.M. Console.WriteLine(String.Format("{0:z zz zzz}", dt)); // :00 time zone Console.ReadKey(); } } C# Programming: From Problem Analysis to Program Design 88

89 using System; using System.Globalization; using System.Resources; using System.Threading; Appendix 3 Formatting Dates class Sample { public static void Main() { DateTime dt = DateTime.Now; Console.WriteLine(dt); // 8 / 8 / :22:15 PM Console.WriteLine(String.Format("{0:t}", dt)); // 10:22 PM Console.WriteLine(String.Format("{0:T}", dt)); // 10:22:15 PM Console.WriteLine(String.Format("{0:d}", dt)); // 8 / 8 / 2015 Console.WriteLine(String.Format("{0:D}", dt)); // Saturday, August 08, 2015 ShortTime LongTime ShortDate LongDate Console.WriteLine(String.Format("{0:F}", dt)); // Saturday, August 08, :22:15 PM FullDateTime Console.WriteLine(String.Format("{0:r}", dt)); // Sat, 08 Aug :22:15 GMT Console.WriteLine(String.Format("{0:u}", dt)); // :22:15Z RFC1123 UniversalSortableDate Console.ReadKey(); } } C# Programming: From Problem Analysis to Program Design 89

90 using System; using System.Globalization; using System.Resources; using System.Threading; Appendix 4 Formatting Tables class Sample { public static void Main() { Console.WriteLine("First Name Last Name Age "); Console.WriteLine(" ===============+-----"); Console.WriteLine(String.Format("{0,-10} {1,-15} {2,5}", "Daenerys", "Targaryen", 19)); Console.WriteLine(String.Format("{0,-10} {1,-15} {2,5}", "Drogon", "", 3)); Console.WriteLine(String.Format("{0,-10} {1,-15} {2,5}", "Maester", "Aemon", 102)); Console.WriteLine(" ===============+-----"); Console.ReadKey(); } } 90

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

Data Types and Expressions. C# Programming: From Problem Analysis to Program Design 2nd Edition 3 Data Types and Expressions C# Programming: From Problem Analysis to Program Design 2nd Edition David McDonald, Ph.D. Director of Emerging Technologies Chapter Objectives Declare memory locations for

More information

Agenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals

Agenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals Agenda & Reading COMPSCI 80 S Applications Programming Programming Fundamentals Data s Agenda: Data s Value s Reference s Constants Literals Enumerations Conversions Implicitly Explicitly Boxing and unboxing

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

AIMMS Function Reference - Date Time Related Identifiers

AIMMS Function Reference - Date Time Related Identifiers AIMMS Function Reference - Date Time Related Identifiers This file contains only one chapter of the book. For a free download of the complete book in pdf format, please visit www.aimms.com Aimms 3.13 Date-Time

More information

Date and Time Functions

Date and Time Functions Date and Time Functions Introduction If you are using these functions in conjunction with either the Now() or Now_() functions, be aware that the time zone returned is the one configured on the machine

More information

typedef int Array[10]; String name; Array ages;

typedef int Array[10]; String name; Array ages; Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

10/9/2012. Computers are machines that process data. assignment in C# Primitive Data Types. Creating and Running Your First C# Program

10/9/2012. Computers are machines that process data. assignment in C# Primitive Data Types. Creating and Running Your First C# Program Primitive Data Types 1. Creating and Running Your First C# Program Integer Floating-Point / Decimal Floating-Point Boolean Character String Object Declaring and Using Variables 2. Identifiers Declaring

More information

Advanced Computer Programming

Advanced Computer Programming Hazırlayan Yard. Doç. Dr. Mehmet Fidan VARIABLE TYPES Integral Types: In C#, an integral is a category of types. For anyone confused because the word Integral sounds like a mathematical term, from the

More information

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Objectives. Describe ways to create constants const readonly enum

Objectives. Describe ways to create constants const readonly enum Constants Objectives Describe ways to create constants const readonly enum 2 Motivation Idea of constant is useful makes programs more readable allows more compile time error checking 3 Const Keyword const

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 10 Structures, Unions, Bit Manipulations and Enumerations Department of Computer Engineering

More information

EEE145 Computer Programming

EEE145 Computer Programming EEE145 Computer Programming Content of Topic 2 Extracted from cpp.gantep.edu.tr Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department

More information

Programming for Engineers Structures, Unions

Programming for Engineers Structures, Unions Programming for Engineers Structures, Unions ICEN 200 Spring 2017 Prof. Dola Saha 1 Structure Ø Collections of related variables under one name. Ø Variables of may be of different data types. Ø struct

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

DigiPen Institute of Technology

DigiPen Institute of Technology DigiPen Institute of Technology Presents Session Two: Overview of C# Programming DigiPen Institute of Technology 5001 150th Ave NE, Redmond, WA 98052 Phone: (425) 558-0299 www.digipen.edu 2005 DigiPen

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

A class is a user-defined type. It is composed of built-in types, other user-defined types and

A class is a user-defined type. It is composed of built-in types, other user-defined types and Chapter 3 User-defined types 3.1 Classes A class is a user-defined type. It is composed of built-in types, other user-defined types and functions. The parts used to define the class are called members.

More information

Unit 3. Constants and Expressions

Unit 3. Constants and Expressions 1 Unit 3 Constants and Expressions 2 Review C Integer Data Types Integer Types (signed by default unsigned with optional leading keyword) C Type Bytes Bits Signed Range Unsigned Range [unsigned] char 1

More information

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values Data Types 1 data type: a collection of values and the definition of one or more operations that can be performed on those values C++ includes a variety of built-in or base data types: short, int, long,

More information

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems Overview The Pascal Programming Language (with material from tutorialspoint.com) Background & History Features Hello, world! General Syntax Variables/Data Types Operators Conditional Statements Functions

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

Bit (0, 1) Byte (8 bits: 0-255) Numeral systems. Binary (bin) 0,1 Decimal (dec) 0, 1, 2, 3, Hexadecimal (hex) 0, 1, 2, 3, 1/13/2011

Bit (0, 1) Byte (8 bits: 0-255) Numeral systems. Binary (bin) 0,1 Decimal (dec) 0, 1, 2, 3, Hexadecimal (hex) 0, 1, 2, 3, 1/13/2011 * VB.NET Syntax I 1. Elements of code 2. Declaration and statements 3. Naming convention 4. Types and user defined types 5. Enumerations and variables Bit (0, 1) Byte (8 bits: 0-255) Numeral systems Binary

More information

Methods and Behaviors. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Methods and Behaviors. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies 4 Methods and Behaviors C# Programming: From Problem Analysis to Program Design 2nd Edition David McDonald, Ph.D. Director of Emerging Technologies Chapter Objectives Become familiar with the components

More information

Outline. Data and Operations. Data Types. Integral Types

Outline. Data and Operations. Data Types. Integral Types Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

More information

Schedule/BACnet Schedule

Schedule/BACnet Schedule Object Dictionary 1 Schedule/BACnet Schedule Introduction Note: The Johnson Controls Schedule object is considered a BACnet Schedule object because it supports BACnet functionality. In addition, this object

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work

More information

CS1100 Introduction to Programming

CS1100 Introduction to Programming CS1100 Introduction to Programming Arrays Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB, PSK, NSN, DK, TAG CS&E, IIT M 1 An Array

More information

Making Decisions Chp. 5

Making Decisions Chp. 5 5 Making Decisions Chp. 5 C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn about conditional expressions

More information

CS Programming I: Arrays

CS Programming I: Arrays CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc. Week 1: Introduction to C++ Gaddis: Chapter 2 (excluding 2.1, 2.11, 2.14) CS 1428 Fall 2014 Jill Seaman Literals A literal represents a constant value used in a program statement. Numbers: 0, 34, 3.14159,

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

ECSE 321 Assignment 2

ECSE 321 Assignment 2 ECSE 321 Assignment 2 Instructions: This assignment is worth a total of 40 marks. The assignment is due by noon (12pm) on Friday, April 5th 2013. The preferred method of submission is to submit a written

More information

Chapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007

Chapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007 Chapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007 Abstract This lecture presents language technicalities, mostly related to user defined types;

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

Flashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser

Flashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser Flashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2013/csc1254.html Overview Classes Implementation and interface Constructors Member

More information

Chapter 9 Technicalities: Classes, etc.

Chapter 9 Technicalities: Classes, etc. Chapter 9 Technicalities: Classes, etc. Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/spring_2011/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice

More information

1. In C++, reserved words are the same as predefined identifiers. a. True

1. In C++, reserved words are the same as predefined identifiers. a. True C++ Programming From Problem Analysis to Program Design 8th Edition Malik TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/c-programming-problem-analysis-program-design-8thedition-malik-test-bank/

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011

More information

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1 INFORMATION TECHNOLOGY SPREADSHEETS Part 1 Page: 1 Created by John Martin Exercise Built-In Lists 1. Start Excel Spreadsheet 2. In cell B1 enter Mon 3. In cell C1 enter Tue 4. Select cell C1 5. At the

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5 1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is

More information

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2 Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2 Ziad Matni Dept. of Computer Science, UCSB Administrative This class is currently FULL and

More information

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

Introduction to C# Applications Pearson Education, Inc. All rights reserved. 1 3 Introduction to C# Applications 2 What s in a name? That which we call a rose by any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the

More information

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Arrays III and Enumerated Types

Arrays III and Enumerated Types Lecture 15 Arrays III and Enumerated Types Multidimensional Arrays & enums CptS 121 Summer 2016 Armen Abnousi Multidimensional Arrays So far we have worked with arrays with one dimension. Single dimensional

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012 TOPICS TODAY Characters & Strings in C Structures in C CHARACTERS & STRINGS char type C supports the char data type

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

Values & Variables 1

Values & Variables 1 Values & Variables 1 Properties of variables Should have a type Stores data Case sensitive Their names can not start with a number Reserved keywords can not be used as variable names 2 Keywords 3 How to

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

Chapter 2: Overview of C++

Chapter 2: Overview of C++ Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in

More information

EP241 Computer Programming

EP241 Computer Programming EP241 Computer Programming Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department of Electric and Electronics Engineering Sep

More information

Chapter 9 Technicalities: Classes

Chapter 9 Technicalities: Classes Chapter 9 Technicalities: Classes Bjarne Stroustrup www.stroustrup.com/programming Abstract This lecture presents language technicalities, mostly related to user defined types; that is, classes and enumerations.

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 TYPES TYPES Programs have to store and process different kinds of data, such as integers and floating-point numbers, in different ways. To this end, the compiler needs to

More information

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter-8 DATA TYPES. Introduction. Variable: Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

Chapter 9 Technicalities: Classes, etc.

Chapter 9 Technicalities: Classes, etc. Chapter 9 Technicalities: Classes, etc. Dr. Hyunyoung Lee Based on slides by Dr. Bjarne Stroustrup www.stroustrup.com/programming Abstract This lecture presents language technicalities, mostly related

More information

Operator overloading: extra examples

Operator overloading: extra examples Operator overloading: extra examples CS319: Scientific Computing (with C++) Niall Madden Week 8: some extra examples, to supplement what was covered in class 1 Eg 1: Points in the (x, y)-plane Overloading

More information

High Performance Computing

High Performance Computing High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control

More information

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Java enum, casts, and others (Select portions of Chapters 4 & 5) Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Lecture 10: Boolean Expressions

Lecture 10: Boolean Expressions Lecture 10: Boolean Expressions CS1068+ Introductory Programming in Python Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/10/17) Lecture 10: Boolean Expressions

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types. Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

More information

Section 1.2: What is a Function? y = 4x

Section 1.2: What is a Function? y = 4x Section 1.2: What is a Function? y = 4x y is the dependent variable because it depends on what x is. x is the independent variable because any value can be chosen to replace x. Domain: a set of values

More information

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long Primitive Types Four integer types: byte short int (most common) long Two floating-point types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

EP578 Computing for Physicists

EP578 Computing for Physicists EP578 Computing for Physicists Topic 2 C++ Basis Department of Engineering Physics University of Gaziantep Course web page www.gantep.edu.tr/~bingul/ep578 Sep 2011 Sayfa 1 1. Introduction In this lecture

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110. Lecture 2 Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

More information

Adobe EchoSign Calculated Fields Guide

Adobe EchoSign Calculated Fields Guide Adobe EchoSign Calculated Fields Guide Version 1.0 Last Updated: May, 2013 Table of Contents Table of Contents... 2 Overview... 3 Calculated Fields Use-Cases... 3 Calculated Fields Basics... 3 Calculated

More information

CS349/SE382 A1 C Programming Tutorial

CS349/SE382 A1 C Programming Tutorial CS349/SE382 A1 C Programming Tutorial Erin Lester January 2005 Outline Comments Variable Declarations Objects Dynamic Memory Boolean Type structs, enums and unions Other Differences The Event Loop Comments

More information

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18 Enum and Struct Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously

More information

The DDE Server plugin PRINTED MANUAL

The DDE Server plugin PRINTED MANUAL The DDE Server plugin PRINTED MANUAL DDE Server plugin All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or mechanical, including photocopying,

More information

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 7. dr inż. Małgorzata Janik Advanced Programming C# Lecture 7 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 C#: classes & objects 3 / 39 Class members Constructors Destructors Fields Methods Properties Indexers

More information