1 / 70

Advanced Programming

Advanced Programming. C# Introduction. C# Genealogy. Object Oriented. Advanced Object Oriented. Elementary Procedural. Advanced Procedural. Special Procedural. Eiffel. Fortran. Algol 68. C. C++. C#. Cobol. PL/I. Ada 95. Java. Pascal. Ada 83. Program.

denton
Download Presentation

Advanced Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Programming C# Introduction

  2. C# Genealogy ObjectOriented AdvancedObjectOriented ElementaryProcedural AdvancedProcedural SpecialProcedural Eiffel Fortran Algol 68 C C++ C# Cobol PL/I Ada 95 Java Pascal Ada 83

  3. Program • A program is a machine-compatible representation of an algorithm • If no algorithm exists for performing a task, then the task can not be performed by a machine • Programs and algorithms they represent collectively referred to as Software

  4. Programming Languages Machine language Strings of 0 and 1, machine dependent Assembly language • English like abbreviations representing elementary operations • Assemblers needed to convert assembly into machine language High-level languages (C, C++, Java, …) • Single statements accomplish substantial tasks • Compiler needed to convert the program into machine language • Some languages are interpreted (executed without the need for compilation)

  5. 177312 137272 001400 026400 017400 000012 000007 004420 010400 011000 000010 005023 012000 012400 000010 003426 013400 000007 000430 003000 064474 064556 037164 000001 024003 053051 000001 041404 062157 000545 007400 064514 062556 072516 061155 071145 060524 066142 000545 002000 060555 067151 000001 024026 046133 060552 060566 066057 067141 027547 072123 064562 063556 024473 000526 005000 067523 071165 062543 064506 062554 000001 046014 067151 067543 067154 065056 073141 006141 004000 004400 000007 006031 015000 015400 000001 040433 070440 067565 062564 060552 060566 064457 027557 071120 067151 051564 071164 060545 000555 003400 071160 067151 066164 000556 012400 046050 060552 060566 066057 067141 027547 072123 064562 063556 024473 000126 000041 000006 000007 000000 000000 000002 000001 000010 000011 000001 000012 000000 000035 000001 000001 000000 025005 000267 130401 000000 000400 005400 000000 003000 000400 000000 003400 004400 006000 006400 000400 005000 000000 030400 001000 000400 000000 010400 000262 011002 133003 002000 000262 011002 133005 002000 000261 000000 000001 000013 000000 000016 000003 000000 000016 000010 000020 000020 000021 000001 000016 000000 000002 000017 Example Machine Code Fragment A number specifies what action the computer should take.

  6. Example Assembly Code Fragment movl (%edx,%eax), %ecx movl 12(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax movl (%edx,%eax), %eax fldl (%ecx) fsubl (%eax) movl 8(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax movl (%edx,%eax), %ecx movl 12(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax Symbols to help programmers to remember the words.

  7. Programming Languages • Examples of High-level languages • FORTRAN (FORmula TRANslator) in 1950s scientific and engineering applications • COBOL (Common Business Oriented language) in 1959 Commercial applications for manipulation of large amounts of data • BASIC (Beginner’s All Purpose Symbolic Instruction Code) Familiarize novices with programming techniques (in mid-1960s) • Pascal (17th century mathematician Blaise Pascal) in 1971 Teaching structured programming in academic environments

  8. Programming Languages • C • Bell labs  Dennis Ritchie, 1973 • C++ • Bjarne Stroustrup, 1980 • Hybrid OOP • Java • Sun Microsystems (formally announced in May 1995) • Pure OOP • Web programming

  9. What is C#? • C# (pronounced "C sharp") is an object-oriented language that is used to build applications for the Microsoft .NET platform • C# is designed by Microsoft to combine the power of C/C++, Java and the productivity of Visual Basic • The goal of C# and the .NET platform is to shorten development time • by allowing developers to spend their time working on the application logic instead of low level programming details

  10. Why C#? • support so-called safe internet programming • simpler than other object-oriented languages [C++] • safe and robust --- no core dump or dead console • good graphics package • related to C and C++ • good client-server and network support • good for your future job

  11. C# A component oriented language • C# is the first “component oriented” language • Component concepts are first class: • Properties, methods, events • Design-time and run-time attributes • Integrated documentation using XML • Enables one-stop programming • No header files, IDL, etc. • Can be embedded in web pages

  12. C# Everything really is an object • Traditional views • C++, Java: Primitive types are “magic” and do not interoperate with objects • Smalltalk, Lisp: Primitive types are objects, but at great performance cost • C# unifies with no performance cost • Deep simplicity throughout system • Improved extensibility and reusability • New primitive types: Decimal, SQL… • Collections, etc., work for alltypes

  13. Learning C# • Just like learning any new language • Syntax: “new words” • Grammar: how to put them together • Programming: telling a coherent story • Library: use plots already written • Picking up Java and C++ after C# should be easy!

  14. Programming Languages C# • Microsoft announced the .NET initiative (June 2000) and C# • .NET enables web-based applications to be distributed to a great variety of devices and desktop computers • Allows applications created in various programming languages to communicate with each other • Designed to ease migration to .NET (roots in C and C++) • Event-driven, fully OO visual programming language

  15. Microsoft’s .NET Technologies Many languages run on .NET framework C#, C++, J#, Visual Basiceven have Python (see IronPython)

  16. Example C++/C#/Java Code Fragment bool DetermineNeighbor(int i, int j) { double distanceX = (nodes[i].x - nodes[j].x); double distanceY = (nodes[i].y - nodes[j].y); double distanceSquare = disx * disx + disy * disy; double distance = sqrt(distanceSquare); if (distance < radius) return true; else return false; } You do not need to understand the exact meaning of this program, just the feeling.

  17. Visual StudioHTML 5 / CSS 3 / Javascript • HTML 5 / CSS • Full HTML 5 and CSS 3 specs supported • Quirks for downlevel browsers fully supported • CSS and JavaScript now first class citizens in editor • DOCTYPE • JavaScript • Based on Chakra engine in IE 9 • Directly tell us which JS files to provide intellisense

  18. C#is executed indirectly through an abstract computer architecture called the CLR. CLR => Common Language Runtime. Abstract, but well defined. C# programs are compiled to an IL. Also called MSIL, CIL (Common Intermediate Language) or bytecode. C# compiling. http://msdn2.microsoft.com/en-us/library/z1zx9t92(VS.80).aspx

  19. Compiling C# Source Code • C# file names have the extension .cs • To create the IL file, we need to compile the .cs file using the csc (using the command line), followed by the name of the source file • The result is a file with the same name but the .exe extension, which is called an assembly • The assembly file contains all the information that the common runtime needs to know to execute the program • We can also create multi-file assemblies using an assembly linker, see the following link for more details: • http://longhorn.msdn.microsoft.com/lhsdk/ndp/tskhowtobuildmultfileassembly.aspx

  20. MSIL C# compiler Just in time compiler Machine code C# Compilation and Execution C# source code

  21. As in Java Object-orientation (single inheritance) Namespaces(like packages) Interfaces Strong typing Exceptions Threads Garbage collection Reflection Dynamic loadingof code As in C++ Operator overloading Pointer arithmetic in unsafe code Some syntactic details As in VB Properties Events RAD development C# and Language Comparison60% Java, 10% C++, 10% VB, 20% new

  22. OOP • Structured programming versus OOP • Objects have properties (attributes) and perform actions • Objects are defined in classes (represent groups of related objects) • Programs are more understandable • better organized programs

  23. Introduction to C# • Console applications • No visual components • Only text output • Two types • MS-DOS prompt (Used in Windows 95/98/ME) • Command prompt (Used in windows 2000/NT/XP) • Windows applications • Forms with several output types • Contain Graphical User Interfaces (GUIs)

  24. New Project dialog.

  25. New Project dialog. • New project dialogue • C# .NET project • Group of related files, images, and documentations • C# .NET solution • Group of projects creating one or a group of applications • Windows Applications • Anything that runs in the Windows OS • Microsoft Word • Microsoft Internet Explorer

  26. Simple Program

  27. A First C# Program: 'Hello World' • using System; • public class HelloWorld • { • public static void Main(string[] args) • { • // This is a single line comment • /* This is a • multiple • line comment */ • Console.WriteLine("Hello World"); • } • }

  28. Simple Program Execution of the Welcome1 program.

  29. Windows Application menu title bat tabs menu bar active tab Solution Explorer Form (windows application) Properties window

  30. Windows Application • IDE after a new project • The form • Grey rectangle in window • Represents the project’s window • Part of the GUI or Graphical User Interface • Graphical components for user interaction • User can enter data (input) • Shows user instructions or results (output) • Tabs • One tab appears for each open document • Used to save space in the IDE

  31. Simple Program: Displaying Text and an Image

  32. Simple Program: Displaying Text and an Image Project type Project name Click to change project location Project location Creating a new Windows application.

  33. Simple Program: Displaying Text and an Image Name and type of object Selected property Property value Property description Setting the form’s Text property.

  34. Simple Program: Displaying Text and an Image • Resize the form • Click and drag one of the forms size handles • Enables handles are white • Disables handles are gray • The grid in the background will not appear in the solution • Change the form’s background color • The BackColor determines the form’s background color • Dropdown arrow is used to set the color • Add a label control to the form • Controls can be dragged to the form • Controls can be added to the form by double clicking • The forms background color is the default of added controls

  35. Simple Program: Displaying Text and an Image Title bar grid Disabled sizing handle Mouse pointer over a sizing handle Enabled sizing handle Form with sizing handles.

  36. Simple Program: Displaying Text and an Image Current color Custom palette Down arrow Changing property BackColor.

  37. Simple Program: Displaying Text and an Image Label control New background color Adding a new label to the form.

  38. Simple Program: Displaying Text and an Image • Set the label’s text • The Text property is used to set the text of a label • The label can be dragged to a desired location • Or Format>CenterInForm>Horizontal can also be used to position the label as in in this example • Set the label’s font size and align text • The Font property changes the label’s text (Fig. 2.23) • The TextAlign property to align the text • Add a picture box to the form • Picture boxes are used to display pictures • Drag the picture box onto the form

  39. Simple Program: Displaying Text and an Image Label centered with updated Text property Label in position with its Text property set.

  40. Simple Program: Displaying Text and an Image Ellipsis indicate dialog will appear Properties window displaying the label’s properties.

  41. Simple Program: Displaying Text and an Image Current font Font size Font window for selecting fonts, styles and sizes.

  42. Simple Program: Displaying Text and an Image Text alignment option Top-center alignment option Centering the text in the label.

  43. Simple Program: Displaying Text and an Image Updated Label New PictureBox Inserting and aligning the picture box.

  44. Simple Program: Displaying Text and an Image • Insert an image • The Image property sets the image that appears • Pictures should be of type .gif, .jpeg, or .png • The picture box is resizable to fit the entire image • Save the project • In the SolutionExplorer select File>Save • Using SaveAll will save the source code and the project • Run the project • In run mode several IDE features are disabled • Click BuildSolution in the Build menu to compile the solution • Click Debug in the Start menu or press the F5 key

  45. Simple Program: Displaying Text and an Image Image property value (no image selected) Image property of the picture box.

  46. Simple Program: Displaying Text and an Image Selecting an image for the picture box.

  47. Simple Program: Displaying Text and an Image Newly inserted image (after resizing the picture box) Picture box after the image has been inserted.

More Related