Welcome to Computer Programming II! Computer Programming II Summer 2015.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 2: Introduction to C++.
C++ for Engineers and Scientists Third Edition
5.05 Apply Looping Structures
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
CS0004: Introduction to Programming Variables – Numbers.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Applications Development
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
Murach, Chapter 4. Two Data Types Value Types – Store their own data Reference Types Do not store their own data Stores a reference to an area of memory.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
5.04 Apply Decision Making Structures
IE 8580 Module 4: DIY Monte Carlo Simulation
Chapter 2 Variables.
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Basic Computation
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Visual Basic 6 (VB6) Data Types, And Operators
Debugging and Random Numbers
Computer Programming I
Single Dimensional Arrays
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
2. Understanding VB Variables
Variables, Printing and if-statements
Understand Variables and Naming Conventions
Arrays, For loop While loop Do while loop
IDENTIFIERS CSC 111.
Chapter 6 Variables What is VBScript?
2.1 Parts of a C++ Program.
Numbers.
Chapter 1: Computer Systems
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
PHP.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
C++ Data Types Data Type
Chapter 2: Introduction to C++.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chap 2. Identifiers, Keywords, and Types
Chapter 2 Variables.
Variables and Constants
Looping and Repetition
Presentation transcript:

Welcome to Computer Programming II! Computer Programming II Summer 2015

Purpose Computer Programming II has been completely redesigned to better align with real world uses of the C# language outside of gaming. The course will use C#. This language is very similar and based on the C language. This PowerPoint will begin to cover differences between Visual Basic and C- based languages.

Essential Standard Understand variable declaration and syntax  This PowerPoint Loop and If Statements Random Numbers Software Design Life Cycle & Types of Errors

Moving to C# from Visual Basic This PowerPoint reviews variables, decision making statements, arrays, and methods (sub procedures). Major differences between C# and VB are also covered. C# is very different from VB in one KEY way. All statements MUST end with a semicolon (;). If you forget this, your code will not work. Exceptions: IF statements and loops The upside to this is two-fold: 1. Multiple coding statements may be on the same line 2. A long code segment can be spilt up without having to use an underscore like in VB.

Spacing C# Examples int intAge; string strName; Two different statements- same line Long line of code: string query whatever FROM tableName WHERE column = 1"; Both are perfectly valid statements in C#.

Semicolon Exceptions Two exceptions to the semicolon rule: if(x==b)  no semicolon here It is a “clause” - only part of the statement { y=7;  semicolon as normal } while(x< i)  no semicolon here either – again it is a “clause” { intGradeTotal=intGrade;  semicolon as normal }

Declaring a Variable In VB we use the Dim keyword to declare a variable: Dim intAge as Integer C# handles this differently: int intAge; In C# use the following format: DataType variableName; All types are spelled out except integer (int), character (char), and boolean (bool)

C# Examples string strName; char charGrade; int intAge; double dblTaxRate;

Data Types Data TypeStorageValue Range Integer (int)4 Bytes-2,147,483,648 to 2,147,483,647 Double8 Bytes1.7E +/- 308 (15 digits) Decimal16 Bytes1.7E +/- 308 (15 digits) Char1 Byte–128 to 127 by default Boolean (bool)1 ByteTrue or False StringVaries0 to approximately 2 billion Unicode characters

Default Value It is a syntax error in C# to declare a variable then use it before giving it a value. In VB a default value of 0 for a number variable or null for a string is assumed. Example: int intAge = 0; intTotal= intAge + 5;  valid because intAge is given the value of 0 before being used below int intAge; intTotal = intAge + 5;  syntax error because no value was given before it was used

Static and Const In Visual Basic if we wanted a variable to hold its value we used the static keyword in place of Dim. Static works differently in C#. Local variables cannot be declared as static in C#. Const works the same as it does in VB. Using Const a variable’s value cannot be changed once assigned. Example: const double TAXRate = 0.675; (C#) Example: Const TAXRate As Double = (VB)

Coding Blocks In VB we use the End keyword to end coding blocks like IF statements or loops. If a = b Then b=c End If In C#, we use braces so this code block would be written: if(a==b) { b=c; }

Equality Check (==) You might have noticed something on the last slide- a == in the if statement. In VB the assignment operator and equality are the same (=). This is NOT true in C#. The equals sign is solely used for assignment. To check for equality you must use ==. Using = in an if statement to check for equality is a logic error. The code will run properly, but not produce the intended result. (It will always be false.)

Increment Counters In VB to add one to a counter we use varName += 1, for two we use +=2 and so on. (i+=1) This shorthand works in C# as well, but C# provides an additional way to add or subtract one from a counter. i++; i--; ++ adds 1 to the value of i while -- subtracts one. Remember the semicolon is required. To count by 2, or another number, we use the same shorthand as in VB (i+=2).

Try/Catch Try/Catch was used for error checking (exception handling) extensively in VB and is also used in C#, but the format is different. Example: try { Code to try } catch { Code to run if try code fails }

try/catch/finally try { Code to try } catch { Code to run if try code fails } finally { Code to run regardless if the try was successful or not. }

Arrays In VB we use ( ) in array statements. In C# [ ] are used instead. Dim intArray = New Integer(4) {1, 2, 3, 4, 5} (VB) int[] intArray = new int[5] {1,2,3,4,5}; (C#) In VB we put in 1 less than the number of elements we want in the array. This is NOT the case in C#. If we want five elements we use a 5 as shown above. Arrays are still index-based starting at 0.

Conclusion of Part I In this PowerPoint we looked at some differences between C# and Visual Basic. In the next part we will take a look at methods in C#. In the next lesson we will continue our look at differences by looking at loops and if statements.