用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

提交评论