C# Language Object-oriented Programming Basics

Size: px
Start display at page:

Download "C# Language Object-oriented Programming Basics"

Transcription

1 C# Language Object-oriented Programming Basics O 2 DES.NET Object-oriented Simulation and Optimization Algorithm (1) 2017 Li Haobin, ISEM Department,NUS 1

2 Syllabus 1. C# Language Object-oriented Programming Basics 2. O 2 DES.NET Discrete Event Simulation Modelling 3. System Decomposition and Modular Modelling 4. Mathematical Programming and Embedded Optimization Simulation 5. Simulation-based Search Optimization 6. Optimal Hash-rate Allocation and Parallel Computing 7. XML Data Storage and Graphical Presentation 2017 Li Haobin, ISEM Department,NUS 2

3 Why Programming? Experiment Tool Theoretical Science axiom assumption - > lemma - > theorem - > corollary Experimental Science Experimental science is science based on experimental research that plays the role of testing hypothesis, typically in controlled laboratory settings Li Haobin, ISEM Department,NUS 3

4 Why Programming? Knowledge Accumulation Thesis Source Code Research motivation Literature review Method discussion Introduction of achievements Study result deliverable Can be duplicated Can be applied Can be accumulated 2017 Li Haobin, ISEM Department,NUS 4

5 Why Programming? Technology Transformation Research Results Commercial Products Method Algorithm Framework Procedure Software System 2017 Li Haobin, ISEM Department,NUS 5

6 Why Object-oriented? Object-oriented Task model What to do? Linear thinking Input-> Output Object-oriented System Model What is it? Reticular thinking Entity Relationship Object-oriented Discrete event Model O 2 DES.NET 2017 Li Haobin, ISEM Department,NUS 6

7 Why using C#? Strongly-typed language, neat grammar and clear structure Inherit and develop advanced languages such as C++, JAVA, Pascal Compatible with collaborative development of complex system and avoid program error Strong reliability Abundant resources in standard library Maintenance and guarantee from commercial company Strong extensibility Derived from windows system, various application scenarios and peripheral devices, leading to wide applicability.net Core can be used for cross-platform development Development environment is powerful yet easy to use IntelliSense, auto code completion, indent function to help the development process 2017 Li Haobin, ISEM Department,NUS 7

8 C# Language Object-oriented Programming Basics 1. Main Data Types 2. Standard Data Structure 3. Input and Output Methods 4. Loop Structure 5. Conditional Structure 6. Function Method 7. Lambda Expression 8. LINQ Search C# only Basic Grammar 2017 Li Haobin, ISEM Department,NUS 8

9 C# Language Object-oriented Programming Basics 9. Encapsulation 10. Inheritance 11. Polymorphism 12. Interface OOP Basic Concept 1.13 Example: 24 Point Intellectual Program 2017 Li Haobin, ISEM Department,NUS 9

10 Basic Grammar 2017 Li Haobin, ISEM Department,NUS 10

11 1.1 Basic Data Type C# Key Words System Type Numerical Range Description Default Value bool System.Boolean true or f a lse Represents truth or falsity f a l se sbyte System.SByte -128 to 127 Signed 8-bit number 0 byte System.Byte 0 to 255 Unsigned 8-bit number 0 sh o rt System.Int16-32,768 to 32,767 Signed 16-bit number 0 ushort System.UInt16 0 to 65,535 Unsigned 16-bit number 0 i n t System.Int32-2,147,483,648 t o 2,147,483,647 Signed 32-bit number 0 u i n t System.UInt32 0 to 4,294,967,295 Unsigned 32-bit number 0 long System.Int64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Signed 64-bit number 0 ulong System.UInt64 0 to 18,446,744,073,709,551,615 Unsigned 64-bit number 0 char System.Char U+0000 to U + f f f f Single 16-bit Unicode character \0 f l o a t System.Single t o bit floating-pointnumber 0.0 double System.Double ± t o ± bit floating-pointnumber 0.0 decimal System.Decimal ( x t o 7.9 x )/(10 0 to 28 ) 128-bit signednumber 0 s t r i n g System.String Limited by system memory Represents a set of Unicode characters "" object System.Object Can store any data type i n an object variable The base class of all types in the.net universe n u l l 2017 Li Haobin, ISEM Department,NUS 11

12 1.1 Basic Data Type Enumeration Type: a data type consisting of a set of named values called elements, members, enumerals, or enumerators of the type. p u b l i c class EnumTest enum Days Sun, Mon, Tue, Wed, Thu, F r i, Sat ; static void Main() i n t x = (int)days.sun; i nt y=( int)days.fri; Console.WriteLine("Sun = 0", x ) ; Console.WriteLine("Fri =0", y ) ; /* Output: Sun = 0 Fri = 5 */ 2017 Li Haobin, ISEM Department,NUS 12

13 1.1 Basic Data Type n u l l Type: represents that no value is assigned static void M a in(string[] args) // Compiler e r r o r s! // Value types cannot be set t o n u l l! bool mybool = n u l l ; int myint = n u l l ; // Define some local nullable variables. int? n u l l a b l e I n t = 10; double? nullabledouble = 3.14; bool? nullablebool = n u l l ; char? nullablechar = 'a'; int?[] arrayofnullableints = new i n t? [ 1 0 ] ; // E r r o r! Strings are reference types! string? s = "oops"; Equivalent to // OK! Strings are reference types. s t r i n g mystring = n u l l ; // Define some local nullable types using Nullable<T>. Nullable<int> n u l l a b l e I n t = 10; Nullable<double> nullabledouble = 3.14; Nullable<bool> nullablebool = n u l l ; Nullable<char> nullablechar = ' a ' ; Nullable<int>[] arrayofnullableints = New Nullable<int>[10]; 2017 Li Haobin, ISEM Department,NUS 13

14 1.1 Basic Data Type System Type System.DateTime System.TimeSpan Description Represents a point of time, usually represents as date and time of day Represents a time interval Instantiation: Time Computation : DateTime date1 = new DateTime(2008, 3, 1, 7, 0, 0 ) ; Console.Writ eli ne(date 1.ToS tri ng()); // For en-us culture, displays 3/1/2008 7:00:00 AM DateTime departure = new DateTime(2010, 6, 12, 18, 32, 0); DateTime a r r i v a l = new DateTime(2010, 6, 13, 22, 47, 0 ) ; TimeSpan traveltime = a r r i v a l - departure; Console.WriteLine("0 - traveltime); 1 = 2", a r r i v a l, departure, // The example displays the f ollowing output: // 6/13/ :47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15: Li Haobin, ISEM Department,NUS 14

15 1.2 Standard Data Structure: Array System Type System.Array Description Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime. Create and use an array: // Create and f i l l an array of 4 Integers int[] myints = new int[4]; myints[0] = 100; myints[1] = 200; myints[2] = 300; myints[3] = 400; // Now print each value. foreach ( int i in myints) Console.WriteLine(i); Console.WriteLine(); myints Initialization grammar: // Array initialization syntax using the new keyword. s t r i n g [] stringarray = new s t r i n g [ ] "one", "two", "three" ; Console.WriteLine("stringArray has 0 elements", stringarray.length); // Array initialization syntax without using the new keyword. bool[] boolarray = f a l s e, f a l s e, true ; Console.WriteLine("boolArray has 0 elements", boolarray.length); // Array initialization with new keyword and s ize. int[] intarray = new int[4] 20, 22, 23, 0 ; Console.WriteLine("intArray has 0 elements", intarray.length); Console.WriteLine(); Fixed size, fast and direct access based on index 2017 Li Haobin, ISEM Department,NUS 15

16 1.2 Standard Data Structure: List System Type System.Collections. Generic.List<T> Description Represents a strongly-typed list of an object that can be accessed by index. Provide methods for searching, sorting and manipulating lists. Create and use a list: Other common operations: // Create and f i l l a list of 4 Integers List<int> myints = new L i s t < i n t > ( ) ; myints.add(100); myints.add(200); myints.add(300); myints.add(400); // Now print each value. foreach ( int i in myints) Console.WriteLine(i); Console.WriteLine(); myints 0 // Add element to the end of the list myints.addrange(new List<int> 500, 600, 700 ); // Insert element into the specific index of List<T> myints.insert(2, 800); // Remove element from the specific index of List<T> myints.removeat(3); Unfixed size, flexible to add or remove elements 2017 Li Haobin, ISEM Department,NUS 16

17 1.2 Standard Data Structure:Queue and Stack System Type System.Collections.Queue<T> System.Collections.Generic.Stack<T> Queue Example: Description Represents a collection of first-in-first-out (FIFO) objects. Represents a collection of last-in-first-out (LIFO) objects that have variable size (Instantiation for the same specified type). Stack Example: // Creates and initializes a new Queue. Queue<int> myq = new Queue<int>(); myq.enqueue(100); myq.enqueue(200); myq.enqueue(300); // Displays the properties and values of the Queue. Console.WriteLine(myQ.Count); Console.WriteLine(myQ.Dequeue()); Console.WriteLine(myQ.Dequeue()); Console.WriteLine(myQ.Dequeue()); myq // Creates and initializes a new Stack. Stack<int> mystack = new Stack<int>(); mystack.push(100); mystack.push(200); mystack.push(300); // Displays the properties and values of the Stack. Console.WriteLine(myStack.Count); Console.WriteLine(myStack.Pop()); Console.WriteLine(myStack.Pop()); Console.WriteLine(myStack.Pop()); mystack Li Haobin, ISEM Department,NUS Unfixed size, fixed access mode 17

18 1.2 Standard Data Structure: Hash Set System Type System.Collections.Generic.HashSet<T> Description Represents a collection of values. Hash Set Example: // Creates and initializes a new hash set. HashSet<int> myset = new HashSet<int>(); myset.add(1); myset.add(3); myset.add(5); // Displays the properties and query the values of the hash set. Console.WriteLine(mySet.Count); Console.WriteLine(mySet.Contains(5)); Console.WriteLine(mySet.Contains(7)); 1 Fast adding, sorting and removing based on given values Li Haobin, ISEM Department,NUS 18

19 1.2 Standard Data Structure: Dictionary System Type System.Collections.Generic. Dictionary<Tkey,TValue> Description Represents a collection of keys and values. Dictionary Example: // Creates and initializes a new dictionary. Dictionary<string, string> mydict = new Dictionary<string, s t r i n g > ( ) ; mydict.add("1", "H"); mydict.add("3", "A"); mydict.add("5", "S"); // Displays the properties and query the values of the dictionary. Console.WriteLine(myDict.Count); Console.WriteLine(myDict.ContainsKey("5")); Console.WriteLine(myDict["3"]); Fast adding, sorting and removing based on given values H A D S 7 C 2017 Li Haobin, ISEM Department,NUS 19

20 1.2 Standard Data Structure: Tuple System Type System.Tuple Description Provides a static method of creating tuple objects. Tuple Example: // Create a 7 - tuple. var population = new T u p l e < s t r i n g, i n t, i n t, i n t, i n t, i n t, int> ( "New Y o r k ", , , , , , ); // Display the first and l a s t elements. Console.WriteLine("Population of 0 in 2000: 1:N0", p o pulation.item1, p o p u l a t i o n. I t e m 7 ) ; // The example d i s p l ays the f o l l o w i n g o u t p u t : // Population of New York in 2000: 8,008,278 Represents a data combination 2017 Li Haobin, ISEM Department,NUS 20

21 1.3 Input and Output Method Console Operation (Example) Console.Clear(); // prompt to key in the value of a Console.Write("Input: a = " ); double a = Convert.ToDouble(Console.ReadLine()); // prompt to key in the value of a Console.Write("Input: b = " ); double b = Convert.ToDouble(Console.ReadLine()); // prompt to press any key to continue Console.Write("Press any key to continue...") ; Console.ReadKey(); // Output the result Console.WriteLine("a + b = 0", a + b); 2017 Li Haobin, ISEM Department,NUS 21

22 1.3 Input and Output Method File Operations (Example) using System.IO; // Method to write to files using (StreamWriter sw = new StreamWriter(" f i l e. t x t " )) sw.writeline("hello W o r l d! " ) ; sw.writeline("welcome to C#!!"); // An easier method to read files foreach ( string line in F i l e. R e a d A l l L i n e s ( " f i l e. t x t " )) C o n s ole.writeline(line); // Method to read files by row using (StreamReader sr = new S t r e a m R e a d e r ( " f i l e. t x t " )) string line1 = sr.readline(); string line2 = sr.readline(); Console.WriteLine(line2); Console.WriteLine(line1); 2017 Li Haobin, ISEM Department,NUS 22

23 1.4 Loop Structure 4 different loops / / For loop f o r ( int i = 0; i < 10; i + + ) C o n s o l e. W r i t e L i n e ( i ) ; / / For Each loop / / While loop int i = 0 ; w h i l e ( i < 10) Consol e. Wr i t eli ne( i ); i++; / / Do-While loop int i = 0; do i n t [ ] arr = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; foreach ( int i in arr) C o n s o l e. W r i t e L i n e ( i ) ; i++; C o n s o l e. W r i t e L i n e ( i ) ; while ( i < 10); 2017 Li Haobin, ISEM Department,NUS 23

24 1.4 Loop Structure Nested-Loop f o r ( int i = 0; i < 5; i + + ) for ( int j = 0; j < i ; j + + ) C o n s o l e. W r i t e L i n e ( " = 2", i, j, i + j); 2017 Li Haobin, ISEM Department,NUS 24

25 Practice One: Use loop structure to output the pattern below in the console * * * **** * * ** ****** *** *** *** ****** ***** ***** **** ****** ******* ******* ***** ****** ********* ***** ****** ****** *********** *** ******* ****** ************* * H i n t : M a t h. A b s ( x ) c a n b e u s e d t o c o m p u t e t h e a b s o l u t e v a l u e o f x Source code: Li Haobin, ISEM Department,NUS 25

26 1.5 Condition Structure // If condition int m = 12; i n t n = 18; if (m > 10) if (n > 20) Console.Wr iteline( "Result1 " ); else if (n > 15) Console.Wr iteline( "Result2 " ); else Console.WriteLine("Result3"); // Switch condition int caseswitch = 1; switch (caseswitch) case 1: Console.WriteLine("Case 1"); break; case 2: Console.WriteLine("Case 2"); break; case 3: Console.WriteLine("Case 3"); break; default: Console.WriteLine("Default c a s e " ); break; 2017 Li Haobin, ISEM Department,NUS 26

27 1.6 Function Method Realize the reuse of code Convenient for code management Differentiate between valuepassing and reference-passing Understand method overloading static void M a i n ( s t r i n g [] args) int a = 3, b = 4; Console.WriteLine( "0 1 2 ", Add(a, b ), a, b); Console.WriteLine( "0 1 2 ", Add(ref a, ref b ), a, b ) ; // Passing Values static int Add(int c, int d) c = c + 1; d = d + 2; return c + d; // Passing References static int Add(ref int c, r e f int d) c = c + 1; d = d + 2; return c + d; 2017 Li Haobin, ISEM Department,NUS 27

28 1.7 Lambda Expression A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. A lambda expression is the most convenient way to create that delegate. int a = 3, b = 4; Func<int, i n t, int> func = c = c + 1; d = d + 2; return c + d; ( c, d) => ; //Func< int, int, int> func = (c, d) => c + d ; Console.WriteLine ("0 1 2 ", func(a, b), a, b ) ; //simple form 2017 Li Haobin, ISEM Department,NUS 28

29 1.8 LINQ Language-Integrated Query Language-Integrated Query i n t [] myints = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; i n t [] arr1 = myints.select(x => x * x ). T o A r r a y ( ) ; // 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 i n t [] arr2 = myints.where(x => x > 5).ToArray(); // 6, 7, 8, 9, 10 i n t [] arr3 = myints.orderby(x => x % 3).ThenBy(x => x).toarray(); // 3, 6, 9, 1, 4, 7, 10, 2, 5, 8 i n t [] arr4 = myints.except(new i n t [] 3, 4, 5 ). T o A r r a y ( ) ; // 1, 2, 6, 7, 8, 9, 10 i n t [] arr5 = myints.concat(new i n t [] 10, 11, 12 ). T o A r r a y ( ) ; / /..., 6, 7, 8, 9, 10, 10, 11, 12 i n t [] arr6 = myints.take(6).toarray(); // 1, 2, 3, 4, 5, 6 i n t [] arr7 = Enumerable.Range(1, 1 0 ). T o A r r a y ( ) ; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 i n t [] arr8 = Enumerable.Repeat(1, 1 0 ). T o A r r a y ( ) ; // 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 i n t [] arr9 = arr5.distinct().toarray(); // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, Li Haobin, ISEM Department,NUS 29

30 1.8 LINQ Language-Integrated Query Language-Integrated Query int agg1 = myints.max(); // 10 int agg2 = myints.min(); // 1 int agg3 = myints.sum(); // 55 double agg4 = myints.average(); // 5.5 int agg5 = myints.aggregate(1, ( i, j) => i * 2 + j ) ; // 3060 int agg6 = m y I n t s. F i r s t ( ) ; / / F i r s t O r D e f a u l t ( ) ; // 1 int agg7 = m y I n t s. L a s t ( ) ; / / L a s t O r D e f a u l t ( ) ; // Li Haobin, ISEM Department,NUS 30

31 Object-oriented Programming (OOP) 2017 Li Haobin, ISEM Department,NUS 31

32 1.9 Encapsulation Encapsulation describes the idea of grouping data and associated functionalities into a single package and hiding internal details from outsider. The two terms Class and Object are sometimes interchangeable in use; however, class is the type of the described object while object is the available instance of a class. As such, the operation of creating objects is called instantiation Li Haobin, ISEM Department,NUS 32

33 1.9 Encapsulation Properties and Fields Properties and fields: describes the information contained in the object Fields are similar to variables, as it can be accessed or set up directly Properties can be get or set, and provide more control on setting and returning values p u b l i c class SampleClass p r i v a t e i n t _sample; p u b l i c i n t Sample // Return the value stored in a field. get return _sample; // Store the value in the field. s e t _sample = v a l u e ; public class SampleClass p u b l i c i n t Sample g e t ; set; 2017 Li Haobin, ISEM Department,NUS 33

34 1.9 Encapsulation - Methods Methods are possible operations to be made on objects For the same method, there can be various implementations for a class, this is also called override ; the difference between implementations is due to difference in number of parameters and parameter types. public class SampleClass public int SampleProperty get; set; public i n t SampleMethod(string sampleparam) return sampleparam.length; public i n t SampleMethod(int sampleparam) r e t u r n sampleparam + 1; 2017 Li Haobin, ISEM Department,NUS 34

35 1.9 Encapsulation Modifier All classes and class methods can use modifiers to provide different level of accessibilities. These are the different modifiers: C# modifier Definition (Who can access) public private protected internal protected internal private protected Any code. No inheritance, external type, or external assembly restrictions Only members within the same type. (default for type members) Only derived types or members of the same type Only code within the same assembly. Can also be code external to object as long as it is in the same assembly. (default for types) Either code from derived type or code in the same assembly. Combination of protected or internal The containing class or types derived from the containing class within the current assembly 2017 Li Haobin, ISEM Department,NUS 35

36 1.9 Encapsulation -- Constructor A constructor is a method that is called when you create an object and it usually initializes the data members of the new object. Constructor is only called when you create an object. The code of a constructor will always run before other code in the same class. However, more constructor overwriting can be created by using the same overriding method. p u b l i c class SampleClass public SampleClass() // Add code here 2017 Li Haobin, ISEM Department,NUS 36

37 1.9 Encapsulation Instantiable Class Instantiable class is needed to create objects, that is, to create class instantiation. SampleClass sampleobject = new SampleClass(); // Set a property v a l u e. sampleobject.sampleproperty = "Sample S t r i n g " ; // Call a method. sampleobject.samplemethod(30); // Set a property value w i t h c o n s t r u c t i o n. SampleClass sampleobject = new SampleClass() SampleProperty = "Sample S t r i n g " ; // Call a method. sampleobject.samplemethod(30); 2017 Li Haobin, ISEM Department,NUS 37

38 1.9 Encapsulation Nested Class A class defined in another class is called nested class public class Container public class Nested // Add code h ere. // Instantiate nested class Container.Nested nestedinstance = new Container.Nested(); 2017 Li Haobin, ISEM Department,NUS 38

39 1.9 Encapsulation Static Class and Members Static members of a class is the properties, processes and fields shared by all the instantiations in the class. A static class can contain only static members and it cannot be instantiated. Static members cannot access properties, fields or methods that are not static. // define static members: static class SampleClass public static s t r i n g SampleString = "Sample S t r i n g " ; // Use the name of the class to access static members, but do not create objects of the class. Console.WriteLine(SampleClass.SampleString); 2017 Li Haobin, ISEM Department,NUS 39

40 1.9 Encapsulation The Realization of Entity Relationship Use class to define how two entities are related to each other. class Location // Define Location class public i n t I d get; set; public double Capacity get; set; public List<SKU> SKUs get; set; = new List<SKU>(); / / describe relationship with SKU public double Occupation get return SKUs.Sum(sku => sku.size); class SKU / / define SKU class public i n t I d get; private set; public double Size get; private set; public List<Location> Storage get; p rivate set; = new List<Location>(); // describe relationship with Location public SKU(int id, double s i z e, Location[] storage) //Two-way references are realized through the use of constructor Id = id; Size = s i z e ; Storage = storage.tolist(); foreach (Location loc in storage) loc.skus.add(this); 2017 Li Haobin, ISEM Department,NUS 40

41 1.9 Encapsulation The Realization of Entity Relationship Use class to define how two entities relate to each other. // Instantiation of Locations List<Location> locs = new List<Location> ; new Location Id = 0, Capacity = 15, new Location Id = 1, Capacity = 15, new Location Id = 2, Capacity = 20, new Location Id = 3, Capacity = 20, new Location Id = 4, Capacity = 20 // Add information of SKU, List<SKU> skus = new List<SKU>(); skus.add(new SKU(0, 0.8, new Location[] locs[0], locs[0], locs[0], l o c s [ 1 ] ) ) ; skus.add(new SKU(1, 0.5, new Location[] locs[1], locs[2], locs[3], l o c s [ 4 ] ) ) ; skus.add(new SKU(2, 1. 2, new L o c a t i o n [ ] l o c s [ 1 ], l o c s [ 2 ], l o c s [ 2 ], l o c s [ 4 ], l o c s [ 4 ] )); skus.add(new SKU(3, 1.5, new Location[] l o c s [ 3 ], l o c s [ 3 ], l o c s [ 3 ] ) ) ; 2017 Li Haobin, ISEM Department,NUS 41

42 Practice Two: Take the Location-SKU entity relationship instantiation above as example, use LINQ to answer the questions below: Which are the SKUs whose storage use more than 3 spaces? Which are the SKUs whose storage use more than 4 spaces? Order the location of SKUs according to spare space. Which are the locations with 3 SKUs being stored? Thinking: How to adjust the storage such that The stock volume is distributed to every location as even as possible? The spare volume is maximum for single location? Source code: Li Haobin, ISEM Department,NUS 42

43 1.10 Inheritance Inheritance is one of the basic features of OOP, with the ability to create a class that inherits, develops or modifies properties and behaviors from an existing class. The newly created class is the derived (or child) class and the existing class is the base (or parent) class. p u b l i c class A p u b l i c i n t Value1() r e t u r n 10; p u b l i c class B : A p u b l i c i n t Value2() r e t u r n 20; p u b l i c class C : B p u b l i c int Value3() r e t u r n 30; // Instantiation A a = new A(); B b = new B(); C c = new C(); Console.WriteLine( "0", a. V a l u e 1 ( ) ) ; Console.WriteLine("0 1 ", b. V a lue1(), b. V a l u e 2 ( ) ) ; Console.WriteLine("0 1 2 ", c. Value1 (), c. Value2 ( ), c. V a l u e 3 ( ) ) ; 2017 Li Haobin, ISEM Department,NUS 43

44 1.11 Polymorphism Base class can define and realize the virtual methods while the derived class can override the methods by providing its own definitions and implementations. Virtual method provides a uniform method to implement several related objects. p u b l i c class A p u b l i c v i r t u a l int Value1() r e t u r n 10; p u b l i c class B : A p u b l i c override i n t Value1() r e t u r n 11; p u b l i c i n t Value2() r e t u r n 20; p u b l i c class C : B p u b l i c override i n t Value1() r e t u r n 12; p u b l i c i n t Value3() r e t u r n 30; // Instantiation A a = new A(); B b = new B(); C c = new C(); Console.WriteLine( "0", a. V a l u e 1 ( ) ) ; Console.WriteLine("0 1 ", b. V a lue1(), b. V a l u e 2 ( ) ) ; Console.WriteLine("0 1 2 ", c. Value1 (), c. Value2 ( ), c. V a l u e 3 ( ) ) ; 2017 Li Haobin, ISEM Department,NUS 44

45 1.12 Interface An interface in C# contains the declaration of the methods, properties, and events of the class. For example, the use of interface in a class may contain behaviors from multiple sources. This feature is important in C# as C# does not support multiple inheritance. interface IEquatable<T> bool Equals(T o b j ) ; p u b l i c class Car : IEquatable<Car> p u b l i c string Make g e t ; s e t ; p u b l i c s t r i n g Model g e t ; set; p u b l i c string Year g e t ; s e t ; // Implementation of IEquatable<T> i n t e r f a c e p u b l i c bool Equals(Car c a r ) if (this.make == car.make && this.model == car.model && this.year == car.year) return true; else r e t u r n f a l s e ; 2017 Li Haobin, ISEM Department,NUS 45

46 1.13 Example: 24 Point Intellectual Program Given 4 numbers randomly, get the result of 24 by arithmetic operation Finite solution set, searching is not difficult The key is how to define, test and traverse operation expressions (system configuration) 2017 Li Haobin, ISEM Department,NUS 46

47 1.13 Example: 24 Point Intellectual Program Step 1:define the class p u b l i c class Expr p u b l i c Expr Operand1 g e t ; s e t ; p u b l i c Expr Operand2 get; set; p u b l i c string Operator get; set; p r i v a t e double? _value; // public double Value g e t ; s e t ; // see next page p u b l i c override string ToString() if (_value is null) r e t u r n s t r i n g. F o r m a t ( " ( ) ", Operand1, Operator, Operand2); r e t u r n _ value.value.tostring(); 2017 Li Haobin, ISEM Department,NUS 47

48 1.13 Example: 24 Point Intellectual Program //... p u b l i c double Value set _value = value; // assign value get // get value double value = 0 ; if (_value is null) switch (Operator) case "+": value = Operand1.Value + Operand2.Value; br e ak; case " - " : value = Operand1.Value - Operand2.Value; break; case "*": value = Operand1.Value * Operand2.Value; br e ak; case "/": value = Operand1.Value / Operand2.Value; b reak; if (value < 0) return double.nan; r e t u r n value; r e t u r n _value.value; Step 2:Calculation Class 2017 Li Haobin, ISEM Department,NUS 48

49 Practice 3(A): Use the previous Expr Class, construct and test the following expressions ( ) x 12 8 / x 10 Source code: Li Haobin, ISEM Department,NUS 49

50 1.13 Example: 24 Point Intellectual Program Step 3: traverse all operation expressions // Given the set of operands, return all possible expressions static List<Expr> GetExpr(int[] arr) // Initialize the return value var exprs = new List<Expr>(); // Separate the numbers into two parts of left and right var divs = new L i s t < T u p l e < i n t [ ], int[]>>(); 2017 Li Haobin, ISEM Department,NUS 50

51 1.13 Example: 24 Point Intellectual Program // Search for all possible ways of separating into two parts, store the results in divs s w i t c h ( a r r. L e n g t h ) c a s e 1 : r e t u r n n e w L i s t < E x p r > n e w E x p r V a l u e = a r r [ 0 ] ; // R e t u r n e x p r e s s i o n d i r e c t l y i f t h e r e i s o n l y o n e o p e r a n d c a s e 2 : d i v s = n e w L i s t < T u p l e < i n t [ ], i n t [ ] > > n e w T u p l e < i n t [ ], i n t [ ] > ( n e w i n t [ ] a r r [ 0 ], n e w i n t [ ] a r r [ 1 ] ) ; b r e a k ; c a s e 3 : d i v s = n e w L i s t < T u p l e < i n t [ ], i n t [ ] > > n e w T u p l e < i n t [ ], i n t [ ] > ( n e w i n t [ ] a r r [ 0 ], n e w i n t [ ] a r r [ 1 ], a r r [ 2 ] ), n e w T u p l e < i n t [ ], i n t [ ] > ( n e w i n t [ ] a r r [ 1 ], n e w i n t [ ] a r r [ 0 ], a r r [ 2 ] ), n e w T u p l e < i n t [ ], i n t [ ] > ( n e w i n t [ ] a r r [ 2 ], n e w i n t [ ] a r r [ 0 ], a r r [ 1 ] ), ; b r e a k ; c a s e 4 : divs = n e w L i s t < T u p l e < i n t [ ], int[ ] > > new T u p l e < int[ ], i nt[]>(new int[] arr[0], new int[] arr[1], arr[ 2 ], arr[3] ), new T u p l e < int[ ], i nt[]>(new int[] arr[1], new int[] arr[0], arr[ 2 ], arr[3] ), new T u p l e < int[ ], i nt[]>(new int[] arr[2], new int[] arr[0], arr[ 1 ], arr[3] ), new T u p l e < int[ ], i nt[]>(new int[] arr[3], new int[] arr[0], arr[ 1 ], arr[2] ), new T u p l e < int[ ], int[]>(new i n t [] arr[ 0 ], arr[1], new int[] arr[ 2 ], arr[3] ), new T u p l e < int[ ], int[]>(new int[ ] arr[0], arr[2], new i n t [ ] arr[ 1 ], arr[3] ), new T u p l e < int[ ], int[]>(new int[ ] arr[0], arr[3], new i n t [ ] arr[ 1 ], arr[2] ), ; break; 2017 Li Haobin, ISEM Department,NUS 51

52 1.13 Example: 24 Point Intellectual Program // For each result of two-part separation, use recursion to generate two expression pairs of left and right. var pairs = d i v s. S e l e c t ( t => new Tuple<List<Expr>, List<Expr>>(GetExpr(t.Item1), G e t E x p r ( t. I t e m 2 ) ) ). T o L i s t ( ) ; // Transverse all pairs foreach (Tuple<List<Expr>, List<Expr>> pair in pairs) foreach (Expr exp1 i n pair.item1) foreach (Expr exp2 in pair.item2) // Transverse operators to generate expressions. exprs.add(new Expr Operand1 = exp1, Operand2 = exp2, Operator = "+" ); exprs.add(new Expr Operand1 = exp1, Operand2 = exp2, Operator = "*" ); exprs.add(new Expr Operand1 = exp1, Operand2 = exp2, Operator = " - " ); exprs.add(new Expr Operand1 = exp2, Operand2 = exp1, Operator = " - " ); exprs.add(new Expr Operand1 = exp1, Operand2 = exp2, Operator = "/" ); exprs.add(new Expr Operand1 = exp2, Operand2 = exp1, Operator = "/" ); // Return the results r e t u r n exprs; 2017 Li Haobin, ISEM Department,NUS 52

53 Practice 3(B): Answer without using the above code: How many expression combinations are there given any 1 random number? How many expression combinations are there given any 2 random numbers? Answer by using the above code: How many expression combinations are there given any 3 random numbers? How many expression combinations are there given any 4 random numbers? Thinking question: How many expression combinations are there given any 4 random numbers? Source code: Li Haobin, ISEM Department,NUS 53

54 1.13 Example: 24 Point Intellectual Program Step 4: Searching ( A trivial case) while ( true) Console.WriteLine("==== GET 24 ===="); var exprs = GetExpr(Console.ReadLine().Split( ' ' ). S e l e c t ( s => Convert.ToInt32(s)).Take(4).ToArray()); foreach ( v a r expr in exprs) if (expr.value == 24) Console.WriteLine(expr); Console.WriteLine(); 2017 Li Haobin, ISEM Department,NUS 54

55 Practice 3(C): Question: Why is the game designed to calculate 24 instead of any other umbers (write a numerical experiment program to answer)? Is it possible to design a game that make calculations using 3 numbers only? Source code: Li Haobin, ISEM Department,NUS 55

56 Practice 3(C): No. of possible combinations Average no. of possible expressions Li Haobin, ISEM Department,NUS 56

57 Thank You! 2017 Li Haobin, ISEM Department,NUS 57

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh C# Fundamentals Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2018/19 H-W. Loidl (Heriot-Watt Univ) F20SC/F21SC 2018/19

More information

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals C# Types Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 C# Types Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Introduction to.net, C#, and Visual Studio. Part I. Administrivia. Administrivia. Course Structure. Final Project. Part II. What is.net?

Introduction to.net, C#, and Visual Studio. Part I. Administrivia. Administrivia. Course Structure. Final Project. Part II. What is.net? Introduction to.net, C#, and Visual Studio C# Programming Part I Administrivia January 8 Administrivia Course Structure When: Wednesdays 10 11am (and a few Mondays as needed) Where: Moore 100B This lab

More information

NOIDATUT E Leaning Platform

NOIDATUT E Leaning Platform NOIDATUT E Leaning Platform Dot Net Framework Lab Manual COMPUTER SCIENCE AND ENGINEERING Presented by: NOIDATUT Email : e-learn@noidatut.com www.noidatut.com C SHARP 1. Program to display Hello World

More information

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators 1 The following pages show errors from the original edition, published in July 2008, corrected in red. Future editions of this book will be printed with these corrections. We apologize for any inconvenience

More information

Standard. Number of Correlations

Standard. Number of Correlations Computer Science 2016 This assessment contains 80 items, but only 80 are used at one time. Programming and Software Development Number of Correlations Standard Type Standard 2 Duty 1) CONTENT STANDARD

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

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Object-Oriented Programming in C# (VS 2015)

Object-Oriented Programming in C# (VS 2015) Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes

More information

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Abstraction Encapsulation Inheritance and Polymorphism Object-Oriented

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

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Learning C# 3.0 Jesse Liberty and Brian MacDonald O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Table of Contents Preface xv 1. C# and.net Programming 1 Installing C# Express 2 C# 3.0

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

C#: framework overview and in-the-small features

C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Course Syllabus C # Course Title. Who should attend? Course Description

Course Syllabus C # Course Title. Who should attend? Course Description Course Title C # Course Description C # is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the.net Framework.

More information

Object-Oriented Programming in C# (VS 2012)

Object-Oriented Programming in C# (VS 2012) Object-Oriented Programming in C# (VS 2012) This thorough and comprehensive course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes the C#

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain 2016-04-02 Overview. C# program structure. Variables and Constant. Conditional statement (if, if/else, nested if

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

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

3. Basic Concepts. 3.1 Application Startup

3. Basic Concepts. 3.1 Application Startup 3.1 Application Startup An assembly that has an entry point is called an application. When an application runs, a new application domain is created. Several different instantiations of an application may

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

CHAPTER 1: INTRODUCING C# 3

CHAPTER 1: INTRODUCING C# 3 INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the.net Framework? 4 What s in the.net Framework? 4 Writing Applications Using the.net Framework 5 What Is C#? 8 Applications

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

This tutorial has been prepared for the beginners to help them understand basics of c# Programming. About thetutorial C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its.net initiative led by Anders Hejlsberg. This tutorial covers basic C# programming

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Namespaces Classes Fields Properties Methods Attributes Events Interfaces (contracts) Methods Properties Events Control Statements if, else, while, for, switch foreach Additional Features Operation Overloading

More information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,

More information

C# in Unity 101. Objects perform operations when receiving a request/message from a client

C# in Unity 101. Objects perform operations when receiving a request/message from a client C# in Unity 101 OOP What is OOP? Objects perform operations when receiving a request/message from a client Requests are the ONLY* way to get an object to execute an operation or change the object s internal

More information

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java.

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java. Q.2 a. What is C#? Discuss its features in brief. 1. C# is a simple, modern, object oriented language derived from C++ and Java. 2. It aims to combine the high productivity of Visual Basic and the raw

More information

IT 528 Developing.NET Applications Using C# Gülşen Demiröz

IT 528 Developing.NET Applications Using C# Gülşen Demiröz IT 528 Developing.NET Applications Using C# Gülşen Demiröz Summary of the Course Hands-on applications programming course We will learn how to develop applications using the C# programming language on

More information

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio Introduction XXV Part I: C# Fundamentals 1 Chapter 1: The.NET Framework 3 What s the.net Framework? 3 Common Language Runtime 3.NET Framework Class Library 4 Assemblies and the Microsoft Intermediate Language

More information

PES INSTITUTE OF TECHNOLOGY

PES INSTITUTE OF TECHNOLOGY Seventh Semester B.E. IA Test-I, 2014 USN 1 P E I S PES INSTITUTE OF TECHNOLOGY C# solution set for T1 Answer any 5 of the Following Questions 1) What is.net? With a neat diagram explain the important

More information

Framework Fundamentals

Framework Fundamentals Questions Framework Fundamentals 1. Which of the following are value types? (Choose all that apply.) A. Decimal B. String C. System.Drawing.Point D. Integer 2. Which is the correct declaration for a nullable

More information

C# Java. C# Types Naming Conventions. Distribution and Integration Technologies. C# C++.NET A C# program is a collection of: C C++ C# Language

C# Java. C# Types Naming Conventions. Distribution and Integration Technologies. C# C++.NET A C# program is a collection of: C C++ C# Language C# Java Distribution and Integration Technologies C# Language C C++ C# C++.NET A C# program is a collection of: Classes Structs Interfaces Delegates Enums (can be grouped in namespaces) One entry point

More information

Distribution and Integration Technologies. C# Language

Distribution and Integration Technologies. C# Language Distribution and Integration Technologies C# Language Classes Structs Interfaces Delegates Enums C# Java C C++ C# C++.NET A C# program is a collection of: (can be grouped in namespaces) One entry point

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class. 1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity

More information

Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer

Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 2 Agenda Ø Quizzes Ø More quizzes Ø And even more quizzes 2 Quiz 1. What will be printed? Ø Integers public class

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C# Microsoft s.net is a revolutionary advance in programming technology that greatly simplifies application development and is a good match for the emerging paradigm of Web-based services, as opposed to proprietary

More information

Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects

Computing is about Data Processing (or number crunching) Object Oriented Programming is about Cooperating Objects Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects C# is fully object-oriented: Everything is an Object: Simple Types, User-Defined Types,

More information

Arrays, Strings and Collections

Arrays, Strings and Collections Arrays Arrays can be informally defined as a group of variables containing values of the same type and that in some way or another they are related. An array has a fixed size that is defined before the

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

TYPES, VALUES AND DECLARATIONS

TYPES, VALUES AND DECLARATIONS COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

PROGRAMMING IN C++ COURSE CONTENT

PROGRAMMING IN C++ COURSE CONTENT PROGRAMMING IN C++ 1 COURSE CONTENT UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 2 1.1 Procedure oriented Programming 1.2 Object oriented programming paradigm 1.3 Basic concepts of Object Oriented

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions C++: Const Function Overloading Constructors and Destructors Enumerations Assertions Const const float pi=3.14159; const int* pheight; // defines pointer to // constant int value cannot be changed // pointer

More information

Object-Oriented Programming Concepts

Object-Oriented Programming Concepts Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are

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.5: Methods A Deeper Look Xianrong (Shawn) Zheng Spring 2017 1 Outline static Methods, static Variables, and Class Math Methods with Multiple

More information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

Object Oriented Programming with Java

Object Oriented Programming with Java Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic? What property of a C# array indicates its allocated size? a. Size b. Count c. Length What property of a C# array indicates its allocated size? a. Size b. Count c. Length What keyword in the base class

More information

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B. CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function

More information

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007 Previous C# Releases C# 3.0 Language Features C# Programming March 12, 2007 1.0 2001 1.1 2003 2.0 2005 Generics Anonymous methods Iterators with yield Static classes Covariance and contravariance for delegate

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION Program: C#.Net (Basic with advance) Duration: 50hrs. C#.Net OVERVIEW Strong Programming Features of C# ENVIRONMENT The.Net Framework Integrated Development Environment (IDE) for C# PROGRAM STRUCTURE Creating

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

A Comparison of Visual Basic.NET and C#

A Comparison of Visual Basic.NET and C# Appendix B A Comparison of Visual Basic.NET and C# A NUMBER OF LANGUAGES work with the.net Framework. Microsoft is releasing the following four languages with its Visual Studio.NET product: C#, Visual

More information

An OBJECT contains VARIABLES = PROPERTIES and METHODS = BEHAVIORS. Outline the general nature of an object.

An OBJECT contains VARIABLES = PROPERTIES and METHODS = BEHAVIORS. Outline the general nature of an object. D Object oriented programming Notes by Dave Mulkey, 2015, Germany D.1 Objects as a programming concept (6 hours) The paradigm of object oriented programming should be introduced through discussion and

More information

Lecture 12: Data Types (and Some Leftover ML)

Lecture 12: Data Types (and Some Leftover ML) Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals

More information

DOT NET Syllabus (6 Months)

DOT NET Syllabus (6 Months) DOT NET Syllabus (6 Months) THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In- Time Compilation and CLS Disassembling.Net Application to IL

More information

Learning to Program in Visual Basic 2005 Table of Contents

Learning to Program in Visual Basic 2005 Table of Contents Table of Contents INTRODUCTION...INTRO-1 Prerequisites...INTRO-2 Installing the Practice Files...INTRO-3 Software Requirements...INTRO-3 Installation...INTRO-3 Demonstration Applications...INTRO-3 About

More information

SWE344. Internet Protocols and Client-Server Programming

SWE344. Internet Protocols and Client-Server Programming SWE344 Internet Protocols and Client-Server Programming Module 1a: 1a: Introduction Dr. El-Sayed El-Alfy Mr. Bashir M. Ghandi alfy@kfupm.edu.sa bmghandi@ccse.kfupm.edu.sa Computer Science Department King

More information

CO Java SE 8: Fundamentals

CO Java SE 8: Fundamentals CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 6: C# Data Manipulation Industrial Programming 1 The Stream Programming Model File streams can be used to access stored data. A stream is an object that represents a generic

More information

DAD Lab. 1 Introduc7on to C#

DAD Lab. 1 Introduc7on to C# DAD 2017-18 Lab. 1 Introduc7on to C# Summary 1..NET Framework Architecture 2. C# Language Syntax C# vs. Java vs C++ 3. IDE: MS Visual Studio Tools Console and WinForm Applica7ons 1..NET Framework Introduc7on

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Programming in Visual Basic with Microsoft Visual Studio 2010

Programming in Visual Basic with Microsoft Visual Studio 2010 Programming in Visual Basic with Microsoft Visual Studio 2010 Course 10550; 5 Days, Instructor-led Course Description This course teaches you Visual Basic language syntax, program structure, and implementation

More information

C# Programming in the.net Framework

C# Programming in the.net Framework 50150B - Version: 2.1 04 May 2018 C# Programming in the.net Framework C# Programming in the.net Framework 50150B - Version: 2.1 6 days Course Description: This six-day instructor-led course provides students

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 214 MODULE TEST 1

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 214 MODULE TEST 1 UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS RIS 214 MODULE TEST 1 DATE: 12 March 2014 TIME: 4 hours MARKS: 220 ASSESSORS: Prof. P.J. Blignaut & Mr G.J. Dollman BONUS MARKS:

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Introduction To C#.NET

Introduction To C#.NET Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan Institute of Engineering & Technology for Diploma Studies Overview of Microsoft.Net Framework: The Dot Net or.net is a technology that is an outcome of Microsoft s new strategy to develop window based robust applications and rich web applications and to keep

More information

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1 CSE P 501 Compilers Static Semantics Hal Perkins Winter 2008 1/22/2008 2002-08 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Attribute grammars Representing types Symbol tables Note: this covers

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

C++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming

More information

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com 70-483 MCSA Universal Windows Platform A Success Guide to Prepare- Programming in C# edusum.com Table of Contents Introduction to 70-483 Exam on Programming in C#... 2 Microsoft 70-483 Certification Details:...

More information

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp...

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp... 1 of 8 8/27/2014 2:15 PM Units: Teacher: ProgIIIAPCompSci, CORE Course: ProgIIIAPCompSci Year: 2012-13 Computer Systems This unit provides an introduction to the field of computer science, and covers the

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information