introduction to computers, problem solving, and programming chapter 1

57
Introduction to Computers, Problem Solving, and Programming Chapter 1

Upload: leo-davis

Post on 25-Dec-2015

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to Computers, Problem Solving, and Programming Chapter 1

Introduction to Computers, Problem Solving, and

ProgrammingChapter 1

Page 2: Introduction to Computers, Problem Solving, and Programming Chapter 1

2

Computer - “A device for counting or computing” Dr. John Atanasoff - 1st computer (1930). ENIAC 1946 at U of Penn (30 Tons, 30-by-50 foot space,

data in memory, programmed by connecting switches and wires)

Dr. John Von Neumann - Princeton– Stored program concept– Memory rather than wires and switches.

Evolution– 1970s: Apple microcomputers– Minicomputers – Mainframes (time-sharing systems)– Supercomputers: for very computing-intensive tasks– Personal computers/Workstations– Laptops

1.1 Overview of Computers

Page 3: Introduction to Computers, Problem Solving, and Programming Chapter 1

3

Von Neumann architecture basis for today's computers

VLSI Technology made computers affordable, small and available to the public

How programming has changed over time

Overview of Computers

Page 4: Introduction to Computers, Problem Solving, and Programming Chapter 1

4

Every computer is organized roughly into six parts– CPU - central processing unit

• Where decisions are made, computations are performed, and input/output requests are delegated

– Main Memory• Stores information being processed by the CPU

– Secondary Memory• Stores data and programs

1.2 Computer Hardware

Page 5: Introduction to Computers, Problem Solving, and Programming Chapter 1

5

– Input devices• Allows people to supply information to computers

– Output devices• Allows people to receive information from

computers

– Network connection• Modems / Ethernet interface

Computer Hardware

Page 6: Introduction to Computers, Problem Solving, and Programming Chapter 1

6

Computer Components

Page 7: Introduction to Computers, Problem Solving, and Programming Chapter 1

7

Main Memory

-27.2

354

.005

75.62

Address Contents

0

1024

1

Page 8: Introduction to Computers, Problem Solving, and Programming Chapter 1

8

Main Memory

Stores – programs– data– results

Types– RAM– ROM

Page 9: Introduction to Computers, Problem Solving, and Programming Chapter 1

9

Secondary Memory & Storage

Semi permanent data-storage capability– Tape or Disk– Hard disk– CD ROM

Secondary memory has much more storage capacity

Page 10: Introduction to Computers, Problem Solving, and Programming Chapter 1

10

CPU

“Brains” of the computer– Arithmetic calculations are performed using the

Arithmetic/Logical Unit or ALU– Control unit decodes and executes instructions

Arithmetic operations are performed using binary number system

Page 11: Introduction to Computers, Problem Solving, and Programming Chapter 1

11

CPU Fundamental building block is a switch

– Switches are made from ultrasmall transistors Examples

– The Pentium ® processor contains about three million transistors

– The Pentium Pro ® has about 5.5 million transistors

Page 12: Introduction to Computers, Problem Solving, and Programming Chapter 1

12

Input / Output Devices Accessories that allow computer to perform

specific tasks– Receiving information for processing– Return the results of processing– Store information

Common input and output devices– Printer Joystick CD-ROM– Keyboard Monitor

Page 13: Introduction to Computers, Problem Solving, and Programming Chapter 1

13

Computer Networks

LAN - Local area network– Organizational

WAN - Wide area network– Internet

Page 14: Introduction to Computers, Problem Solving, and Programming Chapter 1

14

World Wide Web

Introduced 1989 Developed by CERN

– European Laboratory for Particle Physics Web browser

– GUI– Netscape– IE

Page 15: Introduction to Computers, Problem Solving, and Programming Chapter 1

15

Application software– Programs designed to perform specific tasks that

are transparent to the user System software

– Programs that support the execution and development of other programs

– Two major types• Operating systems• Translation systems

1.3 Computer Software

Page 16: Introduction to Computers, Problem Solving, and Programming Chapter 1

16

Application Software Application software is the software that has

made using computers indispensable and popular Common application software

– Word processors– Desktop publishing programs– Spreadsheets– Presentation managers– Drawing programs

Page 17: Introduction to Computers, Problem Solving, and Programming Chapter 1

17

Controls and manages the computing resources Important services that an operating system provides

– File system

– Commands that allow for manipulation of the file system

– Ability to perform input and output on a variety of devices

– Management of the running systems Examples

– MSDOS ®, Windows ®, Unix ®

Operating System

Page 18: Introduction to Computers, Problem Solving, and Programming Chapter 1

18

Programming Languages Machine Language

– “Native tongue” of the computer– Binary 0s and 1s that specify what to do

• 0010 0000 0000 0100• 1000 0000 0000 0101• 0011 0000 0000 0110

Assembly language– Mnemonic code

High - Level Languages– Resemble human language (C++, C, Pascal)

• cost = price + tax;

Page 19: Introduction to Computers, Problem Solving, and Programming Chapter 1

19

Programming Languages Language Standard

– Syntax (grammatical form) (=> rules)– Portability

• programs ideally need no modification when moved from one machine to another

Source Program Object Program Executable Program

Page 20: Introduction to Computers, Problem Solving, and Programming Chapter 1

20

Object Oriented Programming OOP derived from C Bjarne Stroustrup (AT&T) Since mid-1980s, standard 1998 Popular a.o. because of:

– Reuse of Classes and objects

– Efficiency Class

– Definition of attributes and methods of an object Method

– An operation that uses the object data

Page 21: Introduction to Computers, Problem Solving, and Programming Chapter 1

21

OO Programming and Structured Programming

Object– An instance of a class that has all the attributes and

methods included in the class definition C++ is organized in a hierarchy

– Super Classes (“Father Classes”)• It includes some of attributes and methods of a subclass

– Sub Classes (Son Classes)• It is derived from a super class and it may contain own

attributes and methods Object-oriented design and programming supports good

software engineering– Algorithms operate on well-defined data

Page 22: Introduction to Computers, Problem Solving, and Programming Chapter 1

22

OO Programming and Structured Programming

Object-oriented design promotes thinking about software in a way that models the real world– Objects may model real things

Algorithms are the basis for the procedural sections (Structured Programs)– Highly structured– Top-down design– Step-wise refinement

Procedural languages (e.g. C, Pascal, Fortran):– No clear relationship between algorithms and data– OO tries to fill this gap

Page 23: Introduction to Computers, Problem Solving, and Programming Chapter 1

23

Object Oriented Design Abstraction (Different views on the same object!)

– Extract the relevant properties of an object while ignoring inessential details

– Ignore irrelevant properties Encapsulation (Access only through interfaces!)

– Breaking down an object into parts, hiding and protecting its essential information, and supplying an interface to modify the information in a controlled and useful manner

Page 24: Introduction to Computers, Problem Solving, and Programming Chapter 1

24

Object Oriented Design Modularity

– Dividing an object into smaller pieces or modules such that the object is easier to understand and manipulate

– E.g. “Consists–of” relationship! Hierarchy

– Ranking or ordering of objects based on some relationship between them

– E.g. “Is-A” relationship!

Page 25: Introduction to Computers, Problem Solving, and Programming Chapter 1

25

Process of extracting only the relevant properties of an object

Extracted properties define a view of the object

Different contexts may have different views or abstractions

Abstraction

Page 26: Introduction to Computers, Problem Solving, and Programming Chapter 1

26

Examples:– Car dealer views a car from selling features

standpoint • Price, warranty, color, etc.

– Mechanic views a car from systems maintenance standpoint

• Oil, oil filter, spark plugs, etc.

– Abstraction depends on the context

Abstraction

Page 27: Introduction to Computers, Problem Solving, and Programming Chapter 1

27

Encapsulation Breaking down an object into parts, hiding

and protecting its essential information, and supplying an interface to modify the information in a controlled and useful manner

By hiding the information its representation and content can be changed without affecting other parts of the system

Page 28: Introduction to Computers, Problem Solving, and Programming Chapter 1

28

Encapsulation

Example - car radio– Controlled by switches and buttons– The details of how it works is hidden– No manipulation of the car radio is allowed

except using the provided switches and buttons Encapsulation restricts the use to interfaces

Page 29: Introduction to Computers, Problem Solving, and Programming Chapter 1

29

Modularity Dividing an object so that the object holds

useful information and it is easier to understand

Most complex systems are modular– Cooling System– Ignition System– Fuel System

Page 30: Introduction to Computers, Problem Solving, and Programming Chapter 1

30

Modularity Example - Automobile can be decomposed into

subsystems– Cooling system

• Radiator

• Thermostat

• Water pump

– Ignition system• Battery

• Starter

• Spark plugs

Page 31: Introduction to Computers, Problem Solving, and Programming Chapter 1

31

Hierarchy

Ranking or ordering of objects based on some relationship between them

Hierarchies facilitate understanding complex organizations and systems– Example - a company hierarchy helps

employees understand the structure of their company and their positions

Page 32: Introduction to Computers, Problem Solving, and Programming Chapter 1

32

Hierarchy

Example: Means oftransportation

Train Car

BMWVW

- Color- Year

- Type- # Wagons

- # Doors- Fuel type

Page 33: Introduction to Computers, Problem Solving, and Programming Chapter 1

33

OO Classes

Later we will use data abstractions– C++ language

Will apply OO techniques – Structured Programming– Object Oriented Programming

Model our own objects or abstractions

Page 34: Introduction to Computers, Problem Solving, and Programming Chapter 1

34

1.4 Processing a High-Level Language Program

Set of programs used to develop software A key component is a translator Types of translators

– Compiler– Linker

Examples– g++, Borland C++ ®, Microsoft Visual C++ ®

Page 35: Introduction to Computers, Problem Solving, and Programming Chapter 1

35

Processing a Program Editor used to enter the program

– Source program (file.cpp)– UNIX vi text editor

Compiler translates the source program– Displays syntax errors (not descriptive)

Linker/Loader to combine object file with other object files– Executable program

Page 36: Introduction to Computers, Problem Solving, and Programming Chapter 1

36

Processing a Program Major activities

– Editing– Compiling– Linking with pre-compiled files

• Object files

• Library modules

– Loading and executing– Viewing the behavior of the program

Page 37: Introduction to Computers, Problem Solving, and Programming Chapter 1

37

Process Cycle

Page 38: Introduction to Computers, Problem Solving, and Programming Chapter 1

38

1.5 Software Development Method

Steps for any Software development process– 1. Specify the problem requirement– 2. Analyze the problem– 3. Design an algorithm for solving the problem– 4. Implement the algorithm– 5. Test and verify the program– 6. Maintain and update the program

Page 39: Introduction to Computers, Problem Solving, and Programming Chapter 1

39

Software Development Method

Problem requirement– What is the problem exactly?– Eliminate irrelevant aspects– Clear and unambiguous problem statement– Needs interaction with the person who posed the problem

Problem Analysis - (Correct Problem)– Identify data objects– Determine Input / Output data– Identify constraints on the problem/solution

These two steps are very important for avoiding to solve the wrong problem

Page 40: Introduction to Computers, Problem Solving, and Programming Chapter 1

40

Software Development Method

Example– Problem:

Compute and display the total cost of apples given the number of pounds of apples and the cost per pound of apples

– Analysis:• Inputs:

– Quantity of apples in pounds– Cost per pound

• Output:– Total costs (in dollars)

• Main formula:– Total cost = Cost per pound * Pounds of apples

Page 41: Introduction to Computers, Problem Solving, and Programming Chapter 1

41

Software Development Method

Design– Problem solving step– Decompose into smaller problems– Top-down design (divide and conquer)– Develop Algorithm

• Algorithm: List of steps to solve a problem• Algorithm refinement: Developing a sub-algorithm for a

particular step in the main algorithm

– Desk check• Simulate the algorithm execution for simple interesting cases

using pencil and paper

Page 42: Introduction to Computers, Problem Solving, and Programming Chapter 1

42

Software Development Method

Implementation

– Writing the algorithm in a special programming language e.g. C++

– Requires understanding the algorithmic notation as well as the details of the respective programming language

Testing

– Verify that the program meets its requirements

– Unit test (only one sub-problem)

– System test (whole problem)

– Test coverage! Documentation

– Key part in the development process

– Accompanying activity in each phase

Page 43: Introduction to Computers, Problem Solving, and Programming Chapter 1

43

Software Development Method

Maintenance:– Modify a program to remove errors– Modify a program in order to extend it– Initial programmer is very often not the person who

does maintenance!– Understandability of code, use of guidelines

Failure is a part of the process– The step-by-step development help avoid failures– But there are no guaranties– Importance of documentation

Page 44: Introduction to Computers, Problem Solving, and Programming Chapter 1

44

Software Development Method

Software engineering– Area of computer science concerned with:

• Building large software systems

• Providing solutions for efficient and effective software development

Challenge– Tremendous advances in hardware have not been

accompanied by comparable advances in software

– => Software crisis

Page 45: Introduction to Computers, Problem Solving, and Programming Chapter 1

45

Software Engineering Goals Reliability

– An unreliable life-critical system can be fatal– Software is in general more expensive and less reliable

than hardware– E.g. Year 2000 problem– Maintenance affects availability

Understandability– Future development becomes very difficult if software is

hard to understand Cost Effectiveness

– Cost to develop and maintain should not exceed profit

Page 46: Introduction to Computers, Problem Solving, and Programming Chapter 1

46

Software Engineering Goals

Adaptability

– Ease of modification in the program or in its environment

– System that is adaptive is easier to alter and expand Reusability

– Reduces development costs

– Improves reliability and maintainability

– (Exception: Reuse of unreliable software)

Page 47: Introduction to Computers, Problem Solving, and Programming Chapter 1

47

1.6 Applying the Software Development Method

Case Study: Converting Miles to Kilometers

– Problem  Your summer surveying job requires you to study some maps that give distances in kilometers and some that use miles. You and your coworkers prefer to deal in metric measurements. Write a program that performs the necessary conversion.

Page 48: Introduction to Computers, Problem Solving, and Programming Chapter 1

48

Applying the Software Development Method

– Analysis  The first step in solving this problem is to determine what you are asked to do. You must convert from one system of measurement to another, but are you supposed to convert from kilometers to miles, or vice versa? The problem states that you prefer to deal in metric measurements, so you must convert distance measurements in miles to kilometers.

Page 49: Introduction to Computers, Problem Solving, and Programming Chapter 1

49

Applying the Software Development Method

– Design  The next step is to formulate the algorithm that solves the problem. Begin by listing the three major steps, or sub problems, of the algorithm.

• 1. Get distance in miles

• 2. Convert to kilometers

• 3. Display distance in kilometers

Refinement of step 2:

• The distance in kilometers is 1.609 times the distance in miles

Desk check

• 10 miles * 1.609 = 16.09 km (this would be displayed)

– Implementation  To implement the solution, you must write the algorithm as a C++ program.

– Testing  How do you know the sample run is correct?

Page 50: Introduction to Computers, Problem Solving, and Programming Chapter 1

50

Applying the Software Development Method

C++ code:#include <iostream>Using namespace std<int main() {

const Km_Per_Mile = 1.609;float miles, kms;// Get distance in milescout << “Enter distance in miles: ”;cin >> miles;// convert to kilometers

kms = Km_Per_Mile * miles;// display distance in kilometerscout << “The distance in kms is “ << kms << endl;return 0;

}

Page 51: Introduction to Computers, Problem Solving, and Programming Chapter 1

51

1.7 Professional Ethics for Computer Programmers

Privacy and Misuse of Data

– Falsifying data in a database

– Computer thefts Computer Hacking

– Breaking secure systems e.g. for amusement

– Spreading viruses in a network Plagiarism and Software Piracy

– Using foreign programs without permission

– Violating copyright agreements Misuse of a Computer Resource

– Illegal sharing of accounts and passwords in order to access special systems and databases

Page 52: Introduction to Computers, Problem Solving, and Programming Chapter 1

52

1.8 Summary

History– 1930 first computer– Eniac: programmed by hand– Von-Neumann: stored program concept

Components of computers– CPU (Central processing unit)

• Control Unit• Arithmetic and Logic Unit (ALU)

– Main Memory• Addresses• Data: Bytes, Bits, Words

Page 53: Introduction to Computers, Problem Solving, and Programming Chapter 1

53

1.8 Summary

– Secondary storage (unit is file)• Disks• Tapes• Floppy• CDs• Removable disks

– I/O devices• Keyboard (i)• Monitor (o)• Printer (o)• Modem (i/o)

Page 54: Introduction to Computers, Problem Solving, and Programming Chapter 1

54

1.8 Summary

Computer networks– LAN– WAN– WWW

Software– Operating system– Compilers – Application software

Page 55: Introduction to Computers, Problem Solving, and Programming Chapter 1

55

1.8 Summary

Programming Languages– High level language (e.g. procedural, oo, logic,

functional)– Assembly language– Machine language

Tools for program development– Editor– Compiler– Linker– Loader

Page 56: Introduction to Computers, Problem Solving, and Programming Chapter 1

56

1.8 Summary

Basic concepts of OO programming– Class– Object– Method– Abstraction– Encapsulation– Modularity– Hierarchy

Page 57: Introduction to Computers, Problem Solving, and Programming Chapter 1

57

1.8 Summary

Basic steps of software development– Specification of the problem– Analysis– Design– Implementation– Test– Maintenance

Failures ! Software Engineering Goals (e.g. reliability, cost

effectiveness, reusability) Ethics in the use of computers