下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1.1 fill in the blanks in each of the following:a. the company that popularized personal computing was _ apple._b. the computer that made personal computing legitimate in business andindustry was the _ibm personal computerc. computers process data under the control of sets of instructions calledcomp
2、uter _programs_.d. the six key logical units of the computer are the _input unit_, _output unit,_memory unit_, _arithmetic and logic unit_, _central processing unit_ and the _secondary storage unit_e. the three classes of languages discussed in the chapter are _machine languages_,_assembly languages
3、_, and _high-level languages_.f. the programs that translate high-level language programs into machinelanguage are called _compilers_.g. c is widely known as the development language of the _unix_ operatingsystem.h. the _pascal_ language was developed by wirth for teaching structuredprogramming.i. t
4、he department of defense developed the ada language with a capabilitycalled _multitasking._, which allows programmers to specify that many activities canproceed in parallel.1.2 fill in the blanks in each of the following sentences about the c+ environment.a. c+ programs are normally typed into a com
5、puter using a(n) _editor._program.b. in a c+ system, a(n) _preprocessor_ program executes before the compilerstranslation phase begins.c. the _linker_ program combines the output of the compiler with variouslibrary functions to produce an executable image.d. the _loader._ program transfers the execu
6、table image of a c+ program fromdisk to memory.1.3 fill in the blanks in each of the following statements a. objects have the property of _information hiding _ although objects may know how tocommunicate with one another across well-defined interfaces, they normallyare not allowed to know how other
7、objects are implemented.b. c+ programmers concentrate on creating _classes_, which contain datamembers and the member functions that manipulate those data members andprovide services to clients.c. classes can have relationships with other classes. these relationships are called_associations_.d. the
8、process of analyzing and designing a system from an object-oriented pointof view is called _object-oriented analysis and design (ooad)._.e. ood also takes advantage of _inheritance_ relationships, where new classes ofobjects are derived by absorbing characteristics of existing classes, then addingun
9、ique characteristics of their own.f. _the unified modeling language (uml)_ is a graphical language that allows people who design softwaresystems to use an industry-standard notation to represent them.g. the size, shape, color and weight of an object are considered _attributes_ of theobject.1.7 why i
10、s so much attention today focused on object-oriented programming in general and c+ in particular?ans1:object-oriented programming enables the programmer to build reusablesoftwarecomponents that model items in the real world. building software quickly, correctly,andeconomically has been an elusive go
11、al in the software industry. the modular, object-orienteddesign and implementation approach has been found to increase productivity while reducingdevelopment time, errors, and cost.ans2: in object-oriented programming, the source code is organized in classes and objects, whichis easy to be mapping i
12、nto the items in physical world. it is easy to design, reuse and maintainsuch kind of software in large scale software development, which is favored by the softwareindustry.【参考教材的答案】面向对象的编程让编程者可以建立可重用的软件组件,这些组件是现实世界事物的抽象模型。软件工业的目标是快速、正确、有效率的开发软件。面向对象的设计和实现方法模型已经被事实证明是可以提高生产效率和减少开发时间、错误和代价。【参考讲义的答案】面
13、向对象的编程方法中,以类和对象来组织源代码,可以方便的实现与现实物理世界事物的映射。采用这种方法,易于在大型软件开发中进行软件的设计、重用和维护,因此受到软件行业的支持和采用。1.10 you are probably wearing on your wrist one of the worlds most common types of objectsa watch. discuss how each of the following terms and concepts applies to the notion of a watch: object, attributes, behavi
14、ors, class, inheritance (consider, forexample, an alarm clock), abstraction, modeling, messages, encapsulation, interface,information hiding, data members and member functions.1.10 可能现在你的手腕上就戴着世界上最普遍的对象类型之一手表。论述以下这些术语和概念如何应用于手表这个概念上:对象、属性、行为、类、继承(例如,考虑闹钟)、封装、接口、信息隐藏、数据成员和成员函数。ans:the entire watch is
15、 an object that is composed of many other objects (such as the moving parts, the band, the face, etc.)watch attributes are time, color, band, style (digital or analog), etc. the behaviors of the watch include setting the time and getting the time, a watch can be considered a specific type of clock(a
16、s can an alarm clock), with that in mind, it is possible that a class called clock could exist from which other classes such as watch and alarm clock can inherit the basic features in the clock. the watch is an abstraction of the mechanics needed to keep track of the time. the user of the watch does
17、 not need to know the mechanics of the watch in order to use it; the user only needs to know that the watch keeps the proper time. in this sense,the mechanics of the watch are encapsulated(hidden)inside the watch. the interface to the watch(its face and controls for setting the time) allows the user
18、 to set and get the time. the user is not allowed to directly touch the internal mechanics of the watch. all interaction with the internal mechanics is controlled by the interface to the watch. the data members stored in the watch are hidden inside the watch and the member functions(looking at the f
19、ace to get the time and setting the time) provide the interface to the data.2.1 fill in the blanks in each of the following.a. every c+ program begins execution at the function _main_.b. the _left brace ()_ begins the body of every function and the _ right brace ()_ ends the body of every function.c
20、. every c+ statement ends with a(n) _ semicolon_.d. the escape sequence n represents the _ newline._ character, which causes the cursor to position to the beginning of the next line on the screen.e. the _ if._ statement is used to make decisions.2.2 state whether each of the following is true or fal
21、se. if false, explain why. assume the statement using std:cout; is used.a. comments cause the computer to print the text after the / on the screen when theprogram is executed.b. the escape sequence n, when output with cout and the stream insertion operator,causes the cursor to position to the beginn
22、ing of the next line on the screen.c. all variables must be declared before they are used.d. all variables must be given a type when they are declared.e. c+ considers the variables number and number to be identical.f. declarations can appear almost anywhere in the body of a c+ function.g. the modulu
23、s operator (%) can be used only with integer operands.h. the arithmetic operators *, /, %, + and all have the same level of precedence.i. a c+ program that prints three lines of output must contain three statements usingcout and the stream insertion operator.ans: a. false. comments do not cause any
24、action to be performed when the program is executed. they are used to document programs and improve their readability.b. true. c. true. d. true. e. false. c+ is case sensitive, so these variables are unique. f. true. g. true. h. false. the operators *, / and % have the same precedence, and the opera
25、tors + and have a lower precedence. i. false. a single cout statement with multiple n escape sequences can print several lines2.3 write a single c+ statement to accomplish each of the following (assume that using declarations have not been used):a. declare the variables c, thisisavariable, q76354 an
26、d number to be of type int.b. prompt the user to enter an integer. end your prompting message with a colon (:)followed by a space and leave the cursor positioned after the space.c. read an integer from the user at the keyboard and store the value entered in integervariable age.d. if the variable num
27、ber is not equal to 7, print the variable number is not equal to 7.e. print the message this is a c+ program on one line.f. print the message this is a c+ program on two lines. end the first line withc+.g. print the message this is a c+ program with each word on a separate line.h. print the message
28、this is a c+ program with each word separated from thenext by a tab.ans; a. int c, thisisavariable, q76354, number;b. std:cout age;d. if ( number != 7 )std:cout the variable number is not equal to 7n;e. std:cout this is a c+ programn;f. std:cout this is a c+nprogramn;g. std:cout thisnisnanc+nprogram
29、n;h. std:cout thististatc+tprogramn;2.4 write a statement (or comment) to accomplish each of the following (assume that using declarations have been used):a. state that a program calculates the product of three integers.b. declare the variables x, y, z and result to be of type int (in separate state
30、ments).c. prompt the user to enter three integers.d. read three integers from the keyboard and store them in the variables x, y and z.e. compute the product of the three integers contained in variables x, y and z, andassign the result to the variable result.f. print the product is followed by the va
31、lue of the variable result.g. return a value from main indicating that the program terminated successfully.ans: a. / calculate the product of three integersb. int x;int y;int z;int result;c. cout x y z;e. result = x * y * z;f. cout the product is result endl;g. return 0;2.5 using the statements you
32、wrote in exercise 2.4, write a complete program that calculates and displays the product of three integers. add comments to the code where appropriate. note: you will need to write the necessary using declarations.ans: 1 / calculate the product of three integers2 #include / allows program to perform
33、 input and output34 using std:cout; / program uses cout5 using std:cin; / program uses cin6 using std:endl; / program uses endl78 / function main begins program execution9 int main()10 11 int x; / first integer to multiply12 int y; / second integer to multiply13 int z; / third integer to multiply14
34、int result; / the product of the three integers1516 cout x y z; / read three integers from user18 result = x * y * z; / multiply the three integers; store result19 cout the product is result endl; / print result; end line2021 return 0; / indicate program executed successfully22 / end function main2.
35、6 identify and correct the errors in each of the following statements (assume that thestatement using std:cout; is used):a. if ( c 7 );cout 7 )cout .correction: change = to =, and you may want to change equal to or greater than togreater than or equal to as well.question2.8fill in the blanks in each
36、 of the following:a) _ are used to document a program and improve its readability.ans: commentsb) the object used to print information on the screen is _.ans: coutc) a c+ statement that makes a decision is _.ans: ifd) most calculations are normally performed by _ statements.ans: assignmente) the _ o
37、bject inputs values from the keyboard.ans: cinquestion2.10state which of the following are true and which are false. if false, explain your answers.a) c+ operators are evaluated from left to right.ans: false. some operators are evaluated from left to right, while other operators are evaluated right
38、to left.b) the following are all valid variable names: _under_bar_, m928134, t5, j7,her_sales,his_account_total, a, b, c, z, z2.ans: true.c) the statement cout a = 5; is a typical example of an assignment statement.ans: false. the statement is an output statement. the text a = 5; is output to the sc
39、reen.d) a valid c+ arithmetic expression with no parentheses is evaluated from left to right.ans: false. arithmetic operators can appear in any order in an expression, so a counter example is a=b+c*d; whose operators are actually evaluated from right to left because of the rules of operator preceden
40、ce.e) the following are all invalid variable names: 3g, 87, 67h2, h22, 2h.ans: false. h22 is a valid variable name.question2.12what, if anything, prints when each of the following c+ statements is performed? if nothing prints, then answer “nothing.” assume x = 2 and y = 3.a) cout x;ans: 2b) cout x +
41、 x;ans: 4c) cout x=;ans: x=d) cout x = x;ans: x = 2e) cout x + y = x y;ans: nothing.h) / cout x + y = x + y;ans: nothing (because it is a comment).i) cout n;ans: a newline is output which positions the cursor at the beginning of the next line on the screen.question2.15state the order of evaluation o
42、f the operators in each of the following c+ statements and show the value of x after each statement is performed.a) x = 7 + 3 * 6 / 2 - 1;ans: *, /, +, -, =, 15b) x = 2 % 2 + 2 * 2 - 2 / 2;ans: %, *, /, +, -, =, 3c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );ans: innermost parentheses around 3, *, /,
43、 +, *, *, 324quetion3.1fill in the blanks in each of the following:a) a house is to a blueprint as a(n) _ is to a class.ans:objectb) every class definition contains keyword _ followed immediately by the classs name.ans:classc) a class definition is typically stored in a file with the _ filename exte
44、nsion.ans:.hd) each parameter in a function header should specify both a(n) _ and a(n) _.ans:type, namee) when each object of a class maintains its own copy of an attribute, the variable thatrepresents the attribute is also known as a(n) _.ans:data memberf) keyword public is a(n) _.ans:access specif
45、ierg) return type _ indicates that a function will perform a task but will not return any information when it completes its task.ans:voidh) function _ from the library reads characters until a newline character is encountered, then copies those characters into the specified string.ans:getlinei) when
46、 a member function is defined outside the class definition, the function header must include the class name and the _, followed by the function name to tie the member function to the class definition.ans:binary scope resolution operator (:)j) the source-code file and any other files that use a class
47、 can include the classs header file via an_ preprocessor directive.ans:#include3.2 state whether each of the following is true or false. if false, explain why.a. by convention, function names begin with a capital letter and all subsequentwords in the name begin with a capital letter.b. empty parenth
48、eses following a function name in a function prototype indicatethat the function does not require any parameters to perform its task.c. data members or member functions declared with access specifier private areaccessible to member functions of the class in which they are declared.d. variables decla
49、red in the body of a particular member function are known asdata members and can be used in all member functions of the class.e. every functions body is delimited by left and right braces ( and ).f. any source-code file that contains int main() can be used to execute aprogram.g. the types of argumen
50、ts in a function call must match the types of thecorresponding parameters in the function prototypes parameter list.ans: a) false. by convention, function names begin with a lowercase letter and allsubsequent words in the name begin with a capital letter. b) true. c) true. d) false.such variables ar
51、e called local variables and can be used only in the member functionin which they are declared. e) true. f) true. g) true.3.3 what is the difference between a local variable and a data member?ans: a local variable is declared in the body of a function and can be used only from the point at which it
52、is declared to the immediately following closing brace. a datamember is declared in a class definition, but not in the body of any of the classsmember functions. every object (instance) of a class has a separate copy of the classsdata members. also, data members are accessible to all member function
53、s of theclass.3.4 explain the purpose of a function parameter. what is the difference between aparameter and an argument?ans: a parameter represents additional information that a function requires to perform its task. each parameter required by a function is specified in the function header. an argu
54、ment is the value supplied in the function call. when the function is called, the argument value is passed into the function parameter so that the function can perform its task.question3.5explain the difference between a function prototype and a function definition.ans: a function prototype tells the compiler the name of a function and the type of data returned by the function. a prototype also describes any additional data required by the function to perfor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (2026年)劳动保障协理员三级鉴定试题附答案
- 水库大坝土方填筑碾压施工方案及技术措施
- 2026机修钳工证考试题库及模拟考试答案(高级)
- SBS改性沥青防水卷材防水工程施工方案
- 中压蒸汽管道吹扫施工方案
- 市政桥梁防撞护栏安装质量措施
- 复合地板铺设施工方案及技术措施
- ICU病房血液透析管路凝血分级安全生产应急预案演练脚本
- 2026年中职社会福利事业管理(福利基础)下学期期末测试卷(含答案)
- 2026四川科瑞软件有限责任公司招聘商务专员等岗位3人备考题库及参考答案详解【基础题】
- 广州市海珠区2024-2025学年八年级下学期数学期末试卷(含答案)
- 2026年河北省考行测时政省情题库及答案
- XX中学2026年春季学期期末教职工大会暨暑假工作部署会校长总结讲话
- 2025至2030中国宠物医疗连锁机构并购扩张与单店盈利能力建模
- DB13∕T 6093-2025 河湖管理范围划定技术规程
- 会议管理作业指导书
- 2025国际焊接工程师(IWE)考试试题附答案
- 公司甲醇装置操作工工艺作业技术规程
- 2025年国家电网中级职称考试模拟题库政工试题及答案
- 标准物流公司安全生产管理制度文本
- 环卫企业安全管理制度
评论
0/150
提交评论