Download presentation
Presentation is loading. Please wait.
Published byBenedict Lawson Modified over 9 years ago
1
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011
2
Basic Components of a Computer Computer: machine that performs different tasks according to specific instructions. It has two major components: Hardware: composed of electronic and mechanical parts Software: data, and computer programs 2Rommel AB Palomino - UDC Spring 2011
3
Hardware 3Rommel AB Palomino - UDC Spring 2011
4
Software Types of Computer Programs: Operating Systems: Windows, Linux, Solaris Application Programs: Word, Games, Browsers Compilers: Translate high level programming languages into machine language 4Rommel AB Palomino - UDC Spring 2011
5
Programming Languages What is a Programming Language? Express human instructions to computers Each language has its own syntax Languages evolved over time. There exist five different programming languages generations. 5Rommel AB Palomino - UDC Spring 2011
6
Interpreted vs. Compiled Language Interpreted: Source code is directly executed at runtime by the interpreter. Compiled: source code goes to the compiler and creates object code or machine code. Then it is executed in the host CPU. 6Rommel AB Palomino - UDC Spring 2011
7
Interpreted vs. Compiled Language Compiled Needs compilation every time you change the code. Hard to debug Compiled language is faster because source code is reduced to machine code, and then is executed. Interpreted Easy to develop Easy to debug Slower to execute because source code is directly executed (“interpreted”) at runtime 7Rommel AB Palomino - UDC Spring 2011
8
Generation Languages Human Machine 1GL or First Generation: Machine Language (0110101100110000011) 2GL or Second Generation: Assembly languages. push ebx / mov ebx,1 / dec ebx 3GL or Third Generation: more programmer friendly. High level lang. such as C, C++, Java. 4GL or Forth Generation: reduce programming effort, developing time, and cost. 5GL or Fifth Generation: use of constraints rather than an algorithm. Comp. solves problem w/o prog. Use in AI research such as ProLog. Sixth Generation: ??? 8Rommel AB Palomino - UDC Spring 2011
9
Program Development Life Cycle The process of developing a software, according to the desired needs of a user, by following a basic set of interrelated procedures. 9Rommel AB Palomino - UDC Spring 2011
10
Tasks of Program Development Problem Definition Problem Analysis Algorithm design and representation Coding Testing & Debugging Maintenance 10Rommel AB Palomino - UDC Spring 2011
11
Tasks of Program Development Problem Definition Problem Analysis Algorithm design and representation Coding Testing & Debugging Maintenance Define clearly the problem in terms of their inputs, outputs and constraints. A clearly defined problem is half the solution. This step is very critical for success of the completion of the program. Problem Example: “Create a Program that will give the sum of consecutives numbers from 0 to a determined number” Invest a significant portion of your time in this phase! 11Rommel AB Palomino - UDC Spring 2011
12
Tasks of Program Development Problem Definition Problem Analysis Algorithm design and representation Coding Testing & Debugging Maintenance Once identified the problem, we should find the most effective and simplest solution. Divide and Conquer: Break problem into smaller and simple sub- problems Input: certain natural number (n) Output: sum of consecutive natural numbers from 0 to n Problem Example: “Create a Program that will give the sum of consecutives numbers from 0 to a determined number” 12Rommel AB Palomino - UDC Spring 2011
13
Tasks of Program Development Problem Definition Problem Analysis Algorithm Design and Representation Coding Testing & Debugging Maintenance After doing the analysis, we need to design our proposed solution. The solution has to be expressed in a step-by-step manner, so the computer will understand it: Algorithm. Ways of representing it: Human Language: flowchart Pseudocode: human lang/prog. lang. Design techniques: Modular Programming Top-Down Design Structured Programming 13Rommel AB Palomino - UDC Spring 2011
14
Pseudocode 1. Get number “n” 2. Set count to 0 3. Set sum to 0 4. While count is less than or equal to “n“ do Add count value to sum Increment count by 1 5. Return sum Problem Example: “Create a Program that will give the sum of consecutives natural numbers from 0 to a determined number” 14Rommel AB Palomino - UDC Spring 2011
15
Flowchart Process Data Con d Process: represents process of executing an or group of operations that results in a change of value, form or location of information. i.e.: Add 1 to X Sum = sum + 1 Data: Input/output. i.e.: Read N Get N Display X Conditional: Yes/No questions. It has two outputs, one for Yes, and one for No. 15Rommel AB Palomino - UDC Spring 2011
16
Flowchart Terminal Flowline symbol: Represents the flow of information or the correct sequence of steps in the flowchart. Terminal Symbol/Terminator: Represents the start or end point of a flowchart. Connector: Connects parts of flowcharts. 16Rommel AB Palomino - UDC Spring 2011
17
Flowchart Problem Example: “Create a Program that will give the sum of consecutives natural numbers from 0 to a determined number” Start Read n count = 0 sum = 0 count<=n? sum = sum + count count = count + 1 yes Print sum End no 17Rommel AB Palomino - UDC Spring 2011
18
Tasks of Program Development Problem Definition Problem Analysis Algorithm Design and Representation Coding Testing & Debugging Maintenance Algorithm ready! Process of translate it into computer instructions. Each prog. language has its own syntax. Actual software. int n = 5; // let’s pretend we are reading int sum =0, count = 0; while( count <= n ){ sum = sum + count; count = count + 1; } System.out.println(sum); Start Read n count = 0 sum = 0 count<=n? sum = sum + count count = count + 1 yes Print sum End no 18Rommel AB Palomino - UDC Spring 2011
19
Tasks of Program Development Problem Definition Problem Analysis Algorithm Design and Representation Coding Testing & Debugging Maintenance Don’t expect your program works the first time! Debugging: finding errors (bugs) in your program and fix them. Two error types: Compile-time: before running your program. Syntax errors. Runtime: occurs when you are running your program Compile-time error: int n = 0 Runtime error: int n = 0; int x = 5/n; Division by zero! 19Rommel AB Palomino - UDC Spring 2011
20
Tasks of Program Development Problem Definition Problem Analysis Algorithm Design and Representation Coding Testing & Debugging Maintenance Testing: process of validation of the program. Three major types: Unit testing: test basic units of software Integration testing: tests two or more tested units System testing: based on functional/requirement specification Is my program really doing what it was required to do? Look back into your requirements, and your problem definition! Formulate basic tests. i.e. entering the min and max values for parameters. 20Rommel AB Palomino - UDC Spring 2011
21
Tasks of Program Development Problem Definition Problem Analysis Algorithm Design and Representation Coding Testing & Debugging Maintenance Maintenance: Updating and correcting of the program for changing conditions or newly discovered bugs. What if your requirements change? What if your boss wants to add more functionality to your program? Should I start all over again from scratch? NO!!!! … as long as you do all your previous steps correctly, of course. 21Rommel AB Palomino - UDC Spring 2011
22
Exercise Write a program that can calculate the factorial of a given number “n”. 22Rommel AB Palomino - UDC Spring 2011
23
Questions? 23Rommel AB Palomino - UDC Spring 2011
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.