1、C+面向对象程序设计第六版第一章编程题答案INSTRUCTORS RESOURCE GUIDE SOLUTIONS TO PROGRAMMING PROJECTSTO ACCOMPANYPROBLEMSOLVINGWITHC+THE OBJECTOF PROGRAMMINGSixth EditionWalter SavitchUNIVERSITY OF CALIFORNIA, SAN DIEGOThis instructors manual is based on the fourth edition.http:/www.aw-and please visit our general comp
2、uter science and engineering web site at:http:/www.aw-Copyright 2007 by Addison-Wesley Publishing Company All right reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photo-copying, recording, or
3、 any other media embodiments now known or hereafter to become known, without the prior written permission of the publisher. Manufactured in the United States of America.Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where these des
4、ignations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial caps or all caps.The programs and the applications presented in this book have been included for their instructional value. They have been tested with care but are not guara
5、nteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications.Addison-Wesley Publishing Company2725 Sand Hill RoadMenlo Park, CA 94025ContentsPreface Chapter 1 Introduction to Computer
6、s and C+ Programming Chapter 2 C+ Basics Chapter 3 More Flow of Control Chapter 4 Procedural Abstraction and Functions that Return a Value Chapter 5 Functions for all SubtasksChapter 6 I/O Streams as an Introduction to Objects and Classes Chapter 7 Arrays Chapter 8 Strings and Vectors Chapter 9 Poin
7、ters and Dynamic ArraysChapter 10 Defining Classes Chapter 11 Friends and Overloaded Operators Chapter 12 Separate Compilation and NamespacesChapter 13 Pointers and Linked Lists Chapter 14 RecursionChapter 15 InheritanceChapter 16 Exception HandlingChapter 17 TemplatesChapter 18 Standard Template Li
8、braryPrefaceThis is a document that is meant to be a supplement the text for the instructor. There is a discussion of the ideas in each chapter, teaching suggestions, and some supplementary ideas. There are solutions to many of the programming problems. Some problems have several different solutions
9、 that correspond to different paths through the book. There are 25 to 50 test questions with answers and discussion for each chapter. The questions are of both short answer (multiple choice, true false, fill in the blank) type as well as read-the-code questions and short programming problems. I urge
10、 that explanations to the short answer questions be required of the student.With regard to the content of this manual, it should be noted that C+ leaves many options on how to do any problem, and any book will necessarily choose a subset to present. Our author has made such a set of choices. I have
11、also made what I hope is a complementary set of choices for this Instructors resource Manual. I am striving to produce a complementary document to the text, a document for the instructor, but I necessarily will do some things differently. Please do not hold the student responsible for what I have pu
12、t here. The reader of this document must note that it is necessary to read the text, as that is what the student has to work with. In spite of our efforts at consistency of content and style, there will be some variance between some of the presentation here and the presentation in the text.The code
13、has been compiled and tested with g+ (gcc 3.4.4), Visual Studio C+ .NET 2003, Visual Studio C+ .NET 2005, Visual Studio C+ Express .NET, and Visual Studio C+ 6.0 updated to service pack 6. Users of Microsoft Visual Studio C+ 6.0 may experience the most incompatibilities and should ensure that servic
14、e pack 6 is downloaded and installed from the Microsoft website. The text uses only mainstream features of C+, consequently, most compilers will compile the code and produce output that does not differ significantly from the results presented here. We have attempted to supply warnings where any of t
15、hese compilers gives trouble.Instructors Resource ManualforSavitch, Problem Solving with C+: The Object of Programming.Chapter 1Introduction to Computers and C+ ProgrammingThis document is intended to be a resource guide for instructors using Savitch, Problem Solving with C+: The Object of Programmi
16、ng. This guide follows the text chapter by chapter. Each chapter of this guide contains the following sections:1. Outline of topics in the chapter2. General remarks on the chapter3. Solutions to, and remarks on, selected Programming Projects4. Test Questions5. Answers to the test QuestionSolutions a
17、nd remarks on selected Programming ProjectsThese programming exercises are intended to help familiarize the student with the programming environment. Solutions are very system dependent. Consequently, only one solution is provided for the programming projects in this chapter./ Ch1Proj8.cpp/ This pro
18、gram calculates the monetary value of a number of/ quarters, dimes, and nickels./ *#include using namespace std;/ =/ main function/ =int main() int quarters, dimes, nickels, total; / Input coins cout Enter number of quarters. quarters; cout Enter number of dimes. dimes; cout Enter number of nickels.
19、 nickels; / Calculate and output total total = (quarters * 25) + (dimes * 10) + (nickels * 5); cout The monetary value of your coins is total cents. endl; return 0;Outline of Topics in the Chapter 11.1 Computer Systems1.2 Programming and Problem-Solving1.3 Introduction to C+1.4 Testing and Debugging
20、Suggested course outlines:There seem to be three major approaches to teaching C+ as the first course in programming. In the one approach, classes and objects are done very early, frequently with a library of some sort that must be used with the text. In another, all of the ANSI C subset of C+ is cov
21、ered prior to even mentioning classes or objects. This text takes a third road that is more middle of the road. Here, enough of the control constructs and functions are covered prior to doing classes and objects. However, reorderings of the chapters are possible that allow any of these approaches. H
22、ere is a classes early course that follows the text closely. This outline assumes no background in computing. Topics beyond Chapter 11 may be studied as time permits. Day days allotted1 1 Startup business2-3 2 Chapter 1: Introduction to Computers4-8 5 Chapter 2: C+ Basics. If the students have progr
23、amming experience, the time spent can be significantly reduced. 9-11 3 Chapter 3: Procedural Abstraction and functions that return a value12-14 3 Chapter 4: Functions for all subtasksTest 116-18 3 Chapter 5: I/O Streams as introduction to Objects and Classes19-22 4 Chapter 6: Defining Classes23-27 5
24、 Chapter 7: More Flow of ControlTest 229-32 4 Chapter 8:Friends and Overloaded Operators Chapter 9 Separate Compilation and Namespaces33-37 5 Chapter 10: Arrays38-41 3 Chapter 11: Strings and VectorsTest 3 5 Chapter 12 Pointers, Dynamic Arrays 3 Chapter 13 Recursion 3 Chapter 14: Templates 3 Chapter
25、 15: Pointers and Linked Lists 3 Chapter 16: Inheritance 3 Chapter 17: Exception HandlingReorderings:The author suggests a reordering in the preface that allow almost all of ANSI C (with the tighter C+ type-checking) to be covered before classes. Several variants on this reordering that allow classe
26、s a bit earlier are presented in the text. The author describes interdependency of the chapters in the preface of the text. Other reorderings are certainly possible.Chapter 1:The student should do all the programming assignments in this chapter. These teach the locally available program development
27、system and familiarize the student with some of the more common compiler errors. Error messages are quite specific to the compiler being used. It is very important that the student learn these ideas as early as possible.Outline of topics in the chapter:1.1 Computer Systems1.2 Programming and Problem
28、-Solving1.3 Introduction to C+1.4 Testing and DebuggingGeneral remarks on the chapterThis chapter serves as an introduction to computers and the language of computers for those students who have no computer experience. The terminology is very important. Many students only want to learn how the progr
29、amming language works, and seem to be unhappy when they find that they are required to learn the terminology associated with the language. The students who learn the terminology have less trouble by far with this course.Students should be given an indication of the amount of work that must be done b
30、efore coding begins. There are instances where several man-years of work have gone into software before a single line of code was written. Emphasize the importance of the problem-solving phase of program design. This will save the student work in the long run. It is further important to emphasize th
31、at the problem definition and algorithm design phases may need correcting once the actual coding and testing is in process. This is true even if the algorithm was carefully desktop tested. Emphasize that the program design process is an iterative process. You make a start, test, correct and repeat until you have a solution.It is a fact that the sooner the coding is started (on most problems), the longer the problem will take to finish. My students insi
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1