Download presentation
Presentation is loading. Please wait.
Published byBlanche Warner Modified over 8 years ago
1
Programming and Languages Dept. of Computer and Information Science IUPUI
2
Programming as Problem Solving Problem solving principles: 1. Completely understand the problem 2. Devise a plan to solve it 3. Carry out the plan 4. Review the results Developing a Program: 1. Analyze the problem 2. Design the program 3. Code the program 4. Test the program
3
Hardware Machine code Assemblers Compilers Interpreters Progression
4
Hardware encoding Change physical structure of machine Extremely tedious Very difficult Prone to error
5
Programming Languages Programming languages allow programmers to code software. The three major families of languages are: Machine languages Assembly languages High-Level languages
6
Machine Language Stored Language Concept Von Neumann Treat Instructions as data Comprised of 1s and 0s The “native” language of a computer Difficult to program – one misplaced 1 or 0 will cause the program to fail. Example of code: 1110100010101 111010101110 10111010110100 10100011110111
7
Assembly Languages Mnemonics Labeled cells somewhat easier on programmers Assembly languages are a step towards easier programming. Assembly languages are comprised of a set of elemental commands which are tied to a specific processor. Assembly language code needs to be translated to machine language before the computer processes it. Example: ADD 1001010, 1011010
8
High-level Language Typed in near-human language Converted to assembler Much easier on programmers Can be assembled or compiled Language is still very precise, but more nearly readable High-level languages represent a giant leap towards easier programming. The syntax of HL languages is similar to English. Historically, we divide HL languages into two groups: Procedural languages Object-Oriented languages (OOP)
9
Procedural Languages Early high-level languages are typically called procedural languages. Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript
10
Most object-oriented languages are high-level languages. The focus of OOP languages is not on structure, but on modeling data. Programmers code using “blueprints” of data models called classes. Examples of OOP languages include C++, Visual Basic.NET and Java. Object-oriented
11
Interpreting Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed. Interpreter runs in background Instructions are translated in real time high-level code is distributed More flexible Slower
12
Compiling Some programs are translated using a compiler. When programs are compiled, they are translated all at once. Compiled programs typically execute more quickly than interpreted programs, but have a slower translation speed. Compiler converts entire program into machine language binary code is distributed Less flexible Faster Regardless of the HL Language, all HL programs need to be translated to machine code so that a computer can process the program.
13
Structured Programming A method for designing and coding programs in a systematic, organized manner. It combines the principles of top-down design, modularity and the use of the three accepted control structures of sequence, repetition and selection.
14
Control Structures Sequence –in sequential order. The simplest of control structures – start at the beginning and continue in sequential order. Selection – selectively execute statements Called a branch, it requires a condition to determine when to execute statements.
15
Control Structures Repetition – repeat statements more than once Called a loop, it needs a stop condition, I.e, the program will continue to loop until some condition is met.
16
Sequence Structure Start – where the program begins Input – data to be used for the program Step One, Step Two, etc. – the sequence of the program until it finishes No deviation
17
Selection Structure Start the program Input – data to be used Asking the question; only one question The answer, YES or NO Depending on the answer, the action to be taken The program moves on or ends
18
Loop Structure Program starts The condition is set Input – ask for password Answer is evaluated, compared to condition If no, action of asking for password continues until input of correct password
19
Event-Driven Programming In an event-driven program, the flow of control is based on the user’s clicking on menus and buttons, etc. These user actions are called events. Event-driven programming still uses the basic principles of structured programming – program modules, control structures, good programming style, and program testing.
20
Types of Errors Syntax – wrong grammar, i.e., breaking the rules of how to write the language Forgetting punctuation, misspelling keyword The program will not run at all with syntax errors Logic - the program runs, but does not produce the expected results. Using an incorrect formula, incorrect sequence of statements, etc.
21
Programming Example Simple programming problem: Convert a price from British pounds into Dollars. Pseudocode Input the price of the item, PoundPrice, in pounds Compute the price of the item in dollars: Set DollarPrice = 1.62 * PoundPrice Write DollarPrice
22
Programming Example Translating to Basic: INPUT PoundPrice LET DollarPrice = 1.62 * PoundPrice PRINT DollarPrice END
23
<!– var strUserName = ""; // user's name, this is a STRING var strUserCity = ""; // user's city, this is a STRING var intNumLetters = 0; // number of letters in user's first name, this is an INTEGER var strMessage = "" // output to the user, this is a STRING strUserName = window.prompt("What is your name?"); //this is asking for the user's name strUserCity = window.prompt("Where do you live?"); //this is asking what city does the user live in strMessage = ("Hello, "); strMessage += (strUserName.toUpperCase()); //this puts the user's name into uppercase letters strMessage += (". You live in "); strMessage += (strUserCity.toUpperCase()); //this puts the user's city into uppercase letters window.alert(strMessage); //this is the message given to the user intNumLetters = strUserName.length; // output to the user window.alert("There are " +intNumLetters+" letters in your first name."); //this is a string method, it is counting the number of letters in the user's name //this tells the user how many letters that user has in their name // -->
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.