Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOFTWARE DESIGN & DEVELOPMENT

Similar presentations


Presentation on theme: "SOFTWARE DESIGN & DEVELOPMENT"— Presentation transcript:

1 SOFTWARE DESIGN & DEVELOPMENT
Programming Foundations

2 Lecture Topics The Evolution of Hardware & Software
Computer Components Computer Programming Programming Life-Cycle Phases Creating an Algorithm Machine Language vs. High Level Languages Compilation and Execution Processes Generic instruction functionality & control structures Two different approaches to building program modules Case study

3 Evolution of Hardware Generation Time Period Principal Events
1642 – 1945 Mechanical calculators 1 1945 – 1955 Vacuum tubes 2 1955 – 1965 Transistors 3 1965 – 1971 Integrated circuits 4 1971 – Present Computer chips

4 Evolution of Hardware (Pre 1900)
Abacus  first known calculating machine; used for more than 4,000 years 1623  first mechanical calculator (Schickard) 1642  first automatic mechanical calculator (Pascal) 1804  punched block (Jacquard); forerunner of what we now call programming 1822 & 1833  Babbage invented difference engine and then an analytical engine ( a general purpose calculating device) 1854  Boole created an algebra based on logic 1886  Hollerith created punched cards which reduced the time needed to tabulate US census by more than 50%

5 Evolution of Hardware (Post 1900)
1945  Von Neumann created a computer which was the first to use the idea of a stored program 1949  Cambridge Uni: first large scale computer using stored-program concept 1951  first commercial computer, the UNIVAC 1954  first transistorized computer by Bell Labs 1960’s  advent of minicomputers using integrated circuits 1971  Intel 4004 chip starts evolution of placing power of large scale computer in a very small area 1970’s first PC’s & supercomputers 1980’s  networks of computers of varying computing power

6 Computer Architectures
Traditional design of a general purpose computer is called a Von Neumann computer – instructions and data co-exist in RAM Such a machine fetches an instruction from memory, decodes the instruction, and then executes it One way to use such a computer is by pipelining (see following) Not all computers are of this type. Other types include: A parallel processing computer (share memory & control unit) An array processor (each processor has own memory but share the same control unit) Variations on the former two parallel processing options Reduced instruction set computers

7 An example of pipelining
Time Time+1 Time+2 Time+3 Time+4 Time+5 Time+6 Time+7 Inst. # 1 Fetch Decode Execute Inst. # 2 Inst. # 3 Inst. # 4 Inst. # 5 Inst. # 6 ….

8 Software Evolution Generation Time period Principal Events 1
1945 – present Machine languages (binary form) 2 1953 – present Assembly languages (symbolic mnemonic code) 3 present High level languages (Fortran, COBOL, Basic, C) 4 1971 (OOP’s) 1980’s (4GL’s) – present 4GL’s using databases, OOP languages (Smalltalk, C++) 5 present Logic programming (Prolog)

9 Memory Unit ( RAM & Registers )
Computer Components Peripherals Central Processing Unit ( CPU ) Input Device Control Unit Arithmetic Logic Unit Output Device Auxiliary Storage Device Memory Unit ( RAM & Registers )

10 Memory Unit is an ordered sequence of storage cells, each capable of holding a piece of information each cell has its own unique address the information held can be input data, computed values, or your program instructions.

11 Central Processing Unit
has 2 components to execute program instructions Arithmetic/Logic Unit performs arithmetic operations, and makes logical comparisons. Control Unit controls the order in which your program instructions are executed.

12 Peripherals are input, output, or auxiliary storage devices attached to a computer Input Devices include keyboard and mouse. Output Devices include printers, video display, LCD screens. Auxiliary Storage Devices include disk drives, scanners, CD-ROM and DVD-ROM drives, modems, sound cards, speakers, and digital cameras.

13 What is Programming? Planning or scheduling the performance of a task or event. Computer: a programmable device that can store, retrieve, and process data STEP 1 STEP 2 STEP 3

14 What is Computer Programming?
It is the process of planning a sequence of steps (called instructions) for a computer to follow. Computer program: A sequence of instructions to be performed by a computer We, as humans, must specify what we want done and the order in which we want it done. STEP 1 STEP 2 STEP 3

15 Programming Life Cycle Phases
Problem-Solving Implementation Maintenance

16 Problem-Solving Phase
ANALYZE the problem and SPECIFY what the solution must do develop a GENERAL SOLUTION (ALGORITHM) to solve the problem VERIFY that your solution really solves the problem

17 Sample Problem A programmer needs an algorithm to determine an employee’s weekly wages. How would the calculations be done by hand?

18 One Employee’s Wages In one week an employee works 52 hours at the hourly pay rate of $ Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5 What are the employee’s wages? 40 x $ = $ 12 x 1.5 x $ = $ ___________ $

19 Weekly Wages, in General
If hours are more than 40.0, then wages = (40.0 * payRate) + (hours ) * 1.5 *payRate otherwise, wages = hours * payRate RECALL EXAMPLE ( 40 x $ ) + ( 12 x 1.5 x $ ) = $

20 An Algorithm is . . . a step-by-step procedure for solving a problem in a finite amount of time.

21 Algorithm to Determine an Employee’s Weekly Wages
1. Get the employee’s hourly payRate 2. Get the hours worked this week 3. Calculate this week’s regular wages 4. Calculate this week’s overtime wages (if any) 5. Add the regular wages to overtime wages (if any) to determine total wages for the week

22 What is a Programming Language?
It is a language with strict grammar rules, symbols, and special words used to construct a computer program.

23 Implementation Phase: Program
translating your algorithm into a programming language is called CODING with C++, you use Documentation -- your written comments Compiler -- translates your program into machine language Main Program -- may call subalgorithms

24 Implementation Phase: Test
TESTING your program means running (executing) your program on the computer, to see if it produces correct results if it does not, then you must find out what is wrong with your program or algorithm and fix it--this is called debugging

25 Maintenance Phase USE and MODIFY the program to meet changing requirements or correct errors that show up in using it maintenance begins when your program is put into use and accounts for the majority of effort on most programs

26 Programming Life Cycle
Problem-Solving Phase Analysis and Specification General Solution ( Algorithm ) Verify Implementation Phase Concrete Solution ( Program ) Test Maintenance Phase Use Maintain

27 A Tempting Shortcut? DEBUG REVISE REVISE DEBUG DEBUG REVISE Shortcut?
CODE GOAL TEST THINKING CODE

28 Memory Organization two circuit states correspond to 0 and 1
bit (short for binary digit) refers to a single 0 or 1. Bit patterns represent both the computer instructions and computer data 1 byte = 8 bits 1 KB = bytes 1 MB = x = 1,048,576 bytes

29 How Many Possible Digits?
binary (base 2) numbers use 2 digits: JUST 0 and 1 decimal (base 10) numbers use 10 digits: 0 THROUGH 9

30 Machine Language is not portable
runs only on specific type of computer is made up of binary-coded instructions (strings of 0s and 1s) is the language that can be directly used by the computer

31 High Level Languages are portable
user writes program in language similar to natural language examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java most are standardized by ISO/ANSI to provide an official description of the language

32 Three C++ Program Stages
myprog.cpp myprog.obj myprog.exe SOURCE OBJECT EXECUTABLE written in machine language C++ via compiler via linker other code from libraries, etc.

33 Java Programming Language
achieves portability by using both a compiler and an interpreter first, a Java compiler translates a Java program into an intermediate bytecode--not machine language then, an interpreter program called the Java Virtual Machine (JVM) translates a single instruction in the bytecode program to machine language and immediately runs it, one at a time

34 The computer program translation process?
Computers are stupid, they understand only ones and noughts, or more properly high and low voltages on their internal sets of wires. Thus might be a program to a computer. This is called machine code.

35 Assemblers and Mnemonics
Machine code is a bit difficult to read and to program in It is also easy to make mistakes in machine code. What about a language that uses a code instead of a machine instruction, in fact a mnemonic A program called an assembler can turn these mnemonics into machine code relatively easily; this is because the relationship between an assembly language instruction and a machine instruction is close to 1:1.

36 Assembly language programs
Consider this assembly language program LD A,06H LD C,A LD A,07H LD E,A SLL C,02H LD A,E LD 96H,A DEC DE LD A,D OUT A,044H LD 97HA Assembly languages are low level programming languages because they are “close” to the processor. Each processor will have its own assembly language Mnemonics English

37 High Level programming languages
Fortran Formulae Translator COBOL Common Business Oriented Language These programs were more orientated to the human rather than the machine. COBOL: MOVE ER-EMPLOYEE-LINE-OUT TO ER-EMPLOYEE-HIRE-YEAR-OUT READ NAME-ADDRESS-FILE-IN AT END MOVE "YES" TO WS-END-OF-FILE-SWITCH. A high level program requires a program to convert it into executable code: a Compiler.

38 Compilers and compiling?
Compilers must examine and interpret the computer program. It must then produce code that can execute or run on the computer processor. This usually takes place in a number of stages, which are for the most part hidden from the programmer. First of all the programmer must place his/her program in a text file. These consist of data definitions and instructions to the computer. The compiler must firstly check that you have obeyed the grammatical rules of the language.

39 The compilation process from the programmers view
Edit Compilation Source code (.cpp file) Object code (.obj file) Error listing on the standard output. In your case to the screen. Errors detected

40 Compiler processes The code is then compiled proper and then an assembly process is performed Some compilers allow you to have a look at the assembly language generated from your program It will be A LOT! Some languages just go straight to the linking stage from the compilation stage. Linking locates and incorporates into your final executable file those bits of code that have been pre-written for you. Most often the I/O code has been pre-written.

41 Compiler processes Pre-compiled programs such as I/O (.obj files)
Linking Edit Source code (.cpp file) Compilation Object code (.obj file) Executable code (.exe file) Error listing on the standard output. In your case to the screen. Errors detected

42 Computer Program Instructions
“The instructions in a programming language reflect the operations a computer can perform: A computer can transfer data from one place to another A computer can input data from an input device …. and output data to an output device…. A computer can store data into and retrieve data from its memory and secondary storage… A computer can compare two data values for equality and inequality A computer can perform arithmetic operations … very quickly” (page 14, from the text) To implement these operations requires the use of certain control structures…..

43 Basic Control Structures
a sequence is a series of statements that execute one after another selection (branch) is used to execute different statements depending on certain conditions Looping (repetition) is used to repeat statements while certain conditions are met. a subprogram is used to break the program into smaller units

44 SEQUENCE Statement Statement Statement . . .

45 SELECTION (branch) IF Condition THEN Statement1 ELSE Statement2 True
. . . Statement2 False

46 LOOP (repetition) WHILE Condition DO Statement1 False . . . Condition
True Statement

47 SUBPROGRAM (function)
. . . SUBPROGRAM1 SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM

48 Two Approaches to Building Manageable Modules
FUNCTIONAL DECOMPOSITION OBJECT-ORIENTED DESIGN Divides the problem into more easily handled subtasks, until the functional modules (subproblems) can be coded. Identifies various objects composed of data and operations, that can be used together to solve the problem. FOCUS ON: processes FOCUS ON: data objects

49 Functional Design Modules
Find Weighted Average Print Main Get Data Prepare File for Reading Print Data Print Heading

50 Object-Oriented Design
A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. cin cout >> << get Private data setf Private data . . ignore

51 Procedural vs. Object-Oriented Code
“Read the specification of the software you want to build. Underline the verbs if you are after procedural code, the nouns if you aim for an object-oriented program.” Brady Gooch, “What is and Isn’t Object Oriented Design,”

52 Company Payroll Case Study
A small company needs an interactive program to figure its weekly payroll. The payroll clerk will input data for each employee, and each employee’s wages and data should be saved in a secondary file. Display the total wages for the week on the screen.

53 One Employee’s Wages In one week employee ID # 4587 works hours at the hourly pay rate of $ Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5. What are the employee’s wages? 40 x $ = $ 12 x 1.5 x $ = $ ___________ $

54 Problem-Solving Phase
What information will be used? INPUT DATA from outside the program FORMULA CONSTANTS used in program COMPUTED VALUE produced by program OUTPUT RESULTS written to file or screen by program

55 Problem-Solving Phase
INPUT DATA FORMULA CONSTANTS OUTPUT RESULTS Employee ID Number Hourly payRate Hours worked Normal work hours ( 40.0 ) Overtime pay rate factor (1.5) Hourly payRate Hours worked Wages COMPUTED VALUE Wages

56 Week’s Wages, in General
If hours are more than 40.0, then wages = (40.0 * payRate) + (hours ) * 1.5 *payRate otherwise, wages = hours * payRate RECALL EXAMPLE ( 40 x $ ) + ( 12 x 1.5 x $ ) = $

57 Algorithm for Company Payroll Program
initialize total company payroll to 0.0 repeat this process for each employee: 1. Get the employee’s ID empNum 2. Get the employee’s hourly payRate 3. Get the hours worked this week 4. Calculate this week’s wages 5. Add wages to total company payroll 6. Write empNum, payRate, hours, wages to file write total company payroll on screen

58 C++ Program // ***************************************************
// Payroll program // This program computes each employee’s wages and // the total company payroll #include <iostream> // for keyboard/screen I/O #include <fstream> // for file I/O using namespace std; void CalcPay ( float, float, float& ) ; const float MAX_HOURS = 40.0; // Maximum normal hours const float OVERTIME = 1.5; // Overtime pay factor

59 C++ Code Continued int main( ) { float payRate; // Employee’s pay rate
float hours; // Hours worked float wages; // Wages earned float total; // Total company payroll int empNum; // Employee ID number ofstream payFile; // Company payroll file payFile.open( “payfile.dat” ); // Open file total = 0.0; // Initialize total

60 cout << “Enter employee number: “; // Prompt
cin >> empNum; // Read ID number while ( empNum != 0 ) // While not done { cout << “Enter pay rate: “; cin >> payRate ; // Read pay rate cout << “Enter hours worked: “; cin >> hours ; // and hours worked CalcPay(payRate, hours, wages); // Compute wages total = total + wages; // Add to total payFile << empNum << payRate << hours << wages << endl; cout << “Enter employee number: “; cin >> empNum; // Read ID number }

61 cout << “Total payroll is “
<< total << endl; return 0 ; // Successful completion } // *************************************************** void CalcPay ( /* in */ float payRate , /* in */ float hours , /* out */ float& wages ) // CalcPay computes wages from the employee’s pay rate // and the hours worked, taking overtime into account { if ( hours > MAX_HOURS ) wages = (MAX_HOURS * payRate ) + (hours - MAX_HOURS) * payRate * OVER_TIME; else wages = hours * payRate;


Download ppt "SOFTWARE DESIGN & DEVELOPMENT"

Similar presentations


Ads by Google