computer programming. chapter contents section a: programming basics section b: procedural...
Post on 22-Dec-2015
221 views
TRANSCRIPT
![Page 1: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/1.jpg)
Computer Programming
![Page 2: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/2.jpg)
Chapter Contents
• Section A: Programming Basics
• Section B: Procedural Programming
• Section C: Object-Oriented Programming
• Section D: Declarative Programming
• Section E: Secure Programming
![Page 3: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/3.jpg)
Programming Basics
• Computer Programming and Software Engineering
• Programming Languages and Paradigms
• Program Planning
• Program Coding
• Program Testing and Documentation
• Programming Tools
![Page 4: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/4.jpg)
Computer Programming and Software Engineering
• The instructions that make up a computer program are sometimes referred to as code
• Programs can have millions of lines of code– Developed by computer programmers
• Computer programming
![Page 5: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/5.jpg)
Computer Programming and Software Engineering
![Page 6: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/6.jpg)
Programming Languages and Paradigms
• Programming languages are made up of keywords and grammar rules designed for creating computer instructions– Keywords can be combined with parameters
• Low-level languages typically include commands specific to a particular CPU or microprocessor family
• High-level languages use command words and grammar based on human languages
![Page 7: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/7.jpg)
Programming Languages and Paradigms
• First-generation languages– Machine language
• Second-generation languages– Assembly language
• Third-generation languages– Easy-to-remember command words
![Page 8: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/8.jpg)
Programming Languages and Paradigms
• Fourth-generation languages– More closely resembles human language
• Fifth-generation languages– Based on a declarative programming
paradigm
• The programming paradigm refers to a way of conceptualizing and structuring the tasks a computer performs
![Page 9: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/9.jpg)
Programming Languages and Paradigms
![Page 10: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/10.jpg)
Program Planning
• The problem statement defines certain elements that must be manipulated to achieve a result or goal
• You accept assumptions as true to proceed with program planning
• Known information helps the computer to solve a problem
• Variables vs. constants
![Page 11: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/11.jpg)
Program Planning
• Problem statement:
Assuming that there are two pizzas to compare, that both pizzas contain the same toppings, and that the pizzas could be round or square, and given the prices, shapes, and sizes of the two pizzas, the computer will print a message indicating which pizza has the lower price per square inch
![Page 12: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/12.jpg)
Program Coding
A text editor such asNotepad allows programmersto enter lines of code using a familiar word processing interface.
![Page 13: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/13.jpg)
Program Coding
• A VDE (visual development environment) provides programmers with tools to build substantial sections of a program– Form design grid– Control– Properties– Event– Event-
handling code
![Page 14: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/14.jpg)
Program Coding
Controls, such as theBest Deal button, can beselected by a programmerfrom a properties list. Here a programmer is selecting the background color for the Best Deal button.
![Page 15: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/15.jpg)
Program Coding
![Page 16: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/16.jpg)
Program Testing and Documentation
• A computer program must be tested to ensure that it works correctly
• Program errors include– Syntax errors– Runtime errors– Logic errors
• A debugger can help a programmer read through lines of code and solve problems
![Page 17: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/17.jpg)
Program Testing and Documentation
• Remarks or “comments” are a form of documentation that programmers insert into the program code
![Page 18: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/18.jpg)
Programming Tools
• An SDK (software development kit) is a collection of language-specific programming tools that enables a programmer to develop applications for a specific computer platform
• An IDE (integrated development environment) is a type of SDK that packages a set of development tools into a sleek programming application
![Page 19: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/19.jpg)
Programming Tools
• A component is a prewritten module, typically designed to accomplish a specific task
• An API is a set of application program or operating system functions that programmers can access from within the programs they create
• C and C++ are the most popular programming languages
• Particle renderers– Pathfinder algorithms
![Page 20: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/20.jpg)
Procedural Programming
• Algorithms
• Expressing an Algorithm
• Sequence, Selection, and Repetition Controls
• Procedural Languages and Applications
![Page 21: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/21.jpg)
Algorithms
• Set of steps for carrying out a task that can be written down and implemented
• Start by recording the steps you take to solve the problem manually
• Specify how to manipulate information
• Specify what the algorithm should display as a solution
![Page 22: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/22.jpg)
Algorithms
![Page 23: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/23.jpg)
Expressing an Algorithm
• Structured English
• Pseudocode
![Page 24: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/24.jpg)
Expressing an Algorithm
• Flowchart
The pizza program flowchartillustrates how the computershould proceed through theinstructions in the final program.
![Page 25: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/25.jpg)
Expressing an Algorithm
• Perform a walkthrough to make sure your algorithm works
![Page 26: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/26.jpg)
Sequence, Selection, and Repetition Controls
• Sequence control structure
Executing a GOTO commanddirects the computer to a differentpart of the program.
![Page 27: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/27.jpg)
Sequence, Selection, and Repetition Controls
• Subroutines, procedures, and functions are sections of code that are part of the program, but not included in the main sequential execution path
![Page 28: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/28.jpg)
Sequence, Selection, and Repetition Controls
• Selection control structure
The computer executes a decisionindicated on the flowchart by the question in the diamond shape.
![Page 29: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/29.jpg)
Sequence, Selection, and Repetition Controls
• Repetition control structure
To execute a loop, the computerrepeats one or more commands until some condition indicates that the looping should stop.
![Page 30: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/30.jpg)
Procedural Languages and Applications
• Popular procedural languages include FORTRAN, COBOL, FORTH, APL, ALGOL, PL/1, Pascal, C, Ada, and BASIC
• The procedural approach is best used for problems that can be solved by following a step-by-step algorithm– Does not fit well with certain types of
problems
• Produces programs that run quickly and efficiently
![Page 31: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/31.jpg)
Object-Oriented Programming
• Objects and Classes
• Inheritance
• Methods and Messages
• Object-oriented Program Structure
• Object-oriented Languages and Applications
![Page 32: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/32.jpg)
Objects and Classes
• An object represents an abstract or real-world entity
• A class is a template for a group of objects with similar characteristics– A class attribute defines the characteristics of
a set of objects• Public vs. private
attributes
![Page 33: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/33.jpg)
Inheritance
• Passing certain characteristics from one class to other classes– Superclass– Subclass– Class hierarchy
![Page 34: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/34.jpg)
Methods and Messages
• A method is a segment of code that defines an action– Collect input, perform calculations, etc.– A method is activated by a message– Can be defined along with the class they
affect
• Polymorphism refers to the ability to redefine a method in a subclass– Helps simplify program code
![Page 35: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/35.jpg)
Object-Oriented Program Structure
![Page 36: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/36.jpg)
Object-Oriented Program Structure
![Page 37: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/37.jpg)
Object-Oriented Program Structure
When the pizza programruns, on-screen promptsask for the shape, size, andprice of each pizza; thenthe program displays amessage that indicateswhich pizza is the bestdeal.
![Page 38: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/38.jpg)
Object-Oriented Languages and Applications
• SIMULA was believed to be the first object-oriented computer language
• The Dynabook project was the second major development in object-oriented languages
• Popular object-oriented languages today are Ada95, C++, Visual Basic, and C#
• The OO paradigm results in decreased runtime efficiency, but allows encapsulation, which hides the internal details of objects and their methods
![Page 39: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/39.jpg)
Declarative Programming
• The Declarative Paradigm
• Prolog Facts
• Prolog Rules
• Input Capabilities
• Declarative Languages and Applications
![Page 40: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/40.jpg)
The Declarative Paradigm
• Attempts to describe a problem without specifying exactly how to arrive at a solution– A fact is a statement for solving a problem– Rules describe the relationship between facts
![Page 41: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/41.jpg)
The Declarative Paradigm
• A decision table is a tabular method for visualizing and specifying rules based on multiple factors
![Page 42: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/42.jpg)
Prolog Facts
![Page 43: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/43.jpg)
Prolog Facts
• You can query a program’s database by asking a question, called a goal
The ?- prompt allows youto query a set of Prologfacts and rules.
![Page 44: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/44.jpg)
Prolog Facts
• Finding a value for a variable is referred to as instantiation
Prolog uses a process called instantiation tosatisfy goals.
![Page 45: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/45.jpg)
Prolog Rules
• The order of program instructions is critically important
![Page 46: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/46.jpg)
Input Capabilities
When the pizza programruns, the pizzainfo rulecollects input for the prices, the sizes, and the shapes of two pizzas.
![Page 47: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/47.jpg)
Declarative Languages and Applications
• Declarative programming languages are most suitable for problems that pertain to words and concepts rather than to numbers– Highly effective programming environment– Not commonly used for production applications– Minimal input and output capabilities– Poor performance on today’s personal computer
architecture
![Page 48: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/48.jpg)
Secure Programming
• Black Hat Exploits
• Secure Software Development
• Mitigation
![Page 49: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/49.jpg)
Black Hat Exploits
• Today’s operating systems, utilities, and application software are full of defects that create security holes, which are exploited by black hats
• A buffer overflow (also called a buffer overrun) is a condition in which data in memory exceeds its expected boundaries and flows into memory areas intended for use by other data
![Page 50: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/50.jpg)
Black Hat Exploits
![Page 51: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/51.jpg)
Black Hat Exploits
• Verbose error messages can also present attackers with information about the directory location of programs or files, the structure of a database, or the layout of the program in memory
![Page 52: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/52.jpg)
Secure Software Development
• Most software security problems can be traced back to defects that programmers unintentionally introduce in software during design and development
• Formal methods help programmers apply rigorous logical and mathematical models to software design, coding, testing, and verification
• Threat modeling (risk analysis)
![Page 53: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/53.jpg)
Secure Software Development
![Page 54: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/54.jpg)
Secure Software Development
• An attack tree is a hierarchical diagram of potential attacks against a system
![Page 55: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/55.jpg)
Secure Software Development
• Defensive programming (also referred to as secure programming) is an approach to software development in which programmers anticipate what might go wrong as their programs run and take steps to smoothly handle those situations– Source code walkthroughs– Simplification– Filtering input
![Page 56: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/56.jpg)
Secure Software Development
• Signed code is a software program that identifies its source and carries a digital certificate attesting to its authenticity
![Page 57: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/57.jpg)
Mitigation
• Despite defensive programming and other tactics to produce secure software, some defects inevitably remain undiscovered in products that end up in the consumers’ hands When bugs are discovered, the programmer’s remaining line of defense is to produce a bug fix, or patch
![Page 58: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/58.jpg)
Mitigation
• Take the following steps to avoid security problems that stem from software defects– Select applications from software publishers
with a good security track record– Watch for patches and apply them– Consider using open source software, which
has been extensively reviewed by the programming community
– Keep your firewall and antivirus software deployed and up-to-date
![Page 59: Computer Programming. Chapter Contents Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section](https://reader038.vdocument.in/reader038/viewer/2022102907/56649d775503460f94a590f7/html5/thumbnails/59.jpg)
Computer Programming