AFirstofANSIC4thEdition第一本书的ANSIC第四版_第1页
AFirstofANSIC4thEdition第一本书的ANSIC第四版_第2页
AFirstofANSIC4thEdition第一本书的ANSIC第四版_第3页
AFirstofANSIC4thEdition第一本书的ANSIC第四版_第4页
AFirstofANSIC4thEdition第一本书的ANSIC第四版_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、A First Book of ANSI C, 4th Edition14188-35560Chapter 1 SolutionsExercises 1.1Short Answer Questions1. A bit is the smallest and most basic data item which is a switch that can be either opened or closed. A bit can represent the values 0 and 1.2. A byte is a grouping of eight bits. A byte can assume

2、 256 distinct patterns.3. A byte uses a pattern of eight bits, such as 00110011, to represent characters in a computer.4. A word is a single unit combination of one or more bytes. Word sizes for some common computers include: a single byte for early personal computers, such as the Apple IIe and Comm

3、odore machines; two bytes for the first IBM PCs; four bytes for the more current Intel-based PCs.5. The two principal parts of the CPU are the Control Unit and the Arithmetic and Logic Unit (ALU). The Control Unit monitors the overall operation of the computer while the ALU performs all the arithmet

4、ic and logic functions provided by the system.6. The main difference between RAM and ROM is RAM is volatile while ROM is nonvolatile. Both RAM and ROM are random access which means that every section of memory can be accessed randomly as quickly as any other section.7. a. The input/output unit is th

5、e interface that provides access to and from the computer to which peripheral devices are attached.b. Three devices that would be connected to the input/output unit include keyboards, monitors and printers. (Please note there are other examples the student could include.)8. Secondary storage is a pe

6、rmanent storage area for programs and data. Three examples of secondary storage include magnetic tapes, magnetic disks and CD- ROMS. (Please note there are other examples the student could include.)9. The difference between sequential storage and direct access storage is sequential storage allows da

7、ta to be written or read in one sequential stream from beginning to end while direct access storages allows data to be written or read from any one file or program independent of its position on the storage medium. Direct access storage allows the computer to jump directly to the desired point in st

8、orage, rather than passing through all intervening points like sequential storage would require. In other words, the data can be accessed more quickly.10. A microprocessor is a single microchip CPU. In everyday life microprocessors are used in notebook and desktop computers, calculators, and even di

9、gital watches. (Please note there are other examples the student could include.)Exercises 1.21. a. computer program -a self-c ontained set of in struct ions and data used to operate a computer to produce a specific resultb. programming -the process of developing and writing a programc. programming l

10、anguage-the set of data and instructions that can be used to construct a programd. high-level language-languages in which the instructions resemble human languages, such as English, and can be run on a variety of computer typese. low-level language-language that uses instructions that are directly t

11、ied to one type of computerf. machine language-a programming language consisting of the binary codes the can be executed by a computerg. assembly language-a programming language that uses symbolic names for operations and memory addressesh. procedure-oriented language-high-level language in which th

12、e instructions are only used to create self-contained units referred to as proceduresi. object-oriented language-high-level language which defines and manipulates objects to produce resultsj. source program-program written in a computer languagek. compiler -program which translates high-level langua

13、ges as a complete unit before any individual statement is executedl. assembler-a program that converts, or translates, assembly language programs into machine language2. a. A high-level language can be translated to run on a variety of computer types, while a low-level language is directly tied to o

14、ne type of computer.b. Procedure-oriented languages create logically consistent sets of instructions, or procedures, to produce a specific result while object-oriented languages create and manipulate objects to produce specific results.3. An assembler translates assembly language programs, while bot

15、h compilers and interpreters translate high-level source programs. A compiler translates a high- level source programs as a complete unit before any one statement is actually executed, while an interpreter translates individual source program statements one at a time into executable statements. Each

16、 interpreted statement is executed immediately after translation.4. a. Add the data in memory location 1 to the data in memory location 2. Multiply the data in memory location 3 by the data in memory location 2. Subtract the data in memory location 4 from the data in memory location 3. Divide the da

17、ta in memory location 3 by the data in memory location 5.b. 3 + 5 = 86 * 3 = 186 -14 = -86 / 4 = 1.55. ADD 1, 2MUL 3, 2SUB 4, 3DIV 3, 56. (10 + 20) * .6 = 18Exercises 1.31. a.Fix a flat tireStop vehicle in a safe, level locationSet the parking brakeGet jack, lug-wrench, and spare tireCheck air press

18、ure in spare tireUse jack to raise vehicle so that damaged tire is clear of groundRemove hubcapUse lug-wrench to loosen each individual lug nutUse lug-wrench to remove each individual lug nutPlace lug nuts into hubcapRemove tire from axlePlace spare tire onto axleRestore each lug nut, and tighten by

19、 handTighten all lug nuts securely with lug-wrenchReplace hubcapRelease jackReturn jack, lug-wrench, and damaged tire to trunk of vehicleb. Make a telephone callLift telephone receiverDial a numberWait for answerSpeak to person, or respond to electronic instructionsc. Go to the store and purchase a

20、loaf of breadTransport yourself to the storeFind bakery departmentSelect an appropriate loaf of breadProceed to checkout areaExchange money for the loaf of breadd. Roast a turkeyClean turkey thoroughly, removing gibletsPlace turkey into roasting panStuff with dressing, if desiredInsert meat thermome

21、ter deeply into turkey breastCover turkey with foilRoast in 325 degree oven 4-5 hours, until appropriate internal temp is reachedRemove foilRoast until outer surfaces of turkey are browned2. Label cups: #1, #2, and #3, with #3 being the empty cupRinse #3Pour contents of #1 into #3Rinse #1Pour conten

22、ts of #2 into #1Rinse #2Pour contents of #3 into #2Rinse #33. Multiply h by 50, and remember this number as hTotal Multiply q by 25, and remember this number as qTotal Multiply d by 10, and remember this number as dTotal Multiply n by 5, and remember this number as nTotal Add hTotal to qTotal to dTo

23、tal to nTotal to p, and remember this number as Total Divided Total by 100 to get the dollar amount.4. Compare first and secondIf first second, then compare second and thirdIf second third, then compare first and thirdIf first third, then third is smallestIf first second, then compare second and thi

24、rdIf second third, then third is smallestIf second third, then second is smallest5. a. If the number is greater than 100, keep subtracting 100 from the number.The number of times 100 was subtracted is the number of 100 bills needed.If the remaining number is greater than 50, keep subtracting 50 from

25、 the number until the number is less than 50. The number of times 50 was subtracted is the number of 50 bills needed.If the remaining number is greater than 20, keep subtracting 20 from the number until the number is less than 20. The number of times 20 was subtracted is the number of 20 bills neede

26、d.If the remaining number is greater than 10, keep subtracting 10 from the number until the number is less than 10.The number of times 10 was subtracted is the number of 10 bills needed.If the remaining number is greater than 5, keep subtracting 5 from the number until the number is less than 5.The

27、number of times 5 was subtracted is the number of 5 bills needed.The remaining number is then number of one-dollar bills needed.b. Total multiplied by 1 is product1Product1 is the number of $1 bills6. a. Compare the first letter of the word JONES with the first letter of each word.If the first lette

28、r is a match, compare the second letters in each word.If the second letter is a match, compare the third letters.If the third letters match, compare the fourth.If the fourth letters match, compare the fifth.If the fifth letters match, the words match.If a letter is not a match, proceed to the next w

29、ord in the list and repeat this comparison.b. If the names are in alphabetical order you will not need to go through each name from the beginning of the list. You can jump to the names that begin with J, or even just jump straight to where JONES would be stored.7. Step 1: Look at the first letter. I

30、f it is an e then set COUNT to 1; else set COUNT to 0.Step 2: Look at the next letter. If it is e then add one to COUNT.Step 3: Continue to repeat Step 2 until a period . is encountered.8. Step 1: Compare the number in the first position to that in the second position If the number in the first posi

31、tion is greater than the number in the second position, switch the numbersStep 2: Compare the number currently in the second position to that in the third positionIf the number in the second position is greater than the number in the third position, switch the numbersStep 3: Compare the number curre

32、ntly in the first position to that currently in the second positionIf the number in the first position is greater than the number in the second position, switch the numbersExercises 1.41. 1). Specify the programs requirements: Ensure that the program requirement is clearly stated and that you unders

33、tand what is to be achieved.2) Design and Developmen:t This includes, analyzing the problem, developing a solution, coding the solution, and testing and correcting the program.3) Documentation: Provide adequate user documentation for people who will use the program and programmer documentation for p

34、eople who will have to maintain the program.4) Maintenance: Keep the solution up to date by making modifications required, whether due to changes in requirements or because errors are found during program execution.2. a. Find out exactly what the inventory problem is and what is expected of the solu

35、tion.b. Contact Ms. R. Karp to either define the problem more specifically or to introduce you to other people and/or documents that can define the problem more specifically.3. a. One output: the dollar amountb. Five inputs: half dollars, quarters, dimes, nickels, penniesc. Dollar amount = 0.50 * ha

36、lfs + 0.25 * quarters + 0.10 * dimes + 0.05 * nickels + 0.01 * penniesd. Dollar amount = 0.50 * 0 + 0.25 * 17 + 0.10 * 24 + 0.05 * 16 + 0.01 * 12 = 7.574. a. One output: distanceb. Two inputs: rate, elapsed timec. Distance = Rate * Timed. Distance = 55 * 2.5 = 137.5e. Divide time in minutes by 60 to

37、 convert to time in hours5. a. One output: the amount of Ergiesb. Two inputs: Fergies, Lergiesc. Ergies = Fergies * Lergiesd. Ergies = 14.65 * 4 = 58.66. a. Three lines of output.b. Three lines of input.c. Each input becomes a line of output7. a. One output: distance.b. Three inputs: s, d, and tc. D

38、istance = s*t-0.5 * d * t * td. Dista nee = (60*5280)/3600 * 10) -0.5 * 12 * 10 * 10 = 280 ft(Please note the student needs to first convert the 60 mph to feet/second.)8. Generally people envision only the part of the problem they are eoneerned with and in terms they are familiar with. Onee they see

39、 the effeets of the eode on the sereen, other possibilities immediately present themselves. However, onee you have eoded an applieation, making ehanges to it are generally very time eonsuming and in many eases take more time redoing than the original eoding took. This is very diffieult to explain to

40、 a elient, who generally expeets the additional eosts to be less than the original eoding eosts. In some eases the elient may tell you that you should have antieipated the problems. It is almost always better to lay out what the program will and will not do before beginning to eode the solution.9. A

41、 fixed fee is a good ehoiee if you have experienee in exaetly what is wanted, are selling an existing program to a new elient, or both you and the elient are in total agreement as to what will be produeed; otherwise, it is generally a bad ehoiee for both parties. On the positive side is that you do

42、know how mueh you will reeeive for your work and the elient knows how mueh they will pay. The disadvantage is that unless you both are very elear as to what will be produeed, you may end up doing double and triple the amount of work eontraeted for, with very little if any additional funding. This oe

43、eurs beeause after the elient sees the program, new features immediately present themselves. You, as a programmer, may elaim these are additional features, while the elient may elaim them as normal features that you should have ineorporated as part of a useful program. No mater how the issue is reso

44、lved, generally, one or both sides may feel they have been deeeived.10. An hourly rate is generally preferable when the exaet nature and seope of the work is not known or elearly speeified in advanee. This is typieally a good arrangement for new projeets. When a elear understanding, in writing, is a

45、vailable describing what will be produced, or you are selling an application that you have previously developed, a fixed fee is generally used.11. A clearly written statement of programming work to be done is generally a good idea. The user will know exactly what the programmer is expected to do. On

46、ce the programmer completes the program according to the specifications his job is done. You, as the programmer, will know exactly what you need to do to fulfill your obligation. The user cant decide at the last minute that he wants you to add additional features or functionality without hiring you

47、for additional work. The disadvantage is that this will limit the amount of freedom you have as a programmer. You may have a better idea of how to make the program more userfriendly or easier to handle, but unless this is specified in the agreement, you need to stick with what the user originally as

48、ked for. The user also, has less freedom.Unless you both agree on any proposed changes to the agreement the user needs to stick with what was originally specified.12. (100 char / sale) x (15 sales / day) x (6 days / week) x (52 weeks /year) x 2 years = 936,000 characters, or approximately 1 Million

49、characters. Since each character is stored using 1 byte, the minimum storage is 1 Million bytes (1 MB)13. Assuming that the average typist can type 50 words per minute and that the average word consists of 5 characters, the time it takes to enter all of the sales is 300 (char/sale) x (200 sales) / (

50、50 words/minute) x (5 char/word) = (60,000 char) / (250 char/min) = 240 minutes = 4 hours of nonstop typing.Exercises 1.51. #include int main()double rad, cir; /* declare an input and output item */rad = 2.0; /* set a value for the radius */cir = 2.0 * 3.1416 * rad; /* calculate the circumference */

51、printf(The circumference of the circle is f, cir);return 0;2. If the area of a circle was required output, the following modifications would have to be made to Program 1.1: Declare a variable to hold the value of the area. Add a line to calculate the area. Add a line to output the value of the area.

52、 Modify comments to reflect these changes.3. a. The value in miles of a distance given in kilometers is calculated using the formula miles = 0.625 * kilometers. Using this information, write a C program to calculate the value in miles of 86 kilometers.b. The output required is a value in miles.c. Th

53、e program will have one input (86 kilometers).d. miles = 0.625 * kilometerse. miles = 0.625 * 86 = 53.75 milesf. Get the input kilometers value Calculate miles = 0.625 * kilometers value Display the resulting miles value4. a. The final balance of an investment with interest compounded annually is gi

54、ven by the formula balance = principal * (1.0 + rate)(final year - initial year). Using this information, write a C program to calculate the final balance in 2006 of an investment initiated in 1627 with a principal of $24 and an interest rate of 5% compounded annually.b. One output: balancec. Four inputs: principal, rate, initial year, final yeard. balance = principal * (1.0 + rate)(final year -

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论