Introduction to Programming

coordinatedcapableSoftware and s/w Development

Nov 4, 2013 (3 years and 11 months ago)

71 views

Introduction to Programming

When you program,
you are programming
the instruction set of
the CPU (machine
language).

Intel 8080 CPU

Machine Language / Assembly Language


The only programming language a CPU can directly execute
is machine language (or machine code).


Since machine language

instructions are in binary,

Assembly Language is created

to allow a programmer to code

the instructions in a familiar

language, then compile these

instructions into machine

language.


With Assembly Language,

you are still programming using

the instruction set of the CPU.

The Hierarchy of Programming Languages

End
-
User

Database,

Worksheet, Document

Access, Excel, Word

C++, Java, C#

Assembly Language

Machine Language

Hardware
-

CPU

Lower Level
-

Higher Level

10011100

00100111

11100011

01010110

#include <iostream.h>

main()

{


int Total,Kiwi,Bananas;


Kiwi = 5;


Bananas = 6;


Total = Kiwi + Bananas;


cout << Total << endl;

}

Compiled versus Interpreted


A
compiler

translates an entire program (source code)
into machine language for execution by the CPU. The
result is an executable (.exe) file that can be run on a
computer.




A = 5




program.exe



B = A + 3



110001101101101100110101



Print B




001100001110110110101101



An
interpreter

translates or compiles a program one line
at a time while it is executing. An older example of an
interpreted language is Basic. A newer example is
JavaScript.

Enter temperature in Fahrenheit: 75

It is 23.8889 degrees Celsius.

#include <iostream.h>

float Convert(float);


main()

{


float F,C;


cout << "Enter temperature in Fahrenheit: ";


cin >> F;



C = Convert(F);



cout << "It is " << C << " degrees Celsius.
\
n";

}



float Convert (float F)

{


float C = (5.0/9.0) * (F
-

32.0);


return C;

}

Structured Programming

Program Source Code

Program Output

In structured programming, common
tasks such as converting Fahrenheit to
Celsius are put into separate reusable
modules called functions.


These modules/functions may be used
as often as needed and they can be
reused in other programs.

DeckofCards Lucky; // define object
Lucky

to be a deck of cards

Player Kirk; // define object
Kirk

to be a player


Lucky.Shuffle; // shuffle the deck of cards

Lucky.Cut; // cut the deck or cards


Kirk.Cards = Lucky.Deal(5); // deal 5 cards to Kirk

Kirk.ShowCards; // display the cards

Kirk.PokerHand; // display poker hand

Object Oriented Programming (OOP)

Full House

Program Source Code

Program Output

Object
-
oriented programming (OOP) is a newer approach to program design. It focuses
on creating objects. Objects have both properties (data) and methods (functions). For
example, an object might be a deck of cards. It’s properties are the number and order of
the cards. Its methods/functions are shuffling, cutting, dealing, etc.

Software Development Life Cycle

Phase

Comments

Problem Analysis

System analysts study the problem and define
the specifications for the software.

Program Design

The specifications are used to develop an
algorithm for the program

Program Coding

Programmers produce the code for the program.
Alpha versions of the program are created.

Program Debugging and Testing

Program testing may be done in
-
house, or a Beta
version may be produced to allow end
-
users test
the program.

Program Implementation and
Maintenance

After the program is put into production, the
maintenance phase begins. New versions will be
released to fix bugs and add requested
functionality.

Programming Languages

Language

Description

Machine Language

The native programming language of the computer's CPU. This low
-
level language is tedious


CPUs come with a
specified set of very basic instructions and operations. For example, a
load

instruction will move each piece
of data from memory to a register on the CPU for processing. Machine language is written in binary


all 1's
and 0's.

Assembly Language

A fancier way to write machine language. This low
-
level language allows instructions to be written in a more
understandable format (instead of binary), then converted to machine language.

C

A high
-
level structured, procedural programming language that is widely used for programming applications as well
as operating systems. It was developed on a UNIX system and later used to reprogram UNIX.

C++

A high
-
level object oriented programming language that is a superset of C. Originally designed by Bjarne
Stroustrup of AT&T's Bell Labs in 1979. It adds better type checking, data abstraction, and object oriented
programming to C.

C#

Pronounced C
-
Sharp, this programming language was developed by Microsoft for its .NET Framework. In many
ways, it is an upgrade to C++ and was made to compete with the Java language.

BASIC

An early high
-
level programming language that is simple to use and widely popular. Many of the first home
computers in the 1970's and 1980's included this programming language.

COBOL

COBOL (Common Business Oriented Language) was the first widely used high
-
level language for business
applications such as payroll and accounting. This older programming language has been updated and is still
used today, mostly on mainframe computers.

FORTRAN

FORTRAN (Formula Translation) is an older high
-
level language that was designed for scientific applications.

Pascal

Pascal is an older high
-
level language that was also designed for math and science applications. It was popular as a
teaching tool for structured programming before C became popular.

Visual Basic (VB)

Microsoft's Visual Basic adds object
-
oriented features and a graphical user interface to the standard BASIC
language.

Java

A high
-
level object
-
oriented programming language developed by Sun Microsystems for creating applets that are
platform independent. A Java applet (.class file) will execute on any operating system that has the Java run
-
time console installed. Java applets first became popular as programs that execute within a web browser.

JavaScript

A scripting language used in web pages that enhances the limited capabilities of HTML. JavaScript adds many
functions to HTML including as cookies and pop
-
up windows.