Nothing Special   »   [go: up one dir, main page]

CC102 Module 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

MAKILALA INSTITUTE OF SCIENCE AND TECHNOLOGY

COLLEGE OF TECHNOLOGY AND INFORMATION SYSTEM (CTIS) DEPARTMENT


CONCEPCION, MAKILALA, COTABATO, 9401
mistmakilala2014@gmail.com

Course Title: Computer Programming 1 Instructor: Jethro Ryan C. Elipian


Module No.: 1 Mobile No.:
Duration: 2 week EmailAddress: jethroryan143@gmail.com

I. LEARNING OUTCOME(S):
At the end of the lesson, you are expected to:
 Recall the history of computers
 Compare system and application software
 Name the steps of software development
 Describe the different programming methodologies
 Defend why C# is being used today for software development
 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
 Compile, run, build, and debug an application
Create an application that displays output

II. TOPIC(S): INTRODUCTION TO COMPUTER PROGRAMMING


III.References:
http://searchcio.techtarget.com
http://www.igrafx.com
https://www.happyfox.com>what-is-BPM
IV. Course Content

A. HISTORY OF COMPUTER

Computing dates back some 5000 years.

- Abacus - Many considered as the first computer


- Used by merchants of the past and present for trading transactions,
- a calculating device that uses a system of sliding beads on a rack for addition and subtraction.

- Pascaline - a another calculating device was created in 1642


- had eight movable dials on wheels that could calculate sums up to eight figures long
- both the Abacus and Pascaline could perform only addition and subtraction

- Analytical Engine - first general-purpose computer created in 1830s


- designed by Charles Babbage and his assistant, Lady Augusta Ada Bryon
- Key components included:
 Input devices for providing instructions and data.
 Memory storage using punch cards, similar to early computer programming.
 A control unit capable of processing instructions in any sequence.
 Output devices to display or print results.

First Generation

- in the mid-1940s the first generation of general-purpose machines created for strategic types of calculations
- the use of large vacuum tubes as electronic components.
- These computers were enormous, occupying significant physical space.
- difficult to program and limited in functionality
- operating instructions made to order for a specific task

Second Generation

- Transistors – invented in 1956


- Replaced vacuum tubes with transistors as electronic components

1
- Smaller, faster, more reliable, and more energy efficient than vacuum tubes

- FORTRAN (FORmula TRANslation):


- Developed in the mid-1950s by IBM (International Business Machines Corporation).
- Designed for scientific and engineering calculations, particularly for complex mathematical formulas.
 Provided support for mathematical operations, including arithmetic, trigonometric, and
logarithmic functions.
- Considered one of the earliest high-level programming languages.

- COBOL (COmmon Business-Oriented Language):


- Developed in the late 1950s by a committee of experts.
- Created to address business data processing and administrative tasks.
 Designed for data manipulation, file handling, and report generation.
- Emphasizes readability for business applications.

Third Generation Computers (1964–1971):

- Transition to smaller and more efficient computers:


- Utilized semiconductor chips (silicon discs) for electronic components.
- These chips contained thousands of transistors, making them significantly more compact and reliable
than earlier technologies.
- Introduction of operating systems:
- Operating systems (OS) like IBM's OS/360 and DEC's OS/8 emerged.
- OS allowed computers to manage hardware resources and execute multiple programs concurrently.
- Users could run several programs simultaneously, enhancing overall productivity
- Ongoing miniaturization of electronic components:
- Chips became smaller and more densely packed with transistors.
- This trend led to increased computational power while reducing the cost of manufacturing.
- Breakthrough with the Intel 4004 chip:
- Introduced in 1971, it was a microprocessor that integrated CPU (Central Processing Unit), memory,
and I/O (Input/Output) controls onto a single chip.

Fourth Generation

- computer manufacturers tried to bring computing to general consumers.


- In 1981, IBM introduced its personal computer (PC).
- 1980s computer use as clones of the IBM PC made the personal computer even more affordable and
accessible.
- Development of Graphical User Interfaces (GUIs)
- GUIs replaced text-based interfaces with graphical elements like icons and windows.
- mouse
- a handheld input device, made it easier for users to interact with the computer.
- This shift in user interface design made computers more user-friendly and visually appealing.

Fifth Generation

o These computers can accept spoken instructions.


o They can imitate human reasoning through artificial intelligence (AI).
o They can communicate globally by transmitting digital media.
- Mobile Apps - are growing in importance and are being used for various purposes, including:
- Healthcare professionals using handheld devices for patient record updates.
- Delivery truck drivers using GPS for location verification.

B. SYSTEM AND APPLICATION SOFTWARE


- Software consists of programs,
- programs - which are sets of instructions telling the computer exactly what to do
 The instructions might tell the computer to add up a set of numbers, compare two names, or
make a decision based on the result of a calculation.

2
SYSTEM SOFTWARE
- System software is loaded when you power on the computer.
Examples:
Operating Systems: Windows, macOS, Linux, Unix and etc.

- Operating systems such as Windows 8, Android, iOS, Windows 7, and Linux are types of programs that
oversee and coordinate the resources on the machine.
- Included are file system utilities, small programs that take care of locating files and keeping up with the
details of a file’s name, size, and date of creation.

As you begin learning software development, you will write instructions for the computer using a programming
language.

Programming language - is a set of instructions written by a programmer to deliver instructions to the computer to
perform and accomplish a task.

Modern programming languages are designed to be easy to read and write. They are called high level
languages because they are written in English-like statements.

The programming language you will be using is C# (pronounced see sharp).

C# - It is an object-oriented programming language created by Microsoft that runs on the .NET Framework. C# has
roots from the C family, and the language is close to other popular languages like C++ and Java.

Just as the English language has rules for sentence construction, programming languages such as C# have a set
of rules, called syntax, that must be followed

Syntax - Rules for constructing valid statements in a programming language.

Compilers do not convert any statements into machine language until all syntax errors are removed.

Compiler - translates high-level programming code (e.g., C#) into machine-readable format.
- Checks for syntax errors in the entire code before conversion.

Unlike compilers, which look at entire pieces of code, interpreters check for rule violations line by line. If the
line does not contain an error, it is converted to machine language. Interpreters are normally slower than compilers
Interpreter - Translates and executes code line by line.
- Many languages offer both compilers and interpreters, including C, BASIC, Python, and
Lisp.
Assemblers convert the assembly programming language, which is a low-level programming language, into
machine code. Low-level programming languages are closer to hardware.

APPLICATION SOFTWARE
- consists of programs developed to perform a specific task. The games you might play or the search
engines you use on the Internet are types of application software.
Example:
Word Processors: Microsoft Word, Google Docs, LibreOffice Writer.
Spreadsheets: Microsoft Excel, Google Sheets, LibreOffice Calc.
Video Editing: Adobe Premiere Pro, Final Cut Pro, DaVinci Resolve.
Gaming: Minecraft, Fortnite, World of Warcraft.

C. STRUCTURED PROCEDURAL PROGRAMMING


This approach emerged in the 1970s and is still in use today. Procedural programming is process
oriented focusing on the processes that data undergoes from input until meaningful output is produced. This approach
is very effective for small stand-alone applications. The five steps for software development–analyze, design, code,
implement, and test and debug–which were identified in the preceding section, work well for the structured procedural
approach.

During design, processing steps are defined in terms of an algorithm. Any formulas or special processing steps are
included in the algorithm. To think algorithmically, programmers use a number of tools. One such tool used is a
flowchart. Figure 1-7 shows some of the symbols used in a flowchart for the construction of an algorithm.
3
Another tool used to develop an algorithm during design is pseudocode. As the name implies, with pseudocode, steps
are written in pseudo or approximate code format, which looks like English statements. The focus is on determining and
writing the processes or steps involved to produce the desired output. With pseudocode, the algorithm is written using a
combination of English statements and the chosen programming language, such as C#.

Algorithm should include a step-by-step solution for solving the problem. 3 steps Input, Process and Output.

D. Evolution of C# and .NET

Programming Languages In the 1940s, programmers toggled switches on the front of computers to enter
programs and data into memory. That is how some of the early programming began. Assembly languages were
designed to make the programmer’s job easier by using these mnemonic symbols instead of binary numbers. However,
the instructions depended on the particular CPU architecture. Statements to perform the same task differed from
computer to computer. Assembly languages are still considered low-level programming languages.

High-level languages came into existence in the late 1950s with FORTRAN (Formula Translator) and later COBOL
(Common Business Oriented Language). These languages were considered high-level languages because they were
designed to be accessible to humans, easy to read and write, and close to the English language.

Java was introduced in 1995 and was originally called Oak. It was originally designed to be a language for intelligent
consumer-electronic devices such as appliances and microwave ovens. Instead of being used for that purpose, the
business community used Java most heavily for Web applications because of the nature of the bytecode, which enabled
machine-independent language compiling. Because the bytecode does not target any particular computer platform and
must be converted to the language of the system running the application, this facilitates the development of code that runs
on many types of computers.

C# is one of the newer programming languages. It conforms closely to C and C++, but many developers consider it
akin to Java. There are a number of similarities between the languages. It has the rapid graphical user interface (GUI)
features of previous versions of Visual Basic, the added power of C++, and object-oriented class libraries similar to Java.
C# was designed from scratch by Microsoft to work with the new programming paradigm, .NET, and was the language
used most heavily for the development of the .NET Framework class libraries. C# can be used to develop any type of
software component, including mobile applications, dynamic Web pages, database access components, Windows
desktop applications, Web services, and console-based applications

When you think about C#, you should also understand its relationship to .NET. .NET is an environment in which
programs run and was designed to be a new programming paradigm. It is not an operating system, but rather a layer
between the operating system and other applications.

4
E. Why C#?

C# was the language created for .NET and was designed from scratch to work with .NET. A large number of classes
were included as part of .NET. These classes or templates were designed for reuse by any of the .NET-supported
languages. They reduce the amount of programming that needs to be done. These classes are called the .NET
Framework classes. Most of the .NET Framework classes were written using the C# programming language

C#, in conjunction with the .NET Framework classes, offers an exciting vehicle to incorporate and use emerging Web
standards, such as Hypertext Markup Language (HTML), Extensible Markup Language (XML), and Simple Object Access
Protocol (SOAP).

 Syntax:
 Syntax refers to the specific rules and structure that must be followed when writing instructions in a
programming language.
 It defines how statements, commands, and elements should be arranged and formatted.
 Syntax is unique to each programming language and ensures that code is written correctly.
 Source Code:
 Source code is the human-readable instructions written by a programmer to tell a computer what to do.
 It is written in a specific programming language and follows the syntax rules of that language.
 Source code is the original code that developers create.
 Native Code:
 Native code is the machine language that a computer's processor can understand and execute directly.
 Source code cannot be executed directly by a computer; it needs to be translated into native code.
 Compilation is the process of converting source code into native code using a compiler.
 Semantic Meaning:
 Semantic meaning refers to the specific purpose or intention behind each instruction statement in a
program.
 It defines how the statements should be used to achieve the desired outcome or task.
 Understanding semantic meaning is essential to writing code that behaves correctly and produces the
expected results.

F. Types of Applications Developed with C#


C# can be used to create several different types of software applications. Some of the most common applications are:
• Web applications
• Windows graphical user interface (GUI) applications
• Console-based applications

1. Web Applications
C# was built from the ground up with the Internet in mind. For this reason, programmers can use C# to quickly build
applications that run on the Web for end users to view through browser-neutral user interfaces (UIs).
Using Web forms, which are part of the ASP.NET technology, programmable Web pages can be built that serve as a
user interface (UI) for Web applications. ASP.NET is a programming framework that lets you create applications that run
on a Web server and delivers functionality through a browser, such as Microsoft Internet Explorer

5
2. Windows Applications
Windows applications are designed for desktop use and for a single platform. They run on PC desktops much
like your favorite word-processing program. Writing code using C# and classes from the System.Windows.Forms
namespace, applications can be developed to include menus, pictures, drop-down controls, and other widgets you
have come to expect in a modern desktop application.
 .NET uses the concept of namespace to group types of similar functionality
 The System.Windows.Forms namespace is used as an umbrella to organize classes needed to create
Windows applications.

3. Console Applications
Console applications normally send requests to the operating system to display text on the command console
display or to retrieve data from the keyboard. From a beginners’ standpoint, console applications are the easiest to
create and represent the simplest approach to learning software development, because you do not have to be
concerned with the side issues associated with building GUIs.

G. Elements of a C# Program
I. Comments - are not considered instructions to the computer and, therefore, have no effect on the running of the
program. You can place comments anywhere in the program.

With C#, three types of commenting syntax can be added to a program: inline, multiline, and XML document
comments.

1. Inline Comments

6
An inline comment is indicated by two forward slashes // and is usually considered a one-line comment.

INLINE COMMENTS

2. Multiline Comments

For longer comments, multiline comments are available. A forward slash followed by an asterisk /* marks the
beginning of a multiline comment, and the opposite pattern */ marks the end. Everything that appears between the
comment symbols is treated as a comment. Multiline comments are also called block comments.

3. XML Documentation Comments

A third type of comment uses three forward slashes ///. This is an advanced documentation technique used for XML-
style comments. XML (Extensible Markup Language) is a markup language that provides a format for describing data
using tags similar to HTML tags. A C# compiler reads the XML documentation comments and generates XML
documentation from them.

XML Documentation Comments

You will be using the inline // and multiline /* */ comments for the applications you will develop in this book.

II. Namespace
The namespace does little more than group semantically related types under a single umbrella. Example
1-1 illustrates how a namespace called HelloWorldProgram is created. HelloWorldProgram is an identifier,
simply a user-supplied or user-created name. As noted in the previous section, you will create many names
(identifiers) when programming in C#. Rules for creating identifiers are discussed in Chapter 2. You can define
your own namespace and indicate that these are names associated with your particular application.
Each namespace must be enclosed in curly braces { }.

7
III. Class Definition
As C# is an object-oriented language, everything in C# is designed around a class, which is the building
block of an object-oriented program. C# doesn’t allow anything to be defined outside of a class. Every program
must have at least one class. Classes define a category, or type, of object. Many classes are included with
the .NET Framework. Programs written using C# can use these predefined .NET classes or create their own
classes.
Classes are used to define controls such as buttons and labels, as well as types of things such as
Student, Captain, and Employee. The word class is a keyword. Like namespaces, each class definition must be
enclosed in curly braces { }.

IV. Main( ) Method


The Main( ) method plays a very important role in C#. This is the entry point for all applications. This is
where the program begins execution. The Main( ) method can be placed anywhere inside the class definition.
A method is a collection of one or more statements combined to perform an action. Methods are similar
to C++ functions. The heading for the method contains its signature, which includes the name of the method
and its argument list. Return types and modifiers, such as public and static, are part of the heading, but not
considered part of the signature. The heading line for the Main( ) method begins with the keyword static, which
implies that a single copy of the method is created, and that you can access this method without having an
object of the class available. More details regarding static are discussed in subsequent sections. For now,
remember that Main( ) should include the static keyword as part of its heading.
The second keyword in the heading is void. Void is the return type. Typically, a method calls another
method and can return a value to the calling method. Remember that a method is a small block of code that
performs an action. As a result of this action, a value might be returned. If a method does not return a value, the
void keyword is included to signal that no value is returned. When the method does return a value, the type of
value is included as part of the heading

V. Method Body Statements


The statement in the Main( ) method is a call to another method named WriteLine( ). A method call is the
same as a method invocation. Like Main( ), WriteLine( ) has a signature. The heading along with the complete
body of the method is the definition of the method. When called, WriteLine( ) writes the string argument that
appears inside the parentheses to the standard output device, a monitor. After displaying the string, WriteLine( )
advances to the next line, as if the Enter key had been pressed.
A quick way to identify a method is by looking for parentheses; methods always appear with parentheses
( ). A call to any method, such as WriteLine( ), always includes a set of parentheses following the method name
identifier, as do signatures for methods.
The Console class contains the standard input and output methods for console applications. Methods in
this class include Read( ), ReadKey( ), ReadLine( ), Write(), and WriteLine(). The method Write( ) differs from
WriteLine( ) in that it does not automatically advance the carriage return to the next line when it finishes. The
following lines would produce the same result as the single line Console. WriteLine("Hello World!");

Console.Write("Hello");
Console.Write(" ");
Console.WriteLine("World!");

An invisible pointer moves across the output screen as the characters are displayed. As new characters
are displayed, it moves to the next position and is ready to print at that location if another output statement is sent.
Notice the second statement in the preceding code, Console.Write(" "); this places a blank character between the
two words. After displaying the space, the pointer is positioned and ready to display the W in World. The output
for both of the preceding segments of code is:

Usually, the characters inside the double quotes are displayed exactly as they appear when used as an
argument to Write( ) or WriteLine( ). An exception occurs when an escape character is included.

8
When an escape sequence is encountered inside the double quotes, it signals that a special character is
to be produced as output. The output of the statement:

Console.Write("What goes\nup\nmust come\tdown."); is

Four methods in Console class

 WriteLine():
 is used to display text.
 Outputs text or data to the console window.
 Moves the cursor to the next line after displaying the text.
 Read():
 is used to read a single character from the user.
 Accepts input from a standard input device (usually the keyboard).
 Waits for a user to input a character.
 ReadKey():
 is used to pause the program until any key is pressed.
 Waits for a user to press any key.
 Unlike Read(), it doesn't require the user to press Enter; it captures the keypress instantly.
 Often used to pause a program until the user interacts by pressing any key.
 ReadLine():
 is used to read a line of text (e.g., a user's name) until the Enter key is pressed.
 Accepts input from a standard input device (keyboard).
 Allows the user to input multiple characters, forming a complete line of text.
 Waits for the user to press the Enter key to submit the input.
 Commonly used for inputting textual data, such as user names or messages.

9
Figure 1-15 shows how namespace, class, method, and statements are related.

H. Compiling, Building, and Running an Application

I. Typing Your Program Statements


You have a couple of options for writing code using C#.

1. One approach to developing applications is to type the source code statements using a simple text
editor (such as Notepad) and follow that up by using the DOS command line to compile and execute
the application.
- This technique offers the advantage of not requiring significant system
resources, but requires that you must know exactly what to type.
2. A second approach is to use the Visual Studio integrated development environment (IDE), and this
chapter introduces you to Visual Studio. The IDE is an interactive environment that enables you to type
the source code, compile, and execute without leaving the IDE program.
- Because of the debugging and editing features that are part of the IDE, you will find it much
easier to develop applications if Visual Studio is available.

II. Compiling the Source Code Using Visual Studio IDE


Begin by opening Visual Studio. Create a new project by either selecting the New Project button on the
Start page or by using the File, New, Project option.

As shown in Figure 1-16, a list of project types appears in the middle window. There are a number of
templates that can be used within the IDE. To develop a C# console application, select Visual C# and
Console Application for the Template. Using the Browse button beside the Location text box, navigate to
the location where you want to store your projects. The name of the project is HelloWorldProgram. You can
remove the check mark, if it is present, from the check box beside the Create directory for solution option.
Having that option selected creates another directory layer. This extra folder is not necessary for the types of
applications you will be creating.

10
Selecting the template determines what type of code is generated by the IDE. Figure 1-17 shows the
code that is created automatically when you create a console application.

If you use the Solution Explorer window to change the source code filename to HelloWorld.cs, a
message, as shown in Figure 1-18, will be displayed asking whether you want to change all references to that
new name. You can make this change in the Solution Explorer window by either right-clicking on the name in the
Solution Explorer window and selecting the Rename option, as is shown in Figure 1-18, or by simply clicking on
the name. If the Solution Explorer window is not active on your desktop, select View, Solution Explorer. Be
sure to include the .cs file extension when you rename the file.

11
To compile the HelloWorldProgram project, select the Build HelloWorldProgram option on the Build
menu. The name HelloWorldProgram follows the Build option because HelloWorldProgram is the name of the
project. Projects that contain more than one class are compiled using the Build Solution option.
To run the application, you can click Start Debugging or Start Without Debugging on the Debug menu
bar, as illustrated in Figure 1-19. If you attempt to execute code that has not been compiled (using Build), the
smart IDE compiles the code first. Therefore, many developers use the shortcut of bypassing the Build step.

When you ran the application using the Start Debugging option, you probably noticed that the output
flashes on the screen and then disappears. You can hold the output screen if you include a call to the Read( ) or
ReadKey( ) methods.

Another option to hold the command windows in Visual Studio is to select Debug, Start Without
Debugging instead of Debug, Start Debugging to execute your program. Notice in Figure 1-19 that Start
Without Debugging is the option immediately below the Start Debugging option. If you select Debug, Start
Without Debugging, it is not necessary to add the additional Console.Read( ) or ReadKey( ); statements. When
you use the Start Without Debugging option for execution, the user is prompted to ‘‘Press any key to continue,’’

I. Debugging an Application

1. Syntax Errors
When you type source code statements into the editor, you are apt to make typing errors by
misspelling a name or forgetting to end a statement with a semicolon. These types of errors are
categorized as syntax errors and are caught by the compiler.

12
The error messages are displayed in the Error List window found at the bottom of the IDE. The IDE also
underlines the supposed location of the problem. You can also double-click on any of the error messages to go
directly to the line flagged by the compiler. If the Error List tab is not visible on your screen, you can select Error
List from the View menu.
A pushpin icon appears in the upper-right corner of all tool windows such as that shown in the Error List
window. When the pushpin stands up like a thumbtack, the window is docked in place; thus, the Error List
window is docked in place

2. Run-time Errors
Run-time errors are much more difficult to detect than syntax errors. A program containing run-time
errors might compile without any problems, run, and produce results. Run-time errors can also cause a
program to crash. A program might be written to retrieve data from a file. If that file is not available, when the
program runs, a run-time error occurs. Another type of run-time error is division by zero.
Many times, a program compiles and executes without errors, but does not perform as expected. If the
results are incorrect, the associated error is called a logic error. Logic errors are not identified until you look
closely at the results and verify their correctness. For example, a value might not be calculated correctly. The
wrong formula might be used. Failing to understand the problem specification fully is the most common
culprit in logic errors. It is not enough to produce output; the output must be a correct solution to the problem.

13

You might also like