0% found this document useful (0 votes)
117 views37 pages

Chapter 1: Introduction To Computers, Problem Solving, and Programming

CS 106

Uploaded by

Ahmed Amr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views37 pages

Chapter 1: Introduction To Computers, Problem Solving, and Programming

CS 106

Uploaded by

Ahmed Amr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 37

Chapter 1: Introduction to Computers,

Problem Solving, and Programming


Problem Solving,
Abstraction, and Design using C++ 5e
by Frank L. Friedman and Elliot B. Koffman

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Early Computers
Late1930s,JohnAtanasoff,CliffordBerry
ENIAC

1946
UniversityofPennsylvania
J.PresperEckertandJohnMauchley
JohnvonNeumann,storedprogramconcept

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Figure 1.2

Computer components

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

Input / Output Devices


Accessoriesthatallowcomputertoperform
specifictasks
Receivinginformationforprocessing
Returntheresultsofprocessing

Commoninputandoutputdevices
Keyboard
Printer

Joystick
Monitor

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

World Wide Web


Introduced1989
DevelopedbyCERN
EuropeanLaboratoryforParticlePhysics

Webbrowser
GUI
Netscape
IE
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

12

1.3 Computer Software


Operatingsystem
Othersystemsoftware
utilities
programminglanguagesystems

Applications

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

13

Operating System
E.g.Windows,Unix
Controls
theinteractionofsystemwiththeuser
hardwareinteractions

PartisusuallystoredonROM,restonhard
drive
Thisarrangementrequiresbootingthesystem

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

14

Figure 1.6

Clicking on the Recycle Bin Icon in

Windows XP

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

15

Some OS Responsibilities
Communicatingwiththeuser;receivinguser
commands
Managingallocationofmemory,processortime,
filesystem,andotherresources
Collectinginputfromkeyboard,mouse,etc.
Conveyingoutputtoscreen,printer,etc.
Writingdatatosecondarystoragedevices

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

16

Application Software
Doestherealwork
Commonapplicationsoftware

Wordprocessors
Desktoppublishingprograms
Spreadsheets
Presentationmanagers
Drawingprograms

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

17

Programming Languages
MachineLanguage
Mostfundamentallanguageofthecomputer
Uniqueforeachprocessortype
Binary0sand1sthatspecifywhattodo
0010000000000100
1000000000000101
0011000000000110

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

18

Table 1.2

A Program in Machine and Assembly

Language

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

19

High - Level Languages


Resemblehumanlanguage
C++,C,Pascal,FORTRAN,Ada
a=a+b;

Morecompactandhumanunderstandablethan
machinelanguage
Mustbetranslatedintomachinelanguage

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

20

Object Oriented Programming


C++derivedfromCbyBjarneStroustrup
Popularbecauseofreuse
Classes
Objects
Methods

OrganizedinaHierarchy
SuperClasses
SubClasses

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

21

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

22

Object Oriented Design


Abstraction
Extracttherelevantpropertiesofanobject
whileignoringinessentialdetails

Encapsulation
Breakingdownanobjectintoparts,hidingand
protectingitsessentialinformation,and
supplyinganinterfacetomodifythe
informationinacontrolledandusefulmanner
Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

23

1.4 Processing a High-Level


Language Program
Setofprogramsusedtodevelopsoftware
Akeycomponentisatranslator
Compiler

Examples
g++,BorlandC++,MicrosoftVisualC++

Otherprogramsneeded
Editor
Linker
Loader

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

24

Processing a Program
Editorusedtoentertheprogram
Likeminimalwordprocessor
Createssourceprogramfile

Compilertranslatesthesourceprogram
Displayssyntaxerrors
Creates(usually)temporaryobjectcodefile
Linker/Loadertocombineobjectfilewithotherobject
filesandexecuteprogram
Createsfinalexecutableprogram

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

25

Executing a Program
CPU
examineseachprograminstructioninmemory
sendsoutcommandsignalsrequiredtocarry
outtheinstruction

Specialinstructionsusedto
inputdataintomemoryfortheprogramtouse
outputdatatodisplayorprinter(orother
device)

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

26

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

27

1.5 Software Development


Method
ProblemAnalysis
Identifydataobjects
DetermineInput/Outputdata
Constraintsontheproblem

Design
Decomposeintosmallerproblems
Topdowndesign(divideandconquer)
DevelopAlgorithm(Deskcheck)
Algorithmrefinement

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

28

Software Development Method


Implementation
Convertingthealgorithmintoprogramming
language

Testing
Verifytheprogrammeetsrequirements
SystemandUnittest

Maintenance
Allprogramsundergochangeovertime

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

29

1.6 Applying the Software


Development Method
CaseStudy:ConvertingMilestoKilometers
ProblemYoursummersurveyingjobrequiresyouto
studysomemapsthatgivedistancesinkilometersand
somethatusemiles.Youandyourcoworkerspreferto
dealinmetricmeasurements.Writeaprogramthat
performsthenecessaryconversion.

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

30

Case Study
AnalysisThefirststepinsolvingthisproblem
istodeterminewhatyouareaskedtodo.You
mustconvertfromonesystemofmeasurement
toanother,butareyousupposedtoconvert
fromkilometerstomiles,orviceversa?The
problemstatesthatyouprefertodealinmetric
measurements,soyoumustconvertdistance
measurementsinmilestokilometers.

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

31

Data Requirements
ProblemInput
miles
distanceinmiles
ProblemOutput
kms
thedistanceinkilometers
RelevantFormula
1mile=1.609kilometers

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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;
}

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

35

Testing
Testwithinputdataforwhichyoucan
easilydeterminetheexpectedresults
E.g.
10milesshouldconvertto16.09kilometers

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

36

1.7 Professional Ethics for


Computer Programmers

PrivacyandMisuseofData
ComputerHacking
PlagiarismandSoftwarePiracy
MisuseofaComputerResource

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

37

You might also like