Welcome to Visual Programming using C# What the Course is About
Course info Instructor: Yrd. Doç. Dr. Cengiz Örencik E-mail: cengizorencik@beykent.edu.tr Course material http://myweb.sabanciuniv.edu/cengizo/courses all the notes / codes will be shared there
Book Not required You may use any programming book on C# Microsoft Visual C# .NET step by step John Sharp and Jon Jagger
Grading Midterm 30% Inclass quizes (2) 20% (10+10) Final 50% Hws Mostly coding Self study Not be graded
Aims to learn Developing an algorithmic way of thinking The nature of object oriented programming Operators, precedence Class, objects, methods etc. Building big programs using small ones. Test/debug Inheritance, polymorphism …. GUI design Toolbox and control properties Event driven programming Exception handling
Tentative Outline Classes (constructor, properties, access/modify) Methods (overloading, pass by reference, scope of variables…) Introduction to visual programming (textbox, buttons, checkbox, radiobuton, timer…) Control statements (if-else, switch, while, for, do-while) Arrays, strings (sorting, searching) Recursion Inheritance and Polymorphism Generics (type independent) Exception handling Files and streams
Getting started You will need an integrated development environment (IDE) Download Visual Studio Community 2015 https://catalog.imagine.microsoft.com/en-us/catalog If you already have a running visual studio you may go on with it, they are more or less the same If you prefer an open source IDE, you may use SharpDevelop Almost the same interface with visual studio http://www.icsharpcode.net/OpenSource/SD/Download/
Add 3 Number Lets do it from scratch First as console application Next as Visual Read input/write output
Data Types Char String Bool For single character Digits, letters, symbols… One byte (8 bit) Can store 28 = 256 different values String Any set of chars (words, sentences) Can be arbitrarily long More tecnically, string is a class Bool True / false
Numeric Types int (short / long) signed versus unsigned integers integer numbers no infinity in computers limited range 4 bytes (32 bits) integer range: –2,147,483,648 ... 2,147,483,647 for 32-bit computers why? signed versus unsigned integers you can put signed or unsigned keywords before the type unsigned integers use the same amount of bits but ranges are different 32-bit: 0 ... 4,294,967,295 (232 –1) Double 8 bytes (64 bits) 3.14159 -2.5 5.43e21
Arithmetic Operations Mixed type expressions what if one operator is int other is double? integer is converted into double before operation 5.0 * 8 is 40.0 5 / 10 is 0 (integer division) 5.0 / 10 is 0.5 (real division) 10 – 8 is 2 (integer) 10 – 8.0 is 2.0 (double)
Expressions with several operators You can use parentheses in expressions to group them Open ( and close ) parentheses should match Rule 1: Parenthesized sub-expressions are evaluated first inside to out Rule 2: Within an expression/subexpression if there are several operators, use operator precedence, evaluate * / % before + - Rule 3: If the operators are in the same expression/subexpression and at the same precedence level, then associativity rule applies evaluate operators from left-to-right Examples (5 - 3 * (7 - 3)) * 8 is -56 10 / 2 * 6 / 2 + (5 - 3 * (2 - 1)) is 17
Expressions with several operators Are the following expressions equivalent? (40 – 32) * 5 / 9 (40 – 32) * (5 / 9) NO, first one is 4, second one is 0 What about this? (40 – 32.0) * 5 / 9 Operations are double operations. Result is 4.44444 See the example Arithmeticoperations – console circleArea – Windows