用C++解決問題第十版-第1章計算機和C++程式設計_第1頁
用C++解決問題第十版-第1章計算機和C++程式設計_第2頁
用C++解決問題第十版-第1章計算機和C++程式設計_第3頁
用C++解決問題第十版-第1章計算機和C++程式設計_第4頁
用C++解決問題第十版-第1章計算機和C++程式設計_第5頁
已閱讀5頁,還剩58頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Chapter 1Introduction to Computers and C+ ProgrammingOverview1.1 Computer Systems 1.2 Programming and Problem Solving1.3 Introduction to C+1.4 Testing and Debugging1.1Computer SystemsComputer SystemsA computer program isA set of instructions for a computer to followComputer software is The collectio

2、n of programs used by a computerIncludes:EditorsTranslatorsSystem ManagersHardwareThree main classes of computersPCs (Personal Computer)Relatively small used by one person at a timeWorkstationLarger and more powerful than a PCMainframeStill largerRequires support staffShared by multiple usersNetwork

3、sA number of computers connected to share resourcesShare printers and other devicesShare informationComputer OrganizationFive main componentsInput devicesAllows communication to the computerOutput devicesAllows communication to the userProcessor (CPU)Main memoryMemory locations containing the runnin

4、g programSecondary memoryPermanent record of data often on a diskDisplay 1.1Computer MemoryMain MemoryLong list of memory locationsEach contains zeros and onesCan change during program executionBinary Digit or BitA digit that can only be zero or oneByteEach memory location has eight bitsAddress Numb

5、er that identifies a memory location Larger Data ItemsSome data is too large for a single byteMost integers and real numbers are too largeAddress refers to the first byte Next few consecutive bytes can store the additionalbits for larger dataDisplay 1.2Data or Code?A may look like 01000001 65 may lo

6、ok like 01000001An instruction may look like 01000001How does the computer know the meaningof 01000001?Interpretation depends on the current instructionProgrammers rarely need to be concerned with this problem.Reason as if memory locations contain letters and numbers rather than zeroes and onesSecon

7、dary MemoryMain memory stores instructions and data while a program is running.Secondary memoryStores instructions and data between sessionsA file stores data or instructions in secondary memorySecondary Memory MediaA computer might have any of thesetypes of secondary memoryHard diskFastFixed in the

8、 computer and not normally removedFloppy diskSlowEasily shared with other computersCompact diskSlower than hard disksEasily shared with other computersCan be read only or re-writableMemory AccessRandom Access Usually called RAMComputer can directly access any memory locationSequential AccessData is

9、generally found by searching throughother items firstMore common in secondary memoryThe ProcessorTypically called the CPUCentral Processing UnitFollows program instructions Typical capabilities of CPU include: addsubtractmultiplydividemove data from location to locationComputer SoftwareThe operating

10、 system Allows us to communicate with the computerIs a program Allocates the computers resourcesResponds to user requests to run other programsCommon operating systems includeUNIX Linux DOSWindowsMacintoshVMSComputer InputComputer input consists of A programSome dataDisplay 1.3High-level LanguagesCo

11、mmon programming languages include C C+ Java Pascal Visual Basic FORTRAN Perl PHP Lisp Scheme Ada C# PythonThese high level languages Resemble human languagesAre designed to be easy to read and writeUse more complicated instructions than the CPU can followMust be translated to zeros and ones for the

12、 CPU to execute a program Low-level LanguagesAn assembly language command such as ADD X Y Zmight mean add the values found at x and y in memory, and store the result in location z.Assembly language must be translated to machine language (zeros and ones) 0110 1001 1010 1011The CPU can follow machine

13、languageCompilersTranslate high-level language to machine languageSource code The original program in a high level languageObject code The translated version in machine languageDisplay 1.4LinkersSome programs we use are already compiledTheir object code is available for us to useFor example: Input a

14、nd output routinesA Linker combinesThe object code for the programs we write andThe object code for the pre-compiled routines intoThe machine language program the CPU can runDisplay 1.5History NoteFirst programmable computerDesigned by Charles BabbageBegan work in 1822Not completed in Babbages life

15、timeFirst programmerAda Augusta, Countess of LovelaceColleague of BabbageSection 1.1 ConclusionCan youList the five main components of a computer?List the data for a program that adds two numbers?Describe the work of a compiler?Define source code? Define object code?Describe the purpose of the opera

16、ting system?1.2Programming and Problem-SolvingAlgorithms AlgorithmA sequence of precise instructions thatleads to a solutionProgramAn algorithm expressed in a language the computer can understandDisplay 1.6Program DesignProgramming is a creative processNo complete set of rules for creating a program

17、Program Design ProcessProblem Solving PhaseResult is an algorithm that solves the problemImplementation PhaseResult is the algorithm translated into a programminglanguageProblem Solving PhaseBe certain the task is completely specifiedWhat is the input? What information is in the output? How is the o

18、utput organized?Develop the algorithm before implementationExperience shows this saves time in getting your program to run.Test the algorithm for correctnessImplementation PhaseTranslate the algorithm into a programming languageEasier as you gain experience with the languageCompile the source codeLo

19、cates errors in using the programming languageRun the program on sample dataVerify correctness of results Results may require modification of the algorithm and programDisplay 1.7Object Oriented ProgrammingAbbreviated OOPUsed for many modern programsProgram is viewed as interacting objectsEach object

20、 contains algorithms to describe its behaviorProgram design phase involves designing objects and their algorithmsOOP CharacteristicsEncapsulationInformation hidingObjects contain their own data and algorithmsInheritanceWriting reusable codeObjects can inherit characteristics from other objectsPolymo

21、rphismA single name can have multiple meanings depending on its contextSoftware Life CycleAnalysis and specification of the task (problem definition)Design of the software (object and algorithm design)Implementation (coding)Maintenance and evolution of the systemObsolescenceSection 1.2 ConclusionCan

22、 youDescribe the first step to take when creating a program?List the two main phases of the program design process?Explain the importance of the problem-solving phase?List the steps in the software life cycle?1.3Introduction to C+Introduction to C+Where did C+ come from?Derived from the C languageC

23、was derived from the B languageB was derived from the BCPL languageWhy the +?+ is an operator in C+ and results in a cute punC+ HistoryC developed by Dennis Ritchie at AT&TBell Labs in the 1970s.Used to maintain UNIX systemsMany commercial applications written in cC+ developed by Bjarne Stroustrup a

24、t AT&TBell Labs in the 1980s.Overcame several shortcomings of CIncorporated object oriented programmingC remains a subset of C+A Sample C+ ProgramA simple C+ program begins this way#include using namespace std;int main()And ends this way return 0;Display 1.8Explanation of code (1/5)Variable declarat

25、ion line int numberOfPods, peasPerPod, totalPeas;Identifies names of three variables to name numbersint means that the variables represent integersExplanation of code (2/5)Program statementcout “Press return after entering a number.n”;cout (see-out) used for output to the monitor“ inserts “Pressa nu

26、mber.n” in the databound for the monitorThink of cout as a name for the monitor“ numberOfPods;cin (see-in) used for input from the keyboard“” extracts data from the keyboard Think of cin as a name for the keyboard“” points from the keyboard to a variable where the data is storedExplanation of code (

27、4/5)Program statement totalPeas = numberOfPods * peasPerPod;Performs a computation* is used for multiplication= causes totalPeas to get a new value based onthe calculation shown on the right of the equal signExplanation of code (5/5)Program statement cout numberOfPods;Sends the value of variable num

28、berOfPods to the monitorProgram Layout (1/3)Compiler accepts almost any pattern of linebreaks and indentationProgrammers format programs so they are easy to readPlace opening brace and closing brace on a line by themselvesIndent statements Use only one statement per lineProgram Layout (2/3)Variables

29、 are declared before they are usedTypically variables are declared at the beginning of the programStatements (not always lines) end with a semi-colonInclude Directives#include Tells compiler where to find information about items used in the programiostream is a library containing definitions of cin

30、and coutProgram Layout (3/3)using namespace std;Tells the compiler to use names in iostream ina “standard” way To begin the main function of the programint main() To end the main function return 0; Main function ends with a return statementRunning a C+ ProgramC+ source code is written with a text ed

31、itorThe compiler on your system converts source code to object code.The linker combines all the object codeinto an executable program.C+11C+11 (formerly known as C+0 x) is the most recent version of the standard of the C+ programming language.Approved on August 12, 2011 by the International Organiza

32、tion for Standardization.C+11 language features are not supported by older compilersCheck the documentation with your compiler to determine if special steps are needed to compile C+11 programse.g. with g+, use extra flags of std=c+11Run a Program Obtain code in Display 1.10Compile the codeFix any errors the compiler indicates and re-compile the codeRun the program Now you know how to run a program on your systemDisplay 1.10Section 1.3 ConclusionCan youDescribe the output of this line?cout peasPerPod;Explain this? #include 1.4Testing and DebuggingTesting and

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論