m jamil. much of human behavior and thought is characterized by logical sequences. since childhood,...
TRANSCRIPT
M Jamil
Introduction to Programming
What is Programming?
Much of human behavior and thought is
characterized by logical sequences. Since
childhood, you have been learning how to act, how
to do things. And you have learned to expect
certain behavior from other people.
What is Programming?
Programming Planning, scheduling, or
performing a task or an event.
Computer A programmable device that can
store, retrieve, and process data.
Computer Programming The process of
planning a sequence of steps for a computer to
follow
How Do We Write a Program?
To write a sequence of instructions for a computer
to follow, we must go through a two-phase
process:
Problem solving
Implementation
Problem Solving Phase1. Analysis and Specification. Understand
(define) the problem and what the solution
must do
2. General Solution (Algorithm). Develop a
logical sequence of steps to be used to solve
the problem.
3. Verify. Follow the steps exactly to see if the
solution really does solve the problem.
Implementation Phase1. Concrete Solution (Program): Translate the
algorithm into a programming language.
2. Test: Have the computer follow the
instructions. Then manually check the results.
If you find errors, analyze the program and the
algorithm to determine the source of the
errors, and then make corrections.
Programming Process
Program
To get a computer to do something, you (or
someone else) have to tell it exactly – in detail -
what to do. Such a description of "what to do" is
called a program, and programming is the activity
of writing and testing such programs.
Program
Start with x and y
y=0?
Print the Result=x/y;
Yes
N0
A simple program
1. Take values of x and y
2. Chech y=0 or not.
3. If y=0. Take values of x and y
again
4. Else show the result after
dividing
Programmer
Computers are built by people for the use of
people. A computer is a very generic tool; it
can be used for an unimaginable range of
tasks. It takes a program to make it useful to
someone. In other words, a computer is just a
piece of hardware until someone - some
programmer - writes code for it to do
something useful. We often forget about the
software. Even more often, we forget about
the programmer.
Programmer
Sources of disinformation (e.g. movies) have
assigned largely negative images to
programmers.
• Friendless, fat, ugly nerd with no social
skills.
• Love video games and break into other
people's computers.
• Likely to want to destroy the world as he is
to want to save it.
Programmer
Obviously, milder versions of such cartoons
exist in real life, but in our experience they
are no more frequent among software
developers than they are among lawyers,
police officers, car salesmen, journalists,
artists, or politicians.
Programmer
Think about the applications of computers you
know from your own life. Were they done by a
loner in a dark room? Of course not; the
creation of a successful piece of software,
computerized gadget, or system involves
dozens, hundreds, or thousands of people
performing a puzzling set of roles.
Programmer
The person who have ability to transform the
ideas to program using programming
techniques.
A programmer is someone who writes
computer software. The term programmer can
be used to refer to a software developer,
software engineer, computer scientist, or
software analyst.
Programmer
The range of roles of a programmer is huge
an. made even more confusing by the tittles
varying from organization to organization:
Engineer
Programmer
Developer
Architect
Member of Technical staff
Analyst
Programmer
There are even organizations that let titles
employees pick their own titles. A
programmer may over a short period of time
interact With a wide range of people from
application areas, such as biologists, engine
designers, lawyers, car salesmen, medical
researchers and animators. Someone may also
be a programmer at times and fill non-
programming roles at other stages of a
professional career.
Programming
Programming refers to the technique used to:
Determine how the computer should achieve a
task that the programmer would like it to.
Create a set of instructions that reflect the
steps required to achieve the desired result.
Programming Techniques
Superior coding techniques and programming
practices are hallmarks of a professional
programmer. The bulk of programming consists
of making many small choices, which collectively
attempt to solve a large set of problems. A
programmer's skill and expertise largely
determine the wisdom of those choices.
Programming Techniques
With the development of programming
languages the different programming techniques
also evolved. The distinguishable techniques are
listed below.
1. Unstructured or monolithic programming.
2. Procedural Programming
3. Modular Programming
4. Object oriented Programming
Unstructured Programming
The general structure
of a unstructured or
monolithic program
consists of global data
and statements which
modify the data and
finally it contains the
output statements.
Unstructured Programming
The program is executed from top to bottom,
statement by statement. If similar evaluations are
to be carried out at several places in the program,
for example, statement1 and statement2 in last
slide, all the statements concerning that evaluation
have to be repeated at all the places where the
evaluation is desired. This makes the program very
lengthy.
Procedural Programming
These programs are an improvement over the
monolithic programs. If a group of statements
carry out similar action at several places in the
program, such a group is taken out of the main
program and is placed in a subprogram called
procedure or function. In the main program the
functions are called. When a function is called,
the main program is paused and control shifts to
the subroutine till it is finished. Its return value
if any is fed to the main program which is
resumed from where it was left.
Procedural Programming
Procedural Programming
A procedural program is more structured. The
different procedures or subroutines can be
checked independently of the main program,
thus debugging becomes easier. It is also easier
to maintain the program. The drawback is that if
the subroutine is small and is called many times
in the program, the overload of calling makes the
program inefficient.
Modular Programming
Modular programming is a simple programming
technique that can be applied to any
programming language. It's as useful in C++
programming as it is in Java programming or
programming in C. In fact some programming
languages such as AJAX programming rely on it
completely. Without this simple idea today's
computer programmers would have an all but
impossible job to do.
Modular Programming
Modular programming can be used to break up a
large program into manageable units, or to
create code that can be easily re-used. A
modular program consists of a main module and
one or more auxiliary modules. Each module
originates from a separate source code file.
Modular Programming
Modular Programming
The main module is compiled as an EXE, and
calls functions in the auxiliary modules. The
auxiliary modules can be dynamically linked,
meaning they exist as separate executable files
(DLLs) which are loaded when the main EXE is
run; or they can be statically linked, meaning
they are compiled as object files or static
libraries (LIBs) that are combined with the main
module into a single executable file.
Object Oriented Programming
In this technique an important factor is the data
abstraction. The different procedures or
functions are built around the abstract data.
Thus the data and functions are encapsulated in
a single structure called ‘class’. The classes are
the bases of object oriented programming (OOP).
The classes create new data types besides the
fundamental types which are already defined in
C#.
Characteristics of OOPs
Followings are the major elements of object-
oriented languages in general, and C# in
particular.
Objects
Classes
Inheritance
Polymorphism
Encapsulation
Reusability
Characteristics of OOPs
Programming Language
A programming language is an artificial
language designed to express computations that
can be performed by a machine, particularly a
computer. Programming languages can be used
to create programs that control the behavior of a
machine, to express algorithms precisely, or as a
mode of human communication.
Where is Programming Used?Just about everywhere
Mars rovers, animation, graphics, Photoshop, GUI, OS, compilers, slides, chip design, chip manufacturing, semiconductor tools, etc.
Why programming?
•Most engineering activities involve software
Our civilization runs on software
Note: most programs do not run on things that look like a PC
Ships
DesignConstructionManagement
Monitoring Engine Hull design Pumps
Aircraft
CommunicationControlDisplay
Signal processing “Gadget” control Monitoring
Phones
Voice qualityUser interfacesBillingMobility
Switching Reliability Provisioning Images
Energy
ControlMonitoringAnalysisDesign
Communications Visualization Manufacturing
PC/workstation
There’s a lot more to computing than games, word processing, browsing, and spreadsheets!
Typical Industries for programmer Software Industry
• Web Development
• Business Applications
Medical Industry
Embedded Computing Devices• Home Applications
• Entertainment
• Communication Devices
What's C#The C# programming language is one of those
intermediate languages that programmers use to
create executable programs. C# combines the
range of the powerful but complicated C++
(pronounced “see plus plus”) with the ease of use
of the friendly but more verbose Visual Basic.
(Visual Basic’s newer .NET incarnation is almost on
par with C# in most respects. As the flagship
language of .NET, C# tends to introduce most new
features first.) A C# program file carries the
extension .cs.
C# is Flexible
Powerful
Easier to use
Visually Oriented
Internet Friendly
Secure
Programming Environment
Integrated Development Environment
An integrated development environment (IDE) also
known as integrated design environment or integrated
debugging environment is a software application that
provides comprehensive facilities to computer
programmers for software development. An IDE normally
consists of:
• A source code editor
• A compiler and/or an interpreter
• Build automation tools
• A debugger
MSVS 2010Microsoft Visual Studio 2010 is an Integrated
Development Environment (IDE) from Microsoft. It can
be used to develop console and graphical user interface
applications along with Windows Forms applications,
web sites, web applications, and web services in both
native code together with managed code for all
platforms supported by Microsoft Windows, Windows
Mobile, Windows CE, .NET Framework, .NET Compact
Framework and Microsoft Silverlight.
Step by Step on Using MSVS 20101- Start Microsoft Visual Studio 2010 and open file menu → New → Project
Step by Step on Using MSVS 20102- Click Visual C# tab then Select Windows
Step by Step on Using MSVS 20103- Select Empty Project
Select Empty Project
Step by Step on Using MSVS 20104- Give some proper Name to Project
Name the Project
Step by Step on Using MSVS 20105- Click OK button
Click OK
Step by Step on Using MSVS 20106- Right click the solution Add New Item
Select New Item
Step by Step on Using MSVS 20107- Visual C# items Code Codefile.
Select Click to Select Code
Step by Step on Using MSVS 20108- Give some appropriate name and click Add Button.
Give a Name e.g. ‘main’ Click Add
Step by Step on Using MSVS 20109- Now file is available in solution to edit. Write Code here
Write your code here’
Step by Step on Using MSVS 201010- Sample code “hello World”.
Say “Hello World”
Step by Step on Using MSVS 2010
After writing program a programmer needs to compile the
program and execute to see the desired outcome. So here
are some keys to do so
• For compiling and building solution use F7 key
• For Debugging use F5 key
• For Executing program without debugging use Ctrl+F5
We can also use menu items to perform above mentioned
tasks
Programming is Learned by writing programs.
The Classic First ProgramHere is a version of the classic first program. It writes "Hello, World!" to your screen://This program outputs the message "Hello, World ! ~ to the monitor
using System;class FirstClass{ static void Main(String[] str) { Console.WriteLine("Hello World\n"); }}Think of this text as a set of instructions that we give to the computer to execute,much as we would give a recipe to a cook to follow.
Program Basics
Starting with the line
Console.WriteLine("Hello World"); // output Hello, World!“
That's the line that actually produces the output. It prints the
characters Hello,
World! followed by a newline; that is, after writing Hello, World! ,
the cursor will
be placed at the start of the next line. A cursor is a little blinking
character or line
showing where you can type the next character.
Program Basics
In C#, string literals are delimited by double quotes ("); that
is, "Hello, World!\n" is a string of characters. The \n is a
"special character" indicating a newline. the name cout refers
to a standard output stream.
Program Basics
Starting with the line
cout << "Hello. World !\n"; // output Hello, World!“
That's the line that actually produces the output. It prints the
characters Hello,
World! followed by a newline; that is, after writing Hello, World! ,
the cursor will
be placed at the start of the next line. A cursor is a little blinking
character or line
showing where you can type the next character.
Comments
The end of that line
// output Hello, World!"
is a comment. Anything written after the token // (that's the
character /, called "slash“, twice) on a line is a comment.
Comments are ignored by the compiler and written for the
benefit of programmers who read the code. Here, we used
the comment to tell you what the beginning of that line
actually did.
CommentsThe first line of the program is a typical comment; it simply
tells the human reader what the program is supposed to do:
//This program outputs the message "Hello, World ! ~ to the
monitor
Such comments arc useful because the code itself says what
the program does, not what we meant it to do. Also, we can
usually explain (roughly) what a program should do to a
human much more concisely than we can express it (in
detail) in code to a computer. Often such a comment is the
first part of the program we write.
Main functionHow does a compiler know where to Start executing a
program? It looks for a function called “main” and starts
executing the instructions it finds there. Here is
the function main of our "Hello, World!'" program:
static void Main(string[] str) { Console.Write("Hello World\n"); }
Main functionEvery program must have a function called main
to tell it where to Start executing. A function is
basically a named sequence of instructions for the
computer to execute in the order in which they
are written. A function has four pans:
Main function A name, here Main.
A parameter list enclosed in parentheses, here
() ; in this case, the parameter list is empty.
A function body enclosed in a set of "curly
braces," {} which lists the actions (caller
statement) that the function is to perform.
CompilationC# is a compiled language. “ that means that to
get a program to run, you must first translate it
from the human-readable form to something a
machine can understand." That translation is done
by a program called a compiler. What we read and
write is called source code or program text, and
what the computer executes is called executable,
Object code or Machine code.
Compilation
Source code
C# Compiler Executable
C# compiler reads your source code and tries to make sense of
what you wrote. h looks to sec if your program is grammatically
correct, if every word has a defined meaning, and if there is
anything obviously wrong that can be detected without trying to
actually execute the program. You'll find that computers are rather
picky about syntax. Leaving out any detail of our program, such as
an #include file, a semicolon, or a curly brace, will cause errors.
Similarly, the compiler has absolutely zero tolerance for spelling
mistakes.
LinkingA program usually consists of several separate
parts, often developed by different people. For
example, the "Hello, World!" program consists of
the part we wrote plus parts of the C# standard
library. these separate parts (sometimes called
translation units) must be compiled and the
resulting object code files must be linked together
to form an executable program. The program that
links such parts together is (unsurprisingly) called
a linker:
So what is programming?
• Specifying the structure and behavior of
a program, and testing that the program
performs its task correctly and with
acceptable performance
• Never forget to check that “it” works
• Software == one or more programs
ProgrammingProgramming is simple
Just state what the machine is to do
“Programming is understanding”
When you can program a task, you understand it
When you program, you spend significant time trying to
understand the task you want to automate
Programming is part practical, part theory
If you are just practical, you produce non-scalable
unmaintainable hacks
If you are just theoretical, you produce toys
Questions?????