Input/Output Devices

Download Report

Transcript Input/Output Devices

Chapter 1
Introduction to Computers and
C++ Programming
Introduction




A program is a step-by-step series of
instructions for a computer
Programming is the process of writing these
instructions
Programmers, or developers, design and write
programs using a programming language or
development tool
C++ is a programming language that provides
the structure for efficient and economical
programs
Programming a Computer
Companies need developers to build
general application software packages
 Custom applications are built for specific
needs
 Existing programs need maintenance and
upgrades
 New applications will be needed due to
emerging technologies

Programmers follow a general methodology called
the program development cycle to structure
the development process. The phases of the
cycle are
 Analyze the requirements
 Design the solution
 Validate the design
 Implement the design
 Test the solution
 Document the solution
Phase 1 – Analyze Requirements
Verify that the requirements are clear and
complete
 Evaluate the problem to determine that it
is solvable using a program
 List the required input and output data
 Determine whether the input data is
available for testing

Phase 1 – Analyze Requirements
Ensure that a solution, or algorithm, can
be developed with the information
provided in the requirements
 Verify the user interface specifications

Phase 2 – Design Solution



Develop a logical model that illustrates the
sequence of steps you will take to solve the
problem
Use design tools such as storyboards, object
structure diagrams, flowcharts, and pseudocode
to outline the logic of the program
An algorithm is a sequence of precise
instructions that leads to a solution
 Example:
Determine how many times a name
occurs in a list of names
Example: Determine how many times a
name occurs in a list of names
BREAK
Example: Determine how many times a
name occurs in a list of names
1.
2.
3.
4.
Get list of names
Get search name
Establish counter, set to zero
For each name in list:
Compare name in list to search name
2. If list name = search name, increment
counter by one
1.
5.
Answer is the number indicated by the
counter
Phase 2 – Design Solution

Storyboards are sketches of the user
interface
Phase 2 – Design Solution
Flowcharts graphically represent the logic
used to develop an algorithm
 Control structures allow the programmer to
specify the code that will execute only if a
condition is met
 Flowcharts use pseudocode, English, or
mathematical notation inside symbols to
represent the steps of a solution

Phase 2 – Design Solution

Pseudocode is an English representation
of how the program code should be written
Phase 3 – Validate Design
The programmer steps through the
solution with test data
 The user agrees that the program design
solves the problem put forth in the
requirements
 The user verifies that the initial
requirements document contains all
necessary requirements

Phase 4 – Implement Design
Write the code that translates the design
into a program
 Create the user interface
 Create comments within the code that
explains the purpose of the code
 Test the code as it is written
 Test related code

Phase 4 – Implement Design
Phase 5 – Test Solution
Create a test plan with test cases of
sample input data and expected output
 Perform integration testing to ensure that
components interact correctly
 Test boundary values
 Document any problems

 If
results are unsatisfactory, a new iteration of
the development cycle begins
Phase 6 – Document Solution
Requirements documents, program design
documents, user interface documents, and
documentation of the code
 Test cases and proof of successful
completion of testing
 Program code should be archived
electronically

BREAK

gliffy
Object-Oriented Programming and
Design

Object-oriented programming
 Data
and the code that operates on the data
are packaged into a single unit called an
object

Object-oriented design
 Identifies
how objects interact with each other
to solve a problem
Objects

Class


Class diagram


A specific occurrence of an object
Attributes


A tool displaying a hierarchy of classes, including superclasses
and subclasses
Instance


Implementation of an object or set of objects with a common
structure and behavior
The properties of an individual object
Method/function

The code of an operation on the data of an object
Operations

Message
 The
activation of an operation through naming the
object and the operation to be performed on the
object

Trigger
 Impetus

for a sent message
Event
 The
process of a trigger sending a message that
results in an operation
Event Diagrams and UML


Graphically represents relationships among
event and operations
Useful for designing event-driven programs
Encapsulation
The process of hiding the implementation
details of an object from its user
 The user is shielded from the system’s
complexity
 Information hiding provides access to an
object only through its messages
 Objects can be modified without requiring
application modification

Inheritance
An efficient way to reuse code by defining
a subclass as an extension of another
class
 The subclass inherits all the data and
functions of the superclass
 The subclass has at least one attribute or
method that differs from its superclass

Polymorphism
Allows an instruction to be given to an
object using a generalized command
 The same command will obtain different
results depending on the object receiving
the command
 The specific actions internal to the object
are encapsulated from the user

Abstraction
Simplifies complex reality by modeling
classes appropriate to the problem
 Works at most appropriate level of
inheritance for a given aspect of the
problem
 Abstraction is also achieved through
composition (car)

BREAK
Computer Hardware

Computer hardware are the physical
components of the computer.
Input/Output Devices
Input/Output
devices provide communication
between user and hardware.
 Input
Devices
 Keyboard
 Mouse
 Scanner
 Output Devices
 Monitor
 Speakers
 Printer
Processors and Memory

Central Processing Unit (CPU)
 Performs
basic functions, millions and billions
of times per second (brains of the computer)

Random-Access Memory
 Stores
data used by the CPU (before and
after processing)
Data Storage

Data storage uses a variety of
media. Capacity is measured in bits
and bytes:
A
bit represents the on or off state of a
transistor (symbolized by a 1 or a 0).
 A byte is eight bits.
 A kilobyte is 210 or 1,024 bytes.
 A megabyte is 1,048,576 bytes.
Hard Drives

The hard drive is the primary storage
device in a computer. Hard drives are:
 Long
term, rewritable storage
 Large capacity
 Inexpensive
 Fixed media (relatively difficult to move from
one computer to another)
Removable Media

Some storage devices are more
portable:
 CD/DVD
Medium capacity
 Inexpensive
 Easy to transport from one computer to another

 Flash,
Zip, USB drives
Differing capacities
 Differing price per MB

Computer Software

Software can be divided into two
categories:
 Systems
software includes operating systems,
compilers, and utilities.
 Application software runs on top of an
operating system.
What is an operating system?

An operating system (OS) manages the
hardware and software on a computer
system. An OS:
 Manages
memory and hardware resources
 Allocates resources to applications
 Provides a consistent interface for
applications
Operating Systems



UNIX/Linux
 Multiuser OS
 Multitasking
 Runs on many types of hardware
 Modular tools
Mac OS
 First mainstream graphical user interface
 Icons (pictures) and mouse replaced command line interface
DOS/Windows
 DOS gained popularity with first PCs
 Windows provided graphical interface to DOS
 Windows later separated itself from DOS underpinnings
Low-Level Languages

Low-level programming languages use
simple commands to communicate with
the CPU:
 Machine
language (most basic language of
the CPU)
 Assembly language (human readable, but
close to machine language)
High-Level Languages

High-level languages can be
procedural or object-oriented:
 Procedural
languages use a step-by-step process to
solve a problem.
 Basic, Pascal, C
 Object-oriented languages model problems using
objects that correspond to real-world counterparts.
 Smalltalk, C++, Java
Origins of C++
Derived from C, which was derived from B
(short for BCPL), developed in AT&T Bell
Laboratories
 Why ++?
 Early 1980’s
 Most of C is a subset of C++

BREAK
Parts of a Program










User
Programmer
Variable Declarations
Variables
Integer
Statements (executable
statements)
cin and cout
/n
Line breaks and spacing
include directive




int main()
return statement
Compiling and running a
program – what does a
compiler do?
**Test program
Testing and Debugging



bug
debugging
Kinds of Errors:






Syntax error – compile time error (this program won’t run at all) –
you’ve broken a rule of the language
Semantic – compile time error – you’ve changed the meaning of
some word in your code
Run-time error – program compiles fine, and initially runs, but at
some point an error is thrown and the program stops running
Logic error – program compiles fine, runs fine (no error is thrown
throughout execution of the program), BUT the program doesn’t
behave as it was meant to
System – software isn’t installed correctly
Error message vs. warning message