0% found this document useful (0 votes)
13 views105 pages

Inf1030 01 Introduction To Computing and Application Development

Uploaded by

hahepo5515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views105 pages

Inf1030 01 Introduction To Computing and Application Development

Uploaded by

hahepo5515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 105

INF1030 – “Basics in C# Programing”

Introduction to Computing and


Application Development

1
Objectives
• Learn about the history of computers

• Differentiate between system and


application software

• Investigate the steps of software


development

• Explore different programming


methodologies

2
Objectives
• Discover why C# is being used today for
software development

• Distinguish between the different types of


applications that can be created with C#

• Explore an application written in C#

• Examine the basic elements of a C#


program

3
Objectives (continued)
• Compile, run, build, and debug an application

• Create an application that displays output

4
History of Computers
• Computing dates back 5,000 years
• Currently in fourth or fifth generation of
modern computing
• Pre-modern computing
– Abacus

– Pascaline (1642)

5
History of Computers
– Analytical Engine (1830 – Charles Babbage
& Lady Lovelace)

6
History of Computers
(continued)
• First generation distinguished by use of
vacuum tubes (mid-1940s)

7
History of Computers
(continued)
• Second generation distinguished by use of
transistors (mid-1950s)

8
History of Computers
(continued)
• Third generation – transistors squeezed
onto small silicon discs (1964-1971)
– Computers became smaller
– Operating systems first seen

9
History of Computers (continued)
• Fourth generation – computer
manufacturers brought computing to
general consumers
– Introduction of IBM personal computer (PC)
and clones (1981)

10
History of Computers (continued)
• Fifth generation – more difficult to define
– Computers accept spoken word instructions
– Computers imitate human reasoning through
AI
– Computers communicate globally
– Mobile and wireless applications are growing

11
System and Application
Software
• Software consists of programs
– Sets of instructions telling the computer
exactly what to do
• Two types of software
– System
– Application
• Power of what the computer does lies with
what types of software are available

12
System Software
• System software is more than operating
systems
• Operating System
– Loaded when you power on the computer
– Examples include Windows, Linux, Android,
iOS
– Includes file system utilities, communication
software
• Includes compilers, interpreters, and
assemblers
13
Software (continued)

14
Application Software
• Application software performs a specific task
– Word processors, spreadsheets, payroll,
inventory
• Writes instructions using a high-level
programming language
– C#, Java, Visual Basic
• Compiler
– Translates instructions into machine-readable
form
– First checks for rule violations
• Syntax rules – how to write statements 15
Software Development
Process
• Programming is a process of problem
solving

• How do you start?

• Number of different approaches, or


methodologies

• Successful problem solvers follow a


methodical approach
16
Steps in the Program
Development Process
1. Analyze the problem
2. Design a solution
3. Code the solution
4. Implement the code
5. Test and debug

17
Steps in the Program
Development Process
(continued)
• Software development
process is iterative
• As errors are discovered,
it is often necessary to
cycle back to a previous
phase or step
Figure 1. Steps in the
software development
process
18
Step 1: Analyze the Problem

• Precisely what is software supposed to


accomplish?

• Understand the problem definition

• Review the problem specifications

19
Analyze the Problem (continued)

20
Analyze the Problem (continued)
• What kind of data will be available for input?
• What types of values (i.e., whole numbers,
alphabetic characters, and numbers with decimal
points) will be in each of the identified data
items?
• What is the domain (range of the values) for
each input item?
• Will the user of the program be inputting values?
• If the problem solution is to be used with
multiple data sets, are there any data items that
stay the same, or remain constant, with each
set? 21
Analyze the Problem (continued)
May help to see sample input for each data item

22
Step 2: Design a Solution
• Several approaches
– Procedural and object-oriented methodologies
• Careful design always leads to better solutions
• Divide and Conquer
– Break the problem into smaller subtasks
– Top-down design, stepwise refinement
• Object-oriented approach
– Focus is on determining data and methods (behaviors)

23
Design
• Object-oriented approach

• Class diagram

– Divided into three sections


• Top portion identifies the name of the class

• Middle portion lists the data characteristics

• Bottom portion shows what actions are to be


performed on the data

24
Class Diagram

25
Design (continued)
• Structured procedural approach
– Process oriented
– Focuses on the processes that data undergoes
from input until meaningful output is produced
• Tools used
– Flowcharts
– Pseudocode, structured English
• Algorithm written in near English
statements for pseudocode

26
Design a Solution (continued)
• Algorithm
– Clear, unambiguous, step-by-step process for
solving a problem
– Steps must be expressed so completely and so
precisely that all details are included
– Instructions should be simple to perform
– Instructions should be carried out in a finite
amount of time
– Following the steps blindly should result in the
same results

27
Step 3: Code the Solution
• After completing the design, verify the
algorithm is correct
• Translate the algorithm into source code
– Follow the rules of the language
• Integrated Development Environment
(IDE)
– Visual Studio
• Tools for typing program statements,
compiling, executing, and debugging
applications
28
Step 4: Implement the Code
• Source code is compiled to check for rule
violations
• C# → Source code is converted into
Microsoft Intermediate Language (IL)
– IL is between high-level source code and native
code
– IL code not directly executable on any computer
– IL code not tied to any specific CPU platform
• Second step, managed by .NET’s Common
Language Runtime (CLR), is required

29
Implement the Code
(continued)
• CLR loads .NET classes
• A second compilation,
called a just-in-time
(JIT) compilation, is
performed
– IL code is converted to
the platform’s native
code
Figure 1-6 Execution
steps for .NET
30
Step 5: Test and Debug
• Test the program to ensure consistent results
• Test Driven Development (TDD)
– Development methodologies built around testing
• Plan your testing
– Test plan should include extreme values and
possible problem cases
• Logic errors
– Might cause abnormal termination or incorrect
results to be produced
– Run-time error is one form of logic error

31
Programming Methodologies
• Structured Procedural Programming
– Emerged in the 1970s

• Object-Oriented Programming
– Newer approach

32
Structured Procedural
Programming
• Associated with top-down design
– Analogy of building a house
– Write each of the subprograms as separate
functions or methods invoked by a main
controlling function or module

• Drawbacks
– During software maintenance, programs are
more difficult to maintain
– Less opportunity to reuse code
33
Flowchart
• Oval – beginning and end
• Rectangular – processes
• Parallelogram – inputs and
output
• Diamond – decision to be
made
• Flow line
Figure 1-7 Flowchart
symbols and their
interpretation
34
Pseudocode or Structured
English
• Tool used to develop an algorithm
• Steps written in pseudo or near code
format
– Combination English statements and the chosen
programming language
– Verbs like compute, calculate, sum, print, input,
display are used
– Loops are shown with while or do while
– if and if/else used for decisions

35
36
Object-Oriented
Programming
• Construct complex systems that model
real-world entities
• Facilitates designing components
• Assumption is that the world contains a
number of entities that can be identified
and described

37
Object-Oriented Methodologies
• Abstraction
– Through abstracting, determine attributes (data) and
behaviors (processes on the data) of the entities
• Encapsulation
– Combine attributes and behaviors to form a class
• Polymorphism
– Methods of parent and subclasses can have the same
name, but offer different functionality
• Invoke methods of the same name on objects of
different classes and have the correct method
executed

38
Class Diagram

39
Evolution of C# and .NET
• Programming Languages
– 1940s: Programmers toggled switches on the
front of computers
– 1950s: Assembly languages replaced the binary
notation

40
Evolution of C# and .NET
(continued)
• Late 1950s: High-level languages came into
existence
• Today: More than 2,000 high-level
languages
– Noteworthy high-level programming languages
are C, C++, Visual Basic, Java, and C#

41
.NET
• Not an operating system
• An environment in which programs run
• Resides at a layer between operating
system and other applications
• Offers multi-language independence
– One application can be written in more than one
language
• Includes over 2,500 reusable types
(classes)
• Enables creation of dynamic Web pages
and Web services
42
C# Program Running

43
Why C#
• One of the newer programming languages
• Conforms closely to C and C++
• Has the rapid graphical user interface
(GUI) features of previous versions of
Visual Basic
• Has the added power of C++
• Has the object-oriented class libraries
similar to Java

44
Why C# (continued)
• Can be used to develop a number of
applications
– Software components
– Mobile applications
– Dynamic Web pages
– Database access components
– Windows desktop applications
• Open source
• Partnership with Xamarin
45
C# Relationship to .NET
• Many compilers targeting the .NET
platform are available
• C# was used most heavily for development
of the .NET Framework class libraries
• C#, in conjunction with the .NET
Framework classes, offers an exciting
vehicle to incorporate and use emerging
Web standards

46
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
47
Web Applications (continued)
• 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

48
Web Applications

49
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, text boxes,
and labels
• Use drag-and-drop feature of Visual
Studio

50
Windows Applications
(continued)

51
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

52
Output from the First C#
Program

Console-based
application
output

53
Exploring the First C#
From Example 1-1
Program
line 1 // This is traditionally the first program written.
line 2 using System;
line 3 using static System.Console; Comments
line 4
in green
line 5 namespace HelloWorldProgram
line 6 {
line 7 class HelloWorld Keywords
line 8 { in blue
line 9 static void Main( )
line 10 {
line 11 WriteLine("Hello World!");
line 12 ReadKey( );
line 13 }
line 14 } 54
line 15 }
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

55
Comments

• Make the code more readable

• Three types of commenting syntax


– Inline comments

– Multiline comments

– XML documentation comments

56
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.
57
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.
*/

58
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
• Advanced documentation technique used
for XML-style comments
• Compiler generates XML documentation
from them
59
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;

60
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: { }
61
Namespace (continued)
Predefined namespace
From Example 1-1 (System) – part of
.NET FCL

line 1 // This is traditionally the first program written.


line 2 using System;
line 5 namespace HelloWorldProgram
line 6 {
User-defined
namespace
line 15 } Body of user-
defined
namespace

62
using Directive
• In addition to referencing namespaces with
using directive, can also identify specific
static classes
– New feature available with Visual Studio 2015
• Cannot specify class name with prior versions
– Enables you to omit class name when referencing
its static class members

• Syntax
– using static namespaceIdentifier.classname;
63
Static Class Reference
From Example 1-1
line 3 using static System.Console;

line 10 {
line 11 WriteLine(“Hello World!”);
line 12 ReadKey( );
line 13 }
Reference to class
line 15 } members without
fully qualifying.

64
Class Definition

• 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

65
Class Definition (continued)

line 7 class HelloWorld


line 8 {

line 14 } User-
defined
class

66
Class Definition (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( )

67
Main( ) Method
• “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
68
Main( ) Method Heading

line 9 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

69
Method Body − Statements
• Enclosed in curly braces
– Example Main( ) method body
line 9 static void Main( )
line 10 {
line 11 WriteLine("Hello World!");
line 12 ReadKey( );
line 13 }
• Includes program statements
– Calls to other method
• Here Main( ) calling WriteLine( ) and ReadKey( )
methods
70
Method Calls
line 11 WriteLine("Hello World!");

• Program statements
• WriteLine( ) → member of the Console
class
• Main( ) invoking WriteLine( ) method
• Member of Console class
• Method call ends in semicolon

71
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


– WriteLine( );
– WriteLine("WriteLine( ) is a method.");
– Write("Main( ) is a method.");
72
Program Statements (continued)

• Read( ) and ReadKey( ) accept one character


from the input device
• ReadLine( ) accepts string of characters
– 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
73
Escape Sequence Characters

Table 1-1 Escape sequences


74
C# Elements

75
Compiling, Building, and
Running an Application
• Begin by opening Visual Studio
• Create new project
– Select New Project on the Start page
– OR use File → New, Project option

76
Create New Project

77
Create New Project

78
Create New Project

79
Create New Project

80
Create New Project

81
Create New Project

82
Code Automatically Generated

83
Code Automatically Generated

84
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

85
Rename Source Code Name
Clicking Yes
causes the class
name to also be
renamed

86
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 executing code that has not been
compiled, automatically compiles first
• Start option does not hold output screen
→ output flashes quickly
– Last statement in Main( ), could add ReadKey( );
87
Build Visual Studio Project

88
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

89
Error Listing

90
Creating an Application –
ProgrammingMessage
Example

91
ProgrammingMessage Example

92
ProgrammingMessage
Example

• Pseudocode would include


a single line to display the
message "Programming can
be FUN!" on the output
screen

Figure 1-23 Algorithm for


ProgrammingMessage example
93
ProgrammingMessage
Example

Depending on your current


settings, you may not need to
make some of these changes
94
/* Programmer: [supply your name]
Date: [supply the current date]
Purpose: This class can be used to send messages to
the output screen
*/
using System;
using static System.Console; Complete
namespace ProgrammingMessage program
{ listing
class ProgrammingMessage
{
static void Main( )
{
WriteLine("Programming can be");
WriteLine("FUN! ");
ReadKey( );
}
} 95
}
Coding Standards
• Following standards leads to better
solutions
• Following standards makes your code more
maintainable
• Following standards saves you time when
you go to modify your solution
• Developing standards that you consistently
adhere to increases your coding efficiency

96
Coding Standards -
Pseudocode Suggestions
• Use action verbs to imply what type of
activities should be performed
• Group items and add indentation to imply
they belong together
• Use keywords like while or do while to
imply looping
• Use if or if/else for testing the contents
of memory locations

97
Resources
C# Language Specifications –
http://www.microsoft.com/en-
us/download/details.aspx?id=7029
C# Programmers Guide –
http://msdn.microsoft.com/en-
us/library/67ef8sbd.aspx
History of computing project –
http://www.thocp.net/
98
Resources
Pascaline –
http://www.thocp.net/hardware/pascaline.
htm
The Microsoft .NET Web site –
http://www.microsoft.com/net
The Visual Studio home page –
http://msdn2.microsoft.com/en-
us/vcsharp/default.aspx
99
Resources
GitHub Open Source Repository –
https://github.com/Microsoft/dotnet
Mono Cross Platform Open Source
Foundation –
http://www.mono-project.com
Xamarin cross-platform mobile development –
https://xamarin.com/
Microsoft Developer Network –
http://msdn.microsoft.com/en-us/ 100
Resources
U.S. Census Data on Computer and Internet
Use –
http://www.census.gov/cps/
Bureau of Labor Statistics Occupational
Outlook Handbook –
http://www.bls.gov/ooh/Computer-and-
Information-Technology/Software-
developers.htm
.NET Foundation for Open Source
Development –
http://www.dotnetfoundation.org/ 101
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
102
Summary (continued)
• Programming methodologies
– Structured procedural
– Object-oriented
• C#
– One of the .NET managed programming
languages
– Object-oriented
– 2001 EMCA standardized
– Provides rapid GUI development of Visual Basic
– Provides number crunching power of C++
– Provides large library of classes similar to Java
103
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 of program development to
create applications

104
Questions?

105

You might also like