Chapter 15: Programming Languages

Download Report

Transcript Chapter 15: Programming Languages

Programming and Languages:
Telling the Computer What to Do
CIS 105
Topics
 Describe what programmers do
 Explain how programmers define a problem,
plan the solution, and then code, test, and
document the program
 List and differentiate the control structures
 List the major programming paradigms
 Define some concepts of object-oriented
programming
 List some major programming languages that
are in use today
2
Programming
 Program – a set of detailed, step-by-step
instructions that directs the computer to process
data into information.
 Programming is combination of art and science,
because you may code a program however you
like as long as you follow the language’s rules.
 Programming language – a set of rules (syntax)
and commands that provides a way of telling the
computer what operations to perform.
 Programmer – designs algorithm and converts
it into computer instructions and tests programs
as developed.
3
Program Development Life Cycle
 Six main phases
1.
2.
3.
4.
5.
6.
Define the problem
Design the solution
Code the program
Test the program
Document the program
Implement the program
•
The phases will be reviewed over next few slides…
4
1. Define the Problem
• Review program specs
• Meet with analysts / users
• Identify program components
(IPO Chart– Input, Processing, Output)
5
2. Design the Solution
 Design an algorithm.
 An algorithm is a finite series of logical steps
required to solve a particular problem.
 Finite means that the beginning and end are
clearly defined.
 Design tools covered in a next few slides…
 Use flowcharts and pseudocode.
 Use the appropriate programming flow control
structures in the design
Desk check the solution
6
Flowcharting
A flowchart is a pictorial representation of
an algorithm or logical steps.
Each step is represented by a symbol and
the arrows indicate the flow and order of
the steps.
The shape of the symbol indicates the
type of operation that is to occur.
Flowcharts may help the more visual
students learn and understand logic.
7
Basic Flowchart Symbols
Begin or End
Processing
Input or Output
Decision
Branch or Direction of Flow
8
Flow Control Structures
 Flow control is the order in which
statements are executed.
 There are four control structures.
1. Sequence Control
2. Selection Control
 Also referred to as branching (if and if-else)
3. Case Control (similar to selection)
4. Repetition Control (loops)
9
Sequence Control
10
Selection Control (branching)
11
Case Control
12
Repetition Control (loops)
13
Pseudocode
 Pseudocode is a mixture of
programming code and English
like statements.
 Used when designing algorithms.
 When designing, we don’t
necessarily want to be concerned
about specific method names.
 We want to concentrate on the
design and logic.
 Later we can look up specific
properties or method names.
14
Desk Checking
After designing a solution, make sure it is going
to work before coding it by desk checking it.
1.Develop sets of test data (inputs)
2.Determine the expected result (output) for each
data set without using solution algorithm
3.Step through solution using one set of test data
& writing down actual result obtained (output)
4.Compare expected with actual results
5.Repeat steps 3 & 4 for each set of test data
15
3. Code the Program
 Translate solution
algorithms into a
programming
language.
 Enter program
code into
programming
development tool
using correct syntax.
16
4. Test the Program
 Remove syntax and logic errors
 Syntax error - when code violates language rules, errors are
displayed by the programming development tool.
 Logic error – when program does not generate expected
output when using the test data.
This time error must be found by the programmer.
 Logic Errors are also call bugs, so finding and fixing logic
errors is call debugging.
 Debug Utility – some errors are difficult to find, so
programmers use a debugger that allows them to walk
through the code as each statement is executed, so that they
can verify the flow and see the values in variables as they
17
change in memory.
Quality Assurance (QA)
Quality assurance is the activity of providing
evidence to stakeholders establishing that
the programs have been completed
successfully and are ready to be
operational.
Testing software is the process used to help
identify the completeness, correctness,
security, and quality of the developed
programs.
 Growing field: Quality Assurance Specialist
18
5. Document the Program
Programmer name and date
A narrative description of the program
Include comments within the source code
Flowcharts and/or pseudocode
Layouts of input and output records
Testing procedures
Most of the items would be electronic
copies and saved in the project library.
19
6. Implement & Maintain the Program
 Programs may be part of a system
implementation or single program implementation.
 Training, user manuals, technology upgrades, and
conversions must be taken into consideration
during implementation.
 Eventually programs may need to be updated due
to mandatory updates such as government
regulations / requirements, new sales tax rates
 Programs may be enhanced to add new features
or functionality
 Program may become obsolete when changes
become too difficult or new technology needs to
be applied.
20
Programming Paradigms
 Procedural Programming
 Programmer must provide step-by-step instructions, telling the computer
what to do and how to do it.
 Logic begins at the top and flows down.
 Non-procedural language, such as SQL in a relational database, the
programmer specifies what is needed, and the language determines how
by using the data dictionary.
 Event Programming
 A program listens for and reacts to events such as mouse click on a
button.
 Object-Oriented Programming (OOP)
 Use class definitions to build programs.
 A class definition includes properties (attributes) to store information
about the class and methods (operations) to manipulate the properties.
 A programmer uses a class to declare an object, which is then
considered an instance of the class.
 Inheritance is when a programmer uses an existing class as the base
when defining a new class. Everything in the base class is included in
the derived class plus the new properties and methods.
21
 Visual Basic supports all three paradigms.
TextBox Class used in Lab VB
The Textbox control is a class definition
(blueprint) from which objects are created.
When the Textbox control is dragged from
the Toolbox on to a form, an instance
(object) of a Textbox is created.
We can then set the properties, such as
Name, MultiLine, ReadOnly, Text, etc.
We can also call methods in the code:
resultsTextBox.AppendText(addResultString)
firstNumberTextBox.Clear( )
22
Popular Programming Languages
 BASIC (Beginners’ All-purpose Symbolic Instruction Code –
1960s)
 COBOL (Common Business Oriented Language 1960s)
 C - Used to develop UNIX in 1970s;
runs on most operating system now
 C++ - A better C, Object oriented; (1980s)
 Java - Similar to C++;
Became popular because of web development – applets,
Programs run on multiple platforms (Win, Unix, Mac),
Originally named Oak (1991) and renamed to Java in 1995
 Visual Basic – Microsoft created language so that graphical
user interfaces could be created for their new operating
system – Windows (1990s)
 C# (c-sharp) – Microsoft’s newest language (2002);
syntax is similar to Java, but uses the VB library.
23
 See next slide for examples…
Examples of Programming Languages
C#
Visual
Basic
JavaCOBOL
C
24
Compilers & Interpreters
A compiler translates all of the
source code into object code,
an executable program. During
this translation process, a
program listing of any syntax
errors is produced.
An interpreter translates one line
of the source code at a time.
Interpreters run programs more
slowly than compilers, but they are
helpful programs for finding syntax
errors, because they are interactive.
25
Web Page Program Development
 HTML
 Pages are defined using tags ( <html> </html> )
 Cascading Style Sheets (CSS) contains formats
 Client-side Scripts
 Interpreted programs that run on the client
 JavaScript, Perl, Php used to generate Dynamic HTML (DHTML)
 Applet – compiled Java that runs on the client; it is faster than a script
 Server-side Scripts (programming)
 Interpreted or compiled programs that run on the server
 CGI (common gateway interface, Perl, Php, ASP, JSP)
 Servlet – a Java (JSP) applet that runs on the server
 Multimedia Authoring Software
 Flash, Quicktime, Authorware, Director, etc.
26
Selecting a Language or Tool
Standards of the organization may specify
which programming language is used.
New programs may need to interface with
other existing or future programs.
Suitability of the language to the application.
Portability to other systems and platforms.
27
MCC Related Courses…
 CIS150AB – Intro Object-Oriented Programming
 CIS159 – Visual Basic
 CIS162AB – C++
 CIS162AD – C#
 CIS163AA – Java
 CIS133CA – Intro to Web Development (1 credit)
 CIS166AA – JavaScript
 CIS166AC – ASP Web Scripting
 CIS166AE – PHP Web Scripting
28