m jamil. much of human behavior and thought is characterized by logical sequences. since childhood,...

72
M Jamil Introduction to Programming

Upload: josephine-parker

Post on 20-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

M Jamil

Introduction to Programming

Page 2: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 3: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 4: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 5: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 6: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 7: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Programming Process

Page 8: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 9: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 10: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 11: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 12: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 13: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 14: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 15: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 16: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 17: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 18: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 19: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 20: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 21: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 22: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 23: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Procedural Programming

Page 24: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 25: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 26: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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. 

Page 27: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Modular Programming

Page 28: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 29: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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#.

Page 30: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Characteristics of OOPs

Followings are the major elements of object-

oriented languages in general, and C# in

particular.

Objects

Classes

Inheritance

Polymorphism

Encapsulation

Reusability

Page 31: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Characteristics of OOPs

Page 32: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 33: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Where is Programming Used?Just about everywhere

Mars rovers, animation, graphics, Photoshop, GUI, OS, compilers, slides, chip design, chip manufacturing, semiconductor tools, etc.

Page 34: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 35: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Ships

DesignConstructionManagement

Monitoring Engine Hull design Pumps

Page 36: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Aircraft

CommunicationControlDisplay

Signal processing “Gadget” control Monitoring

Page 37: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Phones

Voice qualityUser interfacesBillingMobility

Switching Reliability Provisioning Images

Page 38: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Energy

ControlMonitoringAnalysisDesign

Communications Visualization Manufacturing

Page 39: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

PC/workstation

There’s a lot more to computing than games, word processing, browsing, and spreadsheets!

Page 40: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Typical Industries for programmer Software Industry

• Web Development

• Business Applications

Medical Industry

Embedded Computing Devices• Home Applications

• Entertainment

• Communication Devices

Page 41: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 42: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

C# is Flexible

Powerful

Easier to use

Visually Oriented

Internet Friendly

Secure

Page 43: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Programming Environment

Page 44: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 45: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 46: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20101- Start Microsoft Visual Studio 2010 and open file menu → New → Project

Page 47: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20102- Click Visual C# tab then Select Windows

Page 48: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20103- Select Empty Project

Select Empty Project

Page 49: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20104- Give some proper Name to Project

Name the Project

Page 50: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20105- Click OK button

Click OK

Page 51: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20106- Right click the solution Add New Item

Select New Item

Page 52: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20107- Visual C# items Code Codefile.

Select Click to Select Code

Page 53: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20108- Give some appropriate name and click Add Button.

Give a Name e.g. ‘main’ Click Add

Page 54: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 20109- Now file is available in solution to edit. Write Code here

Write your code here’

Page 55: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Step by Step on Using MSVS 201010- Sample code “hello World”.

Say “Hello World”

Page 56: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 57: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Programming is Learned by writing programs.

Page 58: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 59: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 60: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 61: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 62: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 63: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 64: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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"); }

Page 65: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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:

Page 66: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 67: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 68: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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.

Page 69: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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:

Page 70: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 71: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

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

Page 72: M Jamil. Much of human behavior and thought is characterized by logical sequences. Since childhood, you have been learning how to act, how to do things

Questions?????