410 likes | 537 Views
Introducing Computer Science & Algorithms. Goals. By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand the difference between procedural-type languages and object-oriented languages … understand the program development cycle.
E N D
Goals By the end of this lecture you should … • … understand Computer Science as the study of algorithms • … understand the difference between procedural-type languages and object-oriented languages • … understand the program development cycle
Types of Computers • Personal Computer - a computer operated by one person at a time. AKA “Client” computers. • Server – a computer whose resources and processors are shared by multiple users • VB.Net concerns itself mainly with programming for the client computer
Computer use is Pervasive • Banking • Air Traffic • Space Travel • Commerce • Medicine • Public Safety • Education
Computer Components • Hardware • Physical components of a computer • Examples: Mouse, keyboard, RAM, hard drives, processor, monitor • Software • Instructions that get the computer to do something • Operating Systems & Applications • Examples: Windows 2000, Microsoft Excel, WordPerfect, Netscape, Internet Explorer
What is Computer Science? • NOT about coding or hardware or software! • Computer Science is about PROBLEM SOLVING • Computer Science is about DEVELOPING ALGORITHMS to solve complex problems • Computers are merely tools for solving problems!
Algorithms • Well-developed, organized approaches to solving complex problems • Test of a good algorithm: • Does the algorithm solve the stated problem? • Is the algorithm well-defined? • Does the algorithm produce an output? • Does the algorithm end in a reasonable length of time?
Developing an Algorithm • Identify the Inputs • What data do I need? • How will I get the data? • In what format will the data be? • Identify the Processes: • How can I manipulate data to produce meaningful results? • Identify Outputs: • What outputs do I need to return to the user? • What format should the outputs take?
Develop a HIPO chart Developing an Algorithm
Developing an Algorithm • Identify relevant modules • How can I break larger problems into smaller, more manageable pieces? • What inputs do the modules need? • What processes need to happen in the modules? • What outputs are produced by the modules?
Programs • Sets of instructions that get the computer to do something • Instructions are translated, eventually, to machine language using an interpreter or a compiler • Programs may be a few lines or millions of lines of code
Programming Tasks • All computer programs are written so they can take data, manipulate and then produce a result. • This process uses three distinct tasks: • INPUT – getting data from an external source (the user, a database, a file, etc.) • PROCESSING – actual manipulation of the data • OUTPUT – reporting the results of data manipulation back (using the monitor, writing information to a database, etc.)
Relationships in Programming • Programmer – The person who solves a problem by providing a solution through writing instructions (the program) for the computer. (AKA – The developer) • User – Any person who uses a program written by a programmer
Categories of Languages • Machine Language • Binary digits (bits – 1s and 0s) which are translated to electrical impulses that get the computer to do something • “Native” language of computers • Assembly Languages • Group of basic commands which are more like English • Tied to specific processors • Still need to be translated to machine language
Categories of Languages • High Level Languages • In terms of syntax, very close to human language (mostly English) • Lower error rate than writing machine language or assembly language programs • Need to be translated to machine language before execution • Compilers • Interpreters
More on High-Level Languages • Operations common to all HL languages: • Sequential Operations – Operations in which lines of code execute in order, one right after another • Conditional Operations – Operations in which execution depends on the outcome of a previous condition (usually evaluated to be TRUE or FALSE) • Looping Operations – Operations designed to repeat until a given condition is satisfied.
More on High-Level Languages • Procedural Languages • Early high level languages • Focus on structures • Examples include QuickBasic, Fortran, Pascal, Visual Basic (early versions) • Object-Oriented languages (OOP) • More recent development • Focus on data, not structures (Primacy of Data) • Examples include Java, C#, C++, Visual Basic.Net
Object Oriented Programming • Object– Unique programming entity that has methods, has attributes and can react to events. • Method – Things which an object can do; the “verbs” of objects. In code, usually can be identified by an “action” word -- Hide, Show
Object Oriented Programming • Attribute– Things which describe an object; the “adjectives” of objects. In code, usually can be identified by a “descriptive” word – Enabled, BackColor • Events – Forces external to an object to which that object can react. In code, usually attached to an event procedure
Object Oriented Programming • Class– Provides a way to create new objects based on a “meta-definition” of an object (Example: The automobile class) • Constructors– Special methods used to create new instances of a class (Example: A Honda Civic is an instanceof the automobile class.)
OOP - Encapsulation • Incorporation into a class of data & operations in one package • Data can only be accessed through that package • “Information Hiding”
OOP - Inheritance • Allows programmers to create new classes based on an existing class • Methods and attributes from the parent class are inherited by the newly-created class • New methods and attributes can be created in the new class, but don’t affect the parent class’s definition
OOP - Polymorphism • Creating methods which describe the way to do some general function (Example: The “drive” method in the automobile class) • Polymorphic methods can adapt to specific types of objects.
The Programming Development Cycle • Done after identifying inputs, processing & outputs • Steps • Analyze the problem • Plan a solution to the problem (algorithm) • Design the user interface
The VB.NET Programming Development Cycle • Steps (continued) • Code the solution • Test and debug the solution • Complete program documentation • Begin to plan for next release (start Cycle again)
1. Analyze the Problem • Questions to ask: • Who is my intended audience? • What SPECIFIC outcomes does my audience expect? • What business rules is my audience expecting to have incorporated into the solution? • What is the SCOPE of the problem?
2. Plan a Solution (Algorithm) • What types of programming structures are needed? • Sequential structures • Conditional structures • Looping structures • What data structures are needed? • Variables • Lists • Arrays
3. Design the User Interface • AKA – The “UI” • Is the UI “learnable”? • Is it simple? (Limit user choices) • Does the UI promote error-proof use? • Is the layout of the UI arranged in a fashion conducive to the user’s culture and expectations?
4. Code the Solution • Develop an actual program from an algorithm • Should be the “easiest” part of the process – all the work should already be done!
5. Test & Debug the Solution • Alpha Testing – Internal testing done with expected client data (NOT LIVE DATA) • Beta Testing – Testing done at the client site with their data (USUALLY LIVE DATA) • Try to predict common user errors • Test subjects should be Power Users, Normal Users and Neophytes
6. Complete Documentation • User Documentation: • User Manual • Technical Documentation (for System Administrators) • Internal Documentation: • Documentation comments • Code comments • Procedural comments • Should be done while coding!
7. Plan Next Release • What bugs need to be fixed? • Are bugs “critical”? (Need to be fixed in a minor release) • If bugs are not critical, they can be fixed in next major release • What product enhancements do the users want for the next release?
Internal Commenting • Comments are non-executable lines (the computer ignores them) which are used to communicate valuable information about code to others • Types of Internal Commenting: • Documentation Comments • Code Comments • Procedural Comments • Comment Syntax: • C-like Syntax (C, C++, Java, JavaScript): /* This is a comment */ • Visual Basic Syntax: ‘This is a comment
Documentation Comments • Used to given specific information about a program • Usually found at the beginning of a code window • Include information about the author, creation date, purpose, modification date & modification history
Documentation Comment 'TITLE: Hello World, v2.0'AUTHOR: Bob Molnar'PURPOSE: To demonstrate changing of textbox 'properties using event procedures.'CREATED ON: 09.10.2002'LAST MODIFIED ON: 09.18.2002'LAST MODIFIED BY: RSM'MODIFICATION HISTORY:' 09.12.2002 - Renamed form to frmMain to' conform with accepted naming standards (MJK) ' 09.18.2002 - Created a Clear Button enabling' users to clear output (RSM) NOTE: Example uses Visual Basic Syntax
Code Comments • “Tell the story” of the code, in English • For this class, you should use code comments to indicate what lines of code do
Code Comments /* Initialize loop counter to 1 */counter = 1;/* Set loop to repeat 10 times */while(counter <= 10){ /* Prompt for input */ printf("Enter grade: "); /* Get user's input, store in the variable grade */ scanf("%d", &grade); } /* end while */ NOTE: Example uses C Syntax
Procedural Comments • Identify purpose, arguments & return values for procedures • Can be used in: • Event Procedures • Sub-Procedures • Function Procedures
Procedural Comments ' PROCEDURE: btnClear_Click ' TYPE: Event Procedure ' ARGUMENTS: VB-Generated ' PROCEDURE: btnClear_Click ' RETURNS: Nothing ' PURPOSE: Re-sets the value of the textbox ' txtDspMsg to null when the button btnClear ' clicked Private Sub btnClear_Click(...) Handles _ btnClear.Click txtDspMsg.Text = ""End Sub NOTE: Example uses Visual Basic Syntax
Resources • Bob Molnar, N201 Lecture Notes • Visual Basic.NET Primer Plus by Jack Purdum (Sams Publishing, 2003) • An Introduction to Programming Using Visual Basic.NET Fifth Edition by David I. Schneider (Prentice Hall, 2003) • C: How to Program by Deitel & Deitel (Prentice Hall, 2004)