Chapter 1: Introduction To Computers, Problem Solving, and Programming
Chapter 1: Introduction To Computers, Problem Solving, and Programming
Early Computers
Late1930s,JohnAtanasoff,CliffordBerry
ENIAC
1946
UniversityofPennsylvania
J.PresperEckertandJohnMauchley
JohnvonNeumann,storedprogramconcept
Computer Hardware
CPUcentralprocessingunit
Wheredecisionsaremade,computationsare
performed,andinput/outputrequestsare
delegated
MainMemory
StoresinformationbeingprocessedbytheCPU
SecondaryMemory(MassStorage)
Storesdataandprograms
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Computer Hardware
Inputdevices
Allowpeopletosupplyinformationtocomputers
Outputdevices
Allowpeopletoreceiveinformationfromcomputers
Networkconnection
Modems
Ethernetinterface
Figure 1.2
Computer components
Memory
Stores
programs
operatingsystem
applications
data
Types
RAMvolatile
ROM
Composedofbits,whicharecombinedinto
bytes
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Memory Cells
Address Contents
0
1
2
3
4
5
6
...
999
-27.2
354
0.005
-26
H
RTV 001
...
X
75.62
Secondary Memory
Semipermanentdatastoragecapability
Magnetic
Harddisk
Floppydisk
Tape
Nonmagnetic
CDROM
memorystick,flash
Secondarymemoryusuallyhasmuchmore
storagecapacitythanmainmemory
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
CPU
Brainsofthecomputer
Arithmeticcalculationsareperformedusingthe
Arithmetic/LogicalUnitorALU
Controlunitdecodesandexecutesinstructions
Registersholdinformationandinstructionsfor
CPUtoprocess
Arithmeticoperationsareperformedusing
binarynumbersystem
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Commoninputandoutputdevices
Keyboard
Printer
Joystick
Monitor
Scanner
Speaker
10
Computer Networks
Allowsmultiplecomputerstoconnect
togethertoshareresourcesand/ordata
LANLocalareanetwork
Organizational
WANWideareanetwork
Internet
Requiresadditionalhardware
modem
networkinterface
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
11
Webbrowser
GUI
Netscape
IE
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
12
Applications
13
Operating System
E.g.Windows,Unix
Controls
theinteractionofsystemwiththeuser
hardwareinteractions
PartisusuallystoredonROM,restonhard
drive
Thisarrangementrequiresbootingthesystem
14
Figure 1.6
Windows XP
15
Some OS Responsibilities
Communicatingwiththeuser;receivinguser
commands
Managingallocationofmemory,processortime,
filesystem,andotherresources
Collectinginputfromkeyboard,mouse,etc.
Conveyingoutputtoscreen,printer,etc.
Writingdatatosecondarystoragedevices
16
Application Software
Doestherealwork
Commonapplicationsoftware
Wordprocessors
Desktoppublishingprograms
Spreadsheets
Presentationmanagers
Drawingprograms
17
Programming Languages
MachineLanguage
Mostfundamentallanguageofthecomputer
Uniqueforeachprocessortype
Binary0sand1sthatspecifywhattodo
0010000000000100
1000000000000101
0011000000000110
18
Table 1.2
Language
19
Morecompactandhumanunderstandablethan
machinelanguage
Mustbetranslatedintomachinelanguage
20
OrganizedinaHierarchy
SuperClasses
SubClasses
21
22
Encapsulation
Breakingdownanobjectintoparts,hidingand
protectingitsessentialinformation,and
supplyinganinterfacetomodifythe
informationinacontrolledandusefulmanner
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
23
Examples
g++,BorlandC++,MicrosoftVisualC++
Otherprogramsneeded
Editor
Linker
Loader
24
Processing a Program
Editorusedtoentertheprogram
Likeminimalwordprocessor
Createssourceprogramfile
Compilertranslatesthesourceprogram
Displayssyntaxerrors
Creates(usually)temporaryobjectcodefile
Linker/Loadertocombineobjectfilewithotherobject
filesandexecuteprogram
Createsfinalexecutableprogram
25
Executing a Program
CPU
examineseachprograminstructioninmemory
sendsoutcommandsignalsrequiredtocarry
outtheinstruction
Specialinstructionsusedto
inputdataintomemoryfortheprogramtouse
outputdatatodisplayorprinter(orother
device)
26
27
Design
Decomposeintosmallerproblems
Topdowndesign(divideandconquer)
DevelopAlgorithm(Deskcheck)
Algorithmrefinement
28
Testing
Verifytheprogrammeetsrequirements
SystemandUnittest
Maintenance
Allprogramsundergochangeovertime
29
30
Case Study
AnalysisThefirststepinsolvingthisproblem
istodeterminewhatyouareaskedtodo.You
mustconvertfromonesystemofmeasurement
toanother,butareyousupposedtoconvert
fromkilometerstomiles,orviceversa?The
problemstatesthatyouprefertodealinmetric
measurements,soyoumustconvertdistance
measurementsinmilestokilometers.
31
Data Requirements
ProblemInput
miles
distanceinmiles
ProblemOutput
kms
thedistanceinkilometers
RelevantFormula
1mile=1.609kilometers
32
Design
Formulatethealgorithmthatsolvesthe
problem.
Algorithm
1.Getthedistanceinmiles.
2.Convertthedistancetokilometers.
3.Displaythedistanceinkilometers.
AlgorithmRefinement
2.1Thedistanceinkilometersis1.609the
distanceinmiles
Deskcheck!
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
33
Listing 1.2
Miles to kilometers
34
Implementation
#include<iostream>
usingnamespacestd;
intmain()
{
constfloatKM_PER_MILE=1.609;
floatmiles,kms;
cout<<Enterthedistanceinmiles:;
cin>>miles;
kms=KM_PER_MILE*miles;
cout<<Thedistanceinkilometersis<<kms<<endl;
return0;
}
35
Testing
Testwithinputdataforwhichyoucan
easilydeterminetheexpectedresults
E.g.
10milesshouldconvertto16.09kilometers
36
PrivacyandMisuseofData
ComputerHacking
PlagiarismandSoftwarePiracy
MisuseofaComputerResource
37