C# Programming: From Problem Analysis to Program Design

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Pemrograman VisualMinggu …2… Page 1 MINGGU Ke Dua Pemrograman Visual Pokok Bahasan: Console Application Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Advanced Object-Oriented Programming Features
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program C# Programming: From Problem Analysis to Program Design 2 nd Edition.
Introduction to Computing and Programming
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C# Programming: From Problem Analysis to Program Design
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Creating a Console Application with Visual Studio
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Module 1: Introduction to C# Module 2: Variables and Data Types
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Microsoft Visual Basic 2005: Reloaded Second Edition
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Chapter 1: Creating Java Programs
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Creating a Java Application and Applet
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
C# Programming: From Problem Analysis to Program Design1 4 th Edition Introduction to Computing and Programming 1.
C# Diline Giriş.
Computer Programming Your First Java Program: HelloWorld.java.
Visual Basic.NET Windows Programming
C++ First Steps.
Chapter 2: The Visual Studio .NET Development Environment
Great way to learn is by example so fire up Visual Studios C (at home make sure you custom install with C++ - no longer default) by Deborah R. Fowler.
C# Programming: From Problem Analysis to Program Design
CSC201: Computer Programming
Chapter 1: An Introduction to Visual Basic 2015
Advanced Object-Oriented Programming Features
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
1. Introduction to Visual Basic
Java programming lecture one
Variables and Arithmetic Operations
C# Programming: From Problem Analysis to Program Design
VISUAL BASIC.
Chapter 2 – Getting Started
String Output ICS 111: Introduction to Computer Science I
Social Media And Global Computing Introduction to Visual Studio
Advanced Programming Lecture 02: Introduction to C# Apps
Understanding the Visual IDE
CIS16 Application Development Programming with Visual Basic
Chapter 3 – Introduction to C# Programming
Chapter 2: Introduction to C++.
Computer Programming-1 CSC 111
Presentation transcript:

C# Programming: From Problem Analysis to Program Design Your First C# Program 2 C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design

Chapter Objectives Distinguish between the different types of applications that can be created with C# Explore a program written in C# Examine the basic elements of a C# program Learn about installing the .NET Framework C# Programming: From Problem Analysis to Program Design

Chapter Objectives (continued) Compile, run, and build an application Debug an application Create an application that displays output Work through a programming example that illustrates the chapter’s concepts C# Programming: From Problem Analysis to Program Design

Types of Applications Developed with C# Web applications Windows graphical user interface (GUI) applications Console-based applications Class libraries and stand-alone components (.dlls), smart device applications, and services can also be created C# Programming: From Problem Analysis to Program Design

Web Applications C# was designed with the Internet applications in mind Can quickly build applications that run on the Web with C# Using Web Forms: part of ASP.NET C# Programming: From Problem Analysis to Program Design

Web Applications (continued) Figure 2-1 Web application written using C# C# Programming: From Problem Analysis to Program Design

Windows Applications Applications designed for the desktop Designed for a single platform Use classes from System.Windows.Form Applications can include menus, pictures, drop- down controls, buttons, textboxes, and labels Use drag-and-drop feature of Visual Studio C# Programming: From Problem Analysis to Program Design

Windows Applications (continued) Figure 2-2 Windows application written using C# C# Programming: From Problem Analysis to Program Design

Console Applications Normally send requests to the operating system Display text on the command console Easiest to create Simplest approach to learning software development Minimal overhead for input and output of data C# Programming: From Problem Analysis to Program Design

Exploring the First C# Program line 1 // This is traditionally the first program written. line 2 using System; line 3 namespace FirstProgram line 4 { line 5 class HelloWorld line 6 { line 7 static void Main( ) line 8 { line 9 Console.WriteLine(“Hello World!”); line 10 } line 11 } line 12 } Comments in green Keywords in blue C# Programming: From Problem Analysis to Program Design

Output from the First C# Program Console-based application output Figure 2-3 Output from Example 2-1 console application C# Programming: From Problem Analysis to Program Design

Elements of a C# Program Comments line 1 // This is traditionally the first program written. Like making a note to yourself or readers of your program Not considered instructions to the computer Not checked for rule violations Document what the program statements are doing C# Programming: From Problem Analysis to Program Design

Comments Make the code more readable Three types of commenting syntax Inline comments Multiline comments XML documentation comments C# Programming: From Problem Analysis to Program Design

Inline Comments Indicated by two forward slashes (//) Considered a one-line comment Everything to the right of the slashes ignored by the compiler Carriage return (Enter) ends the comment // This is traditionally the first program written. C# Programming: From Problem Analysis to Program Design

Multiline Comment Forward slash followed by an asterisk (/*) marks the beginning Opposite pattern (*/) marks the end Also called block comments /* This is the beginning of a block multiline comment. It can go on for several lines or just be on a single line. No additional symbols are needed after the beginning two characters. Notice there is no space placed between the two characters. To end the comment, use the following symbols. */ C# Programming: From Problem Analysis to Program Design

XML Documentation Comments Extensible Markup Language (XML) Markup language that provides a format for describing data using tags Similar to HTML tags Three forward slashes (///) mark beginning of comment Advanced documentation technique used for XML-style comments Compiler generates XML documentation from them C# Programming: From Problem Analysis to Program Design

using Directive Permits use of classes found in specific namespaces without having to qualify them Framework class library Over 2,000 classes included Syntax using namespaceIdentifier; C# Programming: From Problem Analysis to Program Design

namespace Namespaces provide scope for the names defined within the group Captain example Groups semantically related types under a single umbrella System: most important and frequently used namespace Can define your own namespace Each namespace enclosed in curly braces: { } C# Programming: From Problem Analysis to Program Design

namespace (continued) Predefined namespace (System)– part of .NET FCL From Example 2-1 line 1 // This is traditionally the first program written. line 2 using System; line 3 namespace FirstProgram line 4 { line 12 } User defined namespace Body of user defined namespace C# Programming: From Problem Analysis to Program Design

class Building block of object-oriented program Everything in C# is designed around a class Every program must have at least one class Classes define a category, or type, of object Every class is named C# Programming: From Problem Analysis to Program Design

class (continued) line 1 // This is traditionally the first program written. line 2 using System; line 3 namespace FirstProgram line 4 { line 5 class HelloWorld line 6 { line 11 } line 12 } User defined class C# Programming: From Problem Analysis to Program Design

class (continued) Define class members within curly braces Include data members Stores values associated with the state of the class Include method members Performs some behavior of the class Can call predefined classes’ methods Main( ) C# Programming: From Problem Analysis to Program Design

Main( ) “Entry point” for all applications Where the program begins execution Execution ends after last statement in Main( ) Can be placed anywhere inside the class definition Applications must have one Main( ) method Begins with uppercase character C# Programming: From Problem Analysis to Program Design

Main( ) Method Heading line 7 static void Main( ) Begins with the keyword static Second keyword → return type void signifies no value returned Name of the method Main is the name of Main( ) method Parentheses “( )” used for arguments No arguments for Main( ) – empty parentheses  C# Programming: From Problem Analysis to Program Design

Body of a Method Enclosed in curly braces Includes program statements Example Main( ) method body line 7 static void Main( ) line 8 { line 9 Console.WriteLine(“Hello World!”); line 10 } Includes program statements Calls to other method Here Main( ) calling WriteLine( ) method C# Programming: From Problem Analysis to Program Design

Method Calls Program statements line 9 Console.WriteLine(“Hello World!”); Program statements WriteLine( ) → member of the Console class Main( ) invoking WriteLine( ) method Member of Console class Method call ends in semicolon C# Programming: From Problem Analysis to Program Design

Program Statements Write ( ) → Member of Console class Argument(s) enclosed in double quotes inside ( ) “Hello World!” is the method’s argument “Hello World!” is string argument string of characters May be called with or without arguments Console.WriteLine( ); Console.WriteLine(“WriteLine( ) is a method.”); Console.Write(“Main( ) is a method.”); C# Programming: From Problem Analysis to Program Design

Program Statements (continued) Read( ) accepts one character from the input device ReadLine( ) accepts string of characters from the input device Until the enter key is pressed Write( ) does not automatically advance to next line Write(“An example\n”); Same as WriteLine(“An example”); Includes special escape sequences C# Programming: From Problem Analysis to Program Design

Program Statements (continued) Special characters enclosed in double quotes C# Programming: From Problem Analysis to Program Design

C# Elements Figure 2-4 Relationship among C# elements C# Programming: From Problem Analysis to Program Design

Installing .NET Framework .NET Framework must be installed to: Compile, build, and run a C# application Can download Microsoft’s .NET Framework Software Development Kit (SDK)→free download OR install Visual Studio software (from book) Create a place to store your work C# Programming: From Problem Analysis to Program Design

Installing .NET Framework (continued) Use the Visual Studio Integrated Development Environment (IDE) → Built-in editor Type your program statements Use Visual Studio IDE → Built-in compiler Check for syntax rule violations Compiler generates a file with an .exe extension Use Visual Studio IDE → Built-in debugger Use Visual Studio IDE → Built-in executor C# Programming: From Problem Analysis to Program Design

Create Console Application Begin by opening Visual Studio Create new project Select New Project on the Start page OR use File → New Project option C# Programming: From Problem Analysis to Program Design

Create New Project Figure 2-6 Creating a console application C# Programming: From Problem Analysis to Program Design

Code Automatically Generated Figure 2-7 Code automatically generated by Visual Studio C# Programming: From Problem Analysis to Program Design

Typing Your Program Statements IntelliSense feature of the IDE Change the name of the class and the source code filename Use the Solution Explorer Window to change the source code filename Select View → Solution Explorer C# Programming: From Problem Analysis to Program Design

Rename Source Code Name Clicking Yes causes the class name to also be renamed Figure 2-8 Changing the source code name from Class1 C# Programming: From Problem Analysis to Program Design

Compile and Run Application To Compile – click Build on the Build menu To run or execute application – click Start or Start Without Debugging on the Debug menu Shortcut – if execute code that has not been compiled, automatically compiles first Start option does not hold output screen → output flashes quickly Last statement in Main( ), add Console.Read( ); C# Programming: From Problem Analysis to Program Design

Build Visual Studio Project Figure 2-9 Compilation of a project using Visual Studio C# Programming: From Problem Analysis to Program Design

Running an Application Figure 2-10 Execution of an application using Visual Studio C# Programming: From Problem Analysis to Program Design

Debugging an Application Types of errors Syntax errors Typing error Misspelled name Forget to end a statement with a semicolon Run-time errors Failing to fully understand the problem More difficult to detect C# Programming: From Problem Analysis to Program Design

Missing ending double quotation mark Error Listing Missing ending double quotation mark Pushpin Errors reported Figure 2-12 Syntax error message listing C# Programming: From Problem Analysis to Program Design

Creating an Application – ProgrammingMessage Example Figure 2-13 Problem specification sheet for the ProgrammingMessage example C# Programming: From Problem Analysis to Program Design

ProgrammingMessage Example (continued) Figure 2-14 Prototype for the ProgrammingMessage example C# Programming: From Problem Analysis to Program Design

ProgrammingMessage Example (continued) Pseudocode would include a single line to display the message “Programming can be FUN!” on the output screen Figure 2-15 Algorithm for ProgrammingMessage example C# Programming: From Problem Analysis to Program Design

ProgrammingMessage Example (continued) Figure 2-16 Recommended deletions May want to remove the XML comments (lines beginning with ///) Change the name Delete [STAThread] Depending on your current settings, you may not need to make some of these changes Can replace with static void Main( ) Replace TODO: with your program statements C# Programming: From Problem Analysis to Program Design

ProgrammingMessage Example (continued) /* Programmer: [supply your name] Date: [supply the current date] Purpose: This class can be used to send messages to the output screen. */ using System; namespace ProgrammingMessage { class ProgrammingDisplay static void Main( ) Console.WriteLine(“Programming can be”); Console.WriteLine(“FUN!”); Console.Read( ); } Complete program listing C# Programming: From Problem Analysis to Program Design

Chapter Summary Types of applications developed with C# Web applications Windows graphical user interface (GUI) applications Console-based applications Framework class library groups by namespaces Namespaces group classes Classes have methods Methods include program statements C# Programming: From Problem Analysis to Program Design

Chapter Summary (continued) Visual Studio includes .NET Framework Editor tool, compiler, debugger, and executor Compile using Build Run using Start or Start without Debugging Debugging Syntax errors Run-time errors Use five steps to program development to create applications C# Programming: From Problem Analysis to Program Design