CS313D: ADVANCED PROGRAMMING LANGUAGE

Similar documents
CS111: PROGRAMMING LANGUAGE II

CS110: PROGRAMMING LANGUAGE I

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

ECE 122 Engineering Problem Solving with Java

Visual C# Instructor s Manual Table of Contents

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Chapter 2: Using Data

CS313D: ADVANCED PROGRAMMING LANGUAGE

Declaration and Memory

CSCI 1061U Programming Workshop 2. C++ Basics

More Programming Constructs -- Introduction

COMP Primitive and Class Types. Yi Hong May 14, 2015

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Eng. Mohammed S. Abdualal

Java Primer 1: Types, Classes and Operators

Introduction to Programming Using Java (98-388)

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Operators. Java operators are classified into three categories:

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Chapter 2: Using Data

Program Elements -- Introduction

3. Java - Language Constructs I

Values, Variables, Types & Arithmetic Expressions. Agenda

LECTURE 3 C++ Basics Part 2

Program Fundamentals

Data Conversion & Scanner Class

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

Chapter 2: Data and Expressions

A variable is a name for a location in memory A variable must be declared

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

COMP 202 Java in one week

This watermark does not appear in the registered version - Slide 1

Reserved Words and Identifiers

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

Chapter 2. Elementary Programming

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Chapter 2: Data and Expressions

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Basics of Java Programming

CSI33 Data Structures

CIS 110: Introduction to Computer Programming

Java Fall 2018 Margaret Reid-Miller

Programming with Java

Full file at

Chapter 2: Data and Expressions

Chapter 2 Elementary Programming

Operators in C. Staff Incharge: S.Sasirekha

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

Operators in java Operator operands.

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

JAVA OPERATORS GENERAL

Values and Variables 1 / 30

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Simple Java Reference

Java Notes. 10th ICSE. Saravanan Ganesh

Programming with C++ as a Second Language

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

These are reserved words of the C language. For example int, float, if, else, for, while etc.

CSC 1214: Object-Oriented Programming

Zheng-Liang Lu Java Programming 45 / 79

Chapter. Let's explore some other fundamental programming concepts

UNIT- 3 Introduction to C++

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

SECTION II: LANGUAGE BASICS

Full file at

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

Chapter 2: Basic Elements of C++

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

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

CEN 414 Java Programming

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Data Types and Variables in C language

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

COMP 202 Java in one week

Unit 3. Operators. School of Science and Technology INTRODUCTION

CT 229. Java Syntax 26/09/2006 CT229

AP Computer Science A

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

COMP 202. Java in one week

Computer System and programming in C

Lecture 3 Tao Wang 1

Operators and Expressions

Programming in C++ 5. Integral data types

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

CMPT 125: Lecture 3 Data and Expressions

Chapter 7. Expressions and Assignment Statements ISBN

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Fundamental of Programming (C)

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Programming. C++ Basics

Introduction to C# Applications

A flow chart is a graphical or symbolic representation of a process.

Transcription:

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics

Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting Control structures Conditions Branching loops

First Program 3 comments A class name is an identifier Series of letters, digits and ( _ ), cannot begin with a digit, and does not contain spaces.

variables 4 Every variable has a name, a type, a size and a value. data type variable name int total = 0; // Initialization int count, temp, result; Multiple variables can be created in one declaration

5

Standard Input 6 input is received from Terminal window. Input entered while program is executing. The Console s ReadLine method waits for the user to type a string of characters at the keyboard and press the Enter key. Console.ReadLine()returns the text the user entered. Use appropriate methods to converts this sequence of characters into a certain data of type

Example 7

Arithmetic Expressions 8 An expression is a combination of operators and operands Arithmetic expressions special methods applied to numerical data objects. They compute numeric results and make use of the arithmetic operators: Addition + Subtraction - Multiplication * Division / Remainder %

9 Expressions The remainder operator is most commonly used with integer operands but can also be used with floats, doubles, and decimals.

Operator precedence 10

Assignment-related Operators 11 Increment and decrement operators: ++, -- Assignment operators: +=, -=, *=, /= these three expressions have the same effect count = count + 1; count += 1; count ++; these two expressions have the same effect count = count - 10; count -= 10;

12

Constants 13 A constant variable is an identifier that is similar to a variable except that it holds one value for its entire existence Why constants: give names to otherwise unclear literal values facilitate changes to the code prevent inadvertent errors In C#: const double PI = 3.14159265;

String 14 Represents text as a series of Unicode characters. The String class provides many methods for safely creating, manipulating, and comparing strings.

15 String concatenation

How Do Data Conversions Happen? 16 Explicitly: Casting widening / narrowing conversions Examples: double MyResult; MyResult = 12.0 / 5.0; //OK int myint = (int) MyResult; // truncation MyResult = (double)myint/3.0;

17 Control Structures

Relational operators 18

Logical Operators 19

Conditional Statements 20 A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic decisions Java's conditional statements: the if and if-else statements the conditional operator the switch statement

condition evaluated true false Statement 1 Statement 2 21 Logic of an if-else statement Several statements can be grouped together into a block statement A block is delimited by braces ( { } )

The if Statement 22 The if statement has the following syntax: if is a C# reserved word The condition must be a boolean expression. e.g., a boolean variable, a == b, a <= b. It must evaluate to either true or false. if ( condition ) statement1; else statement2; If the condition is false, this statement is executed. If the condition is true, this statement is executed.

Conditional Operator 23 Also called "ternary operator" Allows embedded conditional in expression Essentially "shorthand if-else" operator Example: if (n1 > n2) max = n1; else max = n2; Can be written: max = (n1 > n2)? n1 : n2; "?" and ":" form this "ternary" operator

switch 24 multipleselection statement a constant integral expression of type: byte, short, int or char. case labels break statement optional default case

25 loops Chapters 5 & 6

26 while loops while ( condition ) statement;

Example 27

28 do loops do { statement; } while ( condition );

Example 29

30 for loops for ( initialization ; condition ; increment ) statement;

Example 31

break and Continue 32 break; Forces loop to exit immediately. Execution continues with the first statement after the control statement. continue; Skips rest of loop body In while and do while statements, the program evaluates the loop-continuation test immediately after the continue statement executes. In a for statement, the increment expression executes, then the program evaluates the loop-continuation test.

33 That s all Chapter 3: 3.6 3.9 Chapter 5 Chapter 6

34 Case Studies

Q1: 35

Q2: 36

Q3: 37

Q4: 38