├── C++Primer第五版课本源代码 ├── 1 │ ├── README │ ├── Sales_item.h │ ├── add.cpp │ ├── add_item.cpp │ ├── add_item2.cpp │ ├── avg_price.cpp │ ├── data │ │ ├── add │ │ ├── add_item │ │ ├── book_sales │ │ ├── mysum │ │ └── occurs │ ├── for_ex.cpp │ ├── forcount.cpp │ ├── item_io.cpp │ ├── main_only.cpp │ ├── makefile │ ├── mysum.cpp │ ├── occurs.cpp │ ├── runpgms.bat │ └── whilecount.cpp ├── 2 │ ├── README │ ├── Sales_data.cpp │ ├── Sales_data.h │ ├── compounddecls.cpp │ ├── convs.cpp │ ├── data │ │ ├── add_item │ │ └── data │ │ │ └── add_item │ ├── dbl_ptr.cpp │ ├── decl-ex.cpp │ ├── escape.cpp │ ├── inits.cpp │ ├── literals.cpp │ ├── makefile │ ├── ref-ex.cpp │ ├── runpgms.bat │ ├── scope_levels.cpp │ └── unsigned.cpp ├── 3 │ ├── README │ ├── add_using.cpp │ ├── arrayScores.cpp │ ├── cctype.cpp │ ├── char_repl.cpp │ ├── cstring_hdr.cpp │ ├── data │ │ ├── add │ │ ├── grades │ │ ├── hexify │ │ ├── iterarith │ │ ├── ptr_traversal2 │ │ ├── string_io │ │ ├── vecStrings2 │ │ └── word_echo │ ├── getline.cpp │ ├── hexify.cpp │ ├── makefile │ ├── multidim.cpp │ ├── ptr_traversal2.cpp │ ├── runpgms.bat │ ├── square.cpp │ ├── strcompare.cpp │ ├── string_add.cpp │ ├── string_io.cpp │ ├── string_io2.cpp │ ├── string_size.cpp │ ├── string_size2.cpp │ ├── string_size3.cpp │ ├── vecScores.cpp │ ├── vecStrings2.cpp │ ├── vecSubs.cpp │ ├── vec_decls.cpp │ └── word_echo.cpp ├── 4 │ ├── README │ ├── arith-ex.cpp │ ├── arraysizeof.cpp │ ├── cond.cpp │ ├── data │ │ ├── oofe │ │ └── vecSubs │ ├── incr.cpp │ ├── int-div.cpp │ ├── makefile │ ├── oofe.cpp │ ├── overflow.cpp │ ├── prec.cpp │ ├── runpgms.bat │ ├── shift-prec.cpp │ ├── sizeof_pgm.cpp │ ├── unaryOps.cpp │ ├── vec_init.cpp │ └── warn_dbltoint.cpp ├── 5 │ ├── README │ ├── add_item2.cpp │ ├── data │ │ ├── add_item_data │ │ ├── doWhile │ │ ├── grades │ │ ├── guesses │ │ └── readme │ ├── doWhile.cpp │ ├── guess.cpp │ ├── ifgrades.cpp │ ├── makefile │ ├── othercnt.cpp │ ├── rangefor.cpp │ ├── runpgms.bat │ └── vowels.cpp ├── 6 │ ├── LocalMath.cpp │ ├── LocalMath.h │ ├── README │ ├── arrRet.cpp │ ├── count-calls.cpp │ ├── data │ │ ├── mainmath │ │ └── refparms │ ├── errMsg_initList.cpp │ ├── fact.cpp │ ├── fcnptrRet.cpp │ ├── good_printmain.cpp │ ├── inline_shorter.cpp │ ├── mainmath.cpp │ ├── mainret.cpp │ ├── make_plural.h │ ├── makefile │ ├── mk_plural.cpp │ ├── printFcns.h │ ├── ref-fcn.cpp │ ├── refparms.cpp │ ├── refret-ex.cpp │ ├── reset.cpp │ ├── runpgms.bat │ ├── stl-arr-fcns.cpp │ ├── use_mk_plural.cpp │ ├── usefcnptr.cpp │ └── wdebug.cpp ├── 7 │ ├── Account.cpp │ ├── Account.h │ ├── Debug.cpp │ ├── Debug.h │ ├── README │ ├── Sales_data.cpp │ ├── Sales_data.h │ ├── Screen.h │ ├── WindowMgr.h │ ├── add_item.cpp │ ├── avg_price.cpp │ ├── data │ │ ├── add_item │ │ └── book_sales │ ├── makefile │ ├── runpgms.bat │ ├── useAccount.cpp │ ├── useDebug.cpp │ └── useScreen.cpp ├── 8 │ ├── README │ ├── add_item.cpp │ ├── add_itemV2.cpp │ ├── buf.cpp │ ├── clearIO.cpp │ ├── data │ │ ├── add_item │ │ └── sstream │ ├── fileIO.cpp │ ├── makefile │ ├── runpgms.bat │ └── sstream.cpp ├── 9 │ ├── README │ ├── StrConvs.h │ ├── capacity.cpp │ ├── data │ │ └── erase │ ├── erase1.cpp │ ├── erase2.cpp │ ├── find-str.cpp │ ├── find_ops.cpp │ ├── makefile │ ├── refreshIter.cpp │ ├── runpgms.bat │ ├── stack.cpp │ ├── str_assignOps.cpp │ ├── substr.cpp │ └── useConvs.cpp ├── 10 │ ├── README │ ├── absInt.cpp │ ├── accum.cpp │ ├── accum4.cpp │ ├── avg_price.cpp │ ├── bind2.cpp │ ├── data │ │ ├── absInt │ │ ├── accum │ │ ├── book_sales │ │ ├── count-size │ │ ├── iostream_iter │ │ ├── outFile1 │ │ ├── outFile2 │ │ ├── rcomma │ │ ├── readme │ │ ├── reverse-iter │ │ └── use_find │ ├── elimDups.cpp │ ├── equal.cpp │ ├── equiv-istream-iter.cpp │ ├── foo2 │ ├── inserters.cpp │ ├── iostream_iter.cpp │ ├── lambda.cpp │ ├── makefile │ ├── newcount-size.cpp │ ├── ostreamIter2.cpp │ ├── rcomma.cpp │ ├── rev-iters.cpp │ ├── reverse-iter.cpp │ ├── reverse.cpp │ ├── runpgms.bat │ ├── sortSI.cpp │ ├── use-istream-iter.cpp │ └── use_find.cpp ├── 11 │ ├── README │ ├── data │ │ ├── Alice │ │ ├── rules │ │ ├── simple_query │ │ ├── storyDataFile │ │ ├── text │ │ └── word_count │ ├── erasemap.cpp │ ├── makefile │ ├── map1.cpp │ ├── multimap.cpp │ ├── pair.cpp │ ├── restricted_count.cpp │ ├── runpgms.bat │ ├── setOps.cpp │ ├── unorderedWordCount.cpp │ ├── wcEx.cpp │ ├── word_count.cpp │ └── word_transform.cpp ├── 12 │ ├── Foo.h │ ├── QueryResult.h │ ├── README │ ├── StrBlob.h │ ├── TextQuery.cpp │ ├── TextQuery.h │ ├── UP.cpp │ ├── allocPtr.cpp │ ├── allocSP.cpp │ ├── data │ │ ├── Alice │ │ ├── alloc │ │ └── storyDataFile │ ├── makefile │ ├── oknew.cpp │ ├── querymain.cpp │ ├── release.cpp │ ├── runpgms.bat │ ├── unique.cpp │ ├── useBlob.cpp │ ├── usealloc.cpp │ ├── usealloc2.cpp │ └── weak.cpp ├── 13 │ ├── Folder.cpp │ ├── Folder.h │ ├── FolderMain.cpp │ ├── HasPtrUseCount.cpp │ ├── HasPtrValueLike.cpp │ ├── README │ ├── StrFolder.cpp │ ├── StrFolder.h │ ├── StrFolderMain.cpp │ ├── StrVec.cpp │ ├── StrVec.h │ ├── String.cpp │ ├── String.h │ ├── copyNoMove.cpp │ ├── data │ │ └── storyDataFile │ ├── makefile │ ├── moveHP.cpp │ ├── runpgms.bat │ ├── serial.cpp │ ├── small2_SI.h │ ├── small_SI.h │ ├── substr.cpp │ └── useStrVec.cpp ├── 14 │ ├── README │ ├── Sales_data.cpp │ ├── Sales_data.h │ ├── absInt.cpp │ ├── add.cpp │ ├── calc.cpp │ ├── data │ │ ├── absInt │ │ ├── add_item │ │ ├── count-size │ │ └── word_echo │ ├── directcall.cpp │ ├── fcnobj.cpp │ ├── makefile │ ├── newcount-size.cpp │ ├── readStr.cpp │ ├── runpgms │ └── runpgms.bat ├── 15 │ ├── Basket.cpp │ ├── Basket.h │ ├── Basket_main.cpp │ ├── Query.cpp │ ├── Query.h │ ├── Quote.cpp │ ├── Quote.h │ ├── README │ ├── andQueryTest.cpp │ ├── and_orQueryTest.cpp │ ├── data │ │ ├── querymain │ │ ├── storyDataFile │ │ ├── three │ │ └── two │ ├── get_print.cpp │ ├── makefile │ ├── runpgms.bat │ ├── sample.cpp │ ├── scope.cpp │ ├── useQuote.cpp │ ├── vecBasket.cpp │ ├── virtualsNscope.cpp │ └── wordQueryTest.cpp ├── 16 │ ├── Array.cpp │ ├── Blob.h │ ├── DebugDelete.h │ ├── README │ ├── SP.cpp │ ├── Sales_data.cpp │ ├── Sales_data.h │ ├── Vec.h │ ├── Vecmain.cpp │ ├── array-parms4.cpp │ ├── build.cpp │ ├── compare.cpp │ ├── compare.h │ ├── compareDef.cpp │ ├── compareSpec.cpp │ ├── data │ │ ├── Vecmain │ │ ├── book_sales │ │ └── book_trans │ ├── debug.cpp │ ├── debug_rep.h │ ├── makefile │ ├── multiset.cpp │ ├── overSpec.cpp │ ├── qm.cpp │ ├── runpgms │ ├── runpgms.bat │ ├── special.cpp │ ├── useBlob.cpp │ └── useChcking.cpp ├── 17 │ ├── README │ ├── REerrs.cpp │ ├── badgetc.cpp │ ├── bits.cpp │ ├── ccpgms.cpp │ ├── data │ │ ├── badgetc │ │ ├── bits │ │ ├── copyOut │ │ ├── files │ │ ├── findDups │ │ ├── findDupsV2 │ │ ├── findgerunds │ │ ├── game │ │ ├── no-skipws │ │ ├── phones │ │ ├── phones2 │ │ ├── phonesFinal │ │ ├── skipws │ │ ├── store1 │ │ ├── store2 │ │ ├── store3 │ │ ├── store4 │ │ └── validatePhones │ ├── findbook.cpp │ ├── game.cpp │ ├── getc.cpp │ ├── getput.cpp │ ├── makefile │ ├── manips.cpp │ ├── no-skipws.cpp │ ├── normalInts.cpp │ ├── ourRandom.h │ ├── phones.cpp │ ├── phonesFinal.cpp │ ├── point.cpp │ ├── prec.cpp │ ├── rand1.cpp │ ├── rand2.cpp │ ├── rand4.cpp │ ├── rand6.cpp │ ├── regex1.cpp │ ├── runpgms.bat │ ├── seed.cpp │ ├── seek.cpp │ ├── setw.cpp │ ├── skipws.cpp │ ├── subexpr.cpp │ ├── tuple.cpp │ ├── validatePhones.cpp │ └── zips.cpp ├── 18 │ ├── Animal.cpp │ ├── Animal.h │ ├── Animal_virtual_baseVers.h │ ├── README │ ├── Sales_data.cpp │ ├── book.cpp │ ├── bookexcept.h │ ├── class.cpp │ ├── data │ │ └── book_sales │ ├── ex-over.cpp │ ├── inherit.cpp │ ├── makefile │ ├── mi-scope.cpp │ ├── over.cpp │ ├── over2.cpp │ ├── runpgms │ ├── runpgms.bat │ ├── usingDirective.cpp │ └── virt-inherit.cpp ├── 19 │ ├── .calc.cpp.swp │ ├── README │ ├── Screen.cpp │ ├── Screen.h │ ├── TextQuery.h │ ├── Token.h │ ├── bitfields.cpp │ ├── calc.cpp │ ├── dyn_cast.cpp │ ├── enum-match.cpp │ ├── enum.cpp │ ├── makefile │ ├── memFN-bind.cpp │ ├── runpgms │ ├── runpgms.bat │ ├── tok2.cpp │ ├── typeid.cpp │ └── useScreen.cpp ├── CompilerNotes.pdf ├── MS_makefile_template ├── README.pdf ├── makefile ├── runp.bat └── runpgms.bat └── README.md /C++Primer第五版课本源代码/1/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | book_sales avg_price, item_io 7 | add_item add_item, add_item2 8 | add add 9 | my_sum my_sum 10 | occurs occurs 11 | 12 | Programs not listed above print output and do 13 | not read any input 14 | 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/add.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | int main() 33 | { 34 | // prompt user to enter two numbers 35 | std::cout << "Enter two numbers:" << std::endl; 36 | int v1 = 0, v2 = 0; 37 | std::cin >> v1 >> v2; 38 | std::cout << "The sum of " << v1 << " and " << v2 39 | << " is " << v1 + v2 << std::endl; 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/add_item.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | #include "Sales_item.h" 32 | 33 | int main() 34 | { 35 | Sales_item item1, item2; 36 | 37 | std::cin >> item1 >> item2; //read a pair of transactions 38 | std::cout << item1 + item2 << std::endl; //print their sum 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/add_item2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | #include "Sales_item.h" 32 | 33 | int main() 34 | { 35 | Sales_item item1, item2; 36 | 37 | std::cin >> item1 >> item2; 38 | // first check that item1 and item2 represent the same book 39 | if (item1.isbn() == item2.isbn()) { 40 | std::cout << item1 + item2 << std::endl; 41 | return 0; // indicate success 42 | } else { 43 | std::cerr << "Data must refer to same ISBN" 44 | << std::endl; 45 | return -1; // indicate failure 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/data/add: -------------------------------------------------------------------------------- 1 | 3 7 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/data/book_sales: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/data/mysum: -------------------------------------------------------------------------------- 1 | 3 4 5 6 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/data/occurs: -------------------------------------------------------------------------------- 1 | 42 42 42 42 42 55 55 62 100 100 100 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/for_ex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | int main() 32 | { 33 | int sum = 0; 34 | for (int i = -100; i <= 100; ++i) 35 | sum += i; 36 | std::cout << sum << std::endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/forcount.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | int main() 33 | { 34 | int sum = 0; 35 | 36 | // sum values from 1 through 10 inclusive 37 | for (int val = 1; val <= 10; ++val) 38 | sum += val; // equivalent to sum = sum + val 39 | std::cout << "Sum of 1 to 10 inclusive is " 40 | << sum << std::endl; 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/item_io.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | #include "Sales_item.h" 32 | 33 | int main() 34 | { 35 | Sales_item book; 36 | 37 | // read ISBN, number of copies sold, and sales price 38 | std::cin >> book; 39 | // write ISBN, number of copies sold, total revenue, and average price 40 | std::cout << book << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/main_only.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | int main() 31 | { 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = add.exe add_item.exe add_item2.exe avg_price.exe \ 3 | for_ex.exe forcount.exe item_io.exe \ 4 | main_only.exe mysum.exe occurs.exe whilecount.exe 5 | 6 | # tells make to use the file "..\MS_makefile_template", which 7 | # defines general rules for making .obj and .exe files 8 | include ..\MS_makefile_template 9 | 10 | add_item.exe add_item2.exe avg_price.exe item_io.exe: Sales_item.h 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/mysum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | int main() 33 | { 34 | int sum = 0, value = 0; 35 | 36 | // read until end-of-file, calculating a running total of all values read 37 | while (std::cin >> value) 38 | sum += value; // equivalent to sum = sum + value 39 | 40 | std::cout << "Sum is: " << sum << std::endl; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | add < data/add 3 | add_item < data/add_item 4 | add_item2 < data/add_item 5 | avg_price < data/book_sales 6 | item_io < data/book_sales 7 | occurs < data/occurs 8 | mysum < data/mysum 9 | 10 | for %%i in ( for_ex forcount main_only whilecount) do %%i 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/1/whilecount.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | int main() 33 | { 34 | int sum = 0, val = 1; 35 | // keep executing the while as long as val is less than or equal to 10 36 | while (val <= 10) { 37 | sum += val; // assigns sum + val to sum 38 | ++val; // add 1 to val 39 | } 40 | std::cout << "Sum of 1 to 10 inclusive is " 41 | << sum << std::endl; 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | absInt absInt 7 | accum accum 8 | count-size elimDups 9 | count-size bind2 10 | count-size newcount-size 11 | book_sales avg_price 12 | book_sales sortSI 13 | iostream_iter accum4 14 | iostream_iter equiv-istream 15 | iostream_iter iostream_iter 16 | iostream_iter ostreamIter2 17 | iostream_iter use-istream-iter 18 | rcomma rcomma 19 | reverse-iter reverse-iter 20 | use_find use_find 21 | 22 | Programs not listed above print output and do 23 | not read any input 24 | 25 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/accum4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::accumulate; 32 | 33 | #include 34 | using std::istream_iterator; 35 | 36 | #include 37 | using std::cin; using std::cout; using std::endl; 38 | 39 | int main() 40 | { 41 | istream_iterator in(cin), eof; 42 | cout << accumulate(in, eof, 0) << endl; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/absInt: -------------------------------------------------------------------------------- 1 | -42 2 | 65 3 | -95 4 | 100 5 | 39 6 | -67 7 | 95 8 | 76 9 | -88 10 | 76 11 | 83 12 | 92 13 | 76 14 | -93 15 | 0 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/accum: -------------------------------------------------------------------------------- 1 | now is the time for all good fellows to come to the aid of the party 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/book_sales: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/count-size: -------------------------------------------------------------------------------- 1 | the quick red fox jumps over the slow red turtle 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/iostream_iter: -------------------------------------------------------------------------------- 1 | 23 109 45 89 6 34 12 90 34 23 56 23 8 89 23 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/outFile1: -------------------------------------------------------------------------------- 1 | the quick red fox jumps over the slow red turtle 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/outFile2: -------------------------------------------------------------------------------- 1 | 6 8 12 23 23 23 23 34 34 45 56 89 89 90 109 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/rcomma: -------------------------------------------------------------------------------- 1 | FIRST,MIDDLE,LAST 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/readme: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | SI_data arrow 7 | absInt absInt 8 | count-size bind 9 | count-size bind2 10 | count-size newcount-size 11 | book_sales avg_price 12 | iostream_iter accum4 13 | iostream_iter equiv-istream 14 | iostream_iter iostream_iter 15 | iostream_iter ostreamIter2 16 | iostream_iter use-istream-iter 17 | parms parms 18 | readme readStr 19 | reverse-iter reverse-iter 20 | use_find use_find 21 | 22 | Programs not listed above print output and do 23 | not read any input 24 | 25 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/reverse-iter: -------------------------------------------------------------------------------- 1 | 1 7 3 5 9 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/data/use_find: -------------------------------------------------------------------------------- 1 | 42 2 | 47 3 | 83 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/equiv-istream-iter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::istream_iterator; 32 | 33 | #include 34 | using std::vector; 35 | 36 | #include 37 | using std::cin; using std::cout; using std::endl; 38 | 39 | int main() { 40 | // use istream_iterator to initialize a vector 41 | istream_iterator in_iter(cin), eof; 42 | vector vec(in_iter, eof); 43 | 44 | for (vector::const_iterator it = vec.begin(); 45 | it != vec.end(); ++it) 46 | cout << *it << " "; 47 | cout << endl; 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/foo2: -------------------------------------------------------------------------------- 1 | for i in absInt.cc accum.cc accum4.cc avg_price.cc bind2.cc \ 2 | elimDups.cc equal.cc equiv-istream-iter.cc inserters.cc \ 3 | iostream_iter.cc lambda.cc newcount-size.cc ostreamIter2.cc \ 4 | rcomma.cc reverse.cc reverse-iter.cc rev-iters.cc sortSI.cc \ 5 | use_find.cc use-istream-iter.cc 6 | 7 | do 8 | echo $i 9 | sed -f ../../disclaimer.sed orig$i >$i 10 | done 11 | 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = absInt.exe accum.exe accum4.exe \ 3 | avg_price.exe bind2.exe elimDups.exe equal.exe \ 4 | equiv-istream-iter.exe inserters.exe \ 5 | iostream_iter.exe newcount-size.exe \ 6 | ostreamIter2.exe rcomma.exe \ 7 | reverse.exe reverse-iter.exe rev-iters.exe \ 8 | sortSI.exe use_find.exe use-istream-iter.exe 9 | 10 | # the corresponding source file uses c++ 11 features 11 | C11_OBJECTS = lambda.exe 12 | 13 | # tells make to use the file "..\MS_makefile_template", which 14 | # defines general rules for making .obj and .exe files 15 | include ..\MS_makefile_template 16 | 17 | LOCFLAGS = /I..\1 -I..\6 18 | 19 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/rev-iters.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::vector; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | int temp[] = {0,1,2,3,4,5,6,7,8,9}; 39 | vector vec(temp, temp + sizeof(temp)/sizeof(*temp)); 40 | 41 | // reverse iterator of vector from back to front 42 | // binds r_iter to the last element 43 | for (vector::reverse_iterator r_iter = vec.rbegin(); 44 | r_iter != vec.rend(); // one before first element 45 | ++r_iter) // decrements the iterator one element 46 | cout << *r_iter << endl; // prints 9, 8, 7, . . . 0 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/10/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | absInt.exe < data/absInt 3 | accum.exe < data/accum 4 | accum4.exe < data/iostream_iter 5 | avg_price.exe < data/book_sales 6 | bind2.exe < data/count-size 7 | elimDups < data/count-size 8 | equiv-istream-iter.exe < data/iostream_iter 9 | iostream_iter.exe < data/iostream_iter 10 | newcount-size.exe < data/count-size 11 | ostreamIter2.exe < data/iostream_iter 12 | rcomma.exe < data/rcomma 13 | reverse-iter.exe < data/reverse-iter 14 | sortSI.exe < data/book_sales 15 | use_find.exe < data/use_find 16 | use-istream-iter.exe < data/iostream_iter 17 | 18 | for %%i in ( equal.exe inserters.exe reverse.exe 19 | rev-iters.exe ) do %%i 20 | 21 | REM C++ 11 file: 22 | REM lambda.exe 23 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | storyDatafile wcEx 7 | storyDatafile erasemap 8 | storyDatafile pair 9 | storyDatafile word_count 10 | word_count restricted_count 11 | word_count unorderedWord_count 12 | 13 | Programs not listed above print output and do 14 | not read any input 15 | 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/Alice: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/rules: -------------------------------------------------------------------------------- 1 | brb be right back 2 | k okay? 3 | y why 4 | r are 5 | u you 6 | pic picture 7 | thk thanks! 8 | l8r later 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/simple_query: -------------------------------------------------------------------------------- 1 | data 2 | compiler 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/storyDataFile: -------------------------------------------------------------------------------- 1 | Alice Emma has long flowing red hair. 2 | Her Daddy says when the wind blows 3 | through her hair, it looks almost alive, 4 | like a fiery bird in flight. 5 | A beautiful fiery bird, he tells her, 6 | magical but untamed. 7 | "Daddy, shush, there is no such thing," 8 | she tells him, at the same time wanting 9 | him to tell her more. 10 | Shyly, she asks, "I mean, Daddy, is there?" 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/text: -------------------------------------------------------------------------------- 1 | where r u 2 | y dont u send me a pic 3 | k thk l8r 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/data/word_count: -------------------------------------------------------------------------------- 1 | Although most programmers are familiar with data structures 2 | such as vectors and lists, many have never used an 3 | associative data structure. 4 | Before we look at the details of how the library supports 5 | these types, it will be helpful to start with 6 | examples of how we can use 7 | these containers. 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = erasemap.exe map1.exe \ 3 | multimap.exe pair.exe \ 4 | restricted_count.exe setOps.exe \ 5 | unorderedWordCount.exe \ 6 | wcEx.exe word_count.exe word_transform.exe 7 | 8 | # tells make to use the file "..\MS_makefile_template", which 9 | # defines general rules for making .obj and .exe files 10 | include ..\MS_makefile_template 11 | 12 | # directory 7 has Sales_data code, 6 has make_plural function 13 | LOCFLAGS = /I..\7 -I..\6 14 | 15 | map1.exe: map1.obj ..\7\Sales_data.obj 16 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) map1.obj ..\7\Sales_data.obj 17 | 18 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/11/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | wcEx.exe < data/storyDataFile 3 | erasemap.exe < data/storyDataFile 4 | restricted_count.exe < data/word_count 5 | unorderedWordCount.exe < data/word_count 6 | word_count.exe < data/storyDataFile 7 | pair.exe < data/storyDataFile 8 | word_transform.exe data/rules data/text 9 | 10 | for %%i in ( map1.exe multimap.exe setOps.exe ) do %%i 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/Foo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #ifndef FOO_H 31 | #define FOO_H 32 | 33 | #include 34 | 35 | typedef int T; 36 | struct Foo { // members are public by default 37 | Foo(T t): val(t) { } 38 | T val; 39 | }; 40 | 41 | std::ostream& 42 | print(std::ostream &os, const Foo &f) 43 | { 44 | os << f.val; 45 | return os; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | storyDatafile usealloc 7 | storyDatafile querymain 8 | Alice querymain 9 | alloc allocPtr 10 | alloc allocSP 11 | 12 | Programs not listed above print output and do 13 | not read any input 14 | 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/data/Alice: -------------------------------------------------------------------------------- 1 | Alice 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/data/alloc: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/data/storyDataFile: -------------------------------------------------------------------------------- 1 | Alice Emma has long flowing red hair. 2 | Her Daddy says when the wind blows 3 | through her hair, it looks almost alive, 4 | like a fiery bird in flight. 5 | A beautiful fiery bird, he tells her, 6 | magical but untamed. 7 | "Daddy, shush, there is no such thing," 8 | she tells him, at the same time wanting 9 | him to tell her more. 10 | Shyly, she asks, "I mean, Daddy, is there?" 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = allocPtr.exe allocSP.exe \ 3 | oknew.exe querymain.exe \ 4 | unique.exe UP.exe \ 5 | usealloc.exe usealloc2.exe \ 6 | useBlob.exe weak.exe 7 | 8 | # the corresponding source file uses c++ 11 features 9 | C11_OBJECTS = release.exe 10 | 11 | # tells make to use the file "..\MS_makefile_template", which 12 | # defines general rules for making .obj and .exe files 13 | include ..\MS_makefile_template 14 | 15 | # 7 has Sales_data files, 6 has make_plural 16 | LOCFLAGS = /I..\7 -I..\6 17 | 18 | TextQuery.obj querymain.obj: TextQuery.h QueryResult.h 19 | 20 | querymain.exe: querymain.obj TextQuery.obj 21 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) querymain.obj TextQuery.obj \ 22 | -o querymain.exe 23 | 24 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | querymain.exe data/storyDataFile < data/Alice 3 | allocPtr.exe < data/alloc 4 | allocSP.exe < data/alloc 5 | usealloc.exe < data/storyDataFile 6 | 7 | for %%i in ( oknew.exe 8 | unique.exe UP.exe usealloc2.exe useBlob.exe weak.exe ) do %%i 9 | 10 | REM c++ 11 files: 11 | REM release.exe 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/unique.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::vector; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include 37 | using std::ostream; using std::cin; using std::cout; using std::endl; 38 | 39 | #include 40 | using std::shared_ptr; 41 | 42 | int main() { 43 | shared_ptr p(new string("Hello!")); 44 | shared_ptr p2(p); // two users of the allocated string 45 | string newVal; 46 | if (!p.unique()) 47 | p.reset(new string(*p)); // we aren't alone; allocate a new copy 48 | *p += newVal; // now that we know we're the only pointer, okay to change this object 49 | cout << *p << " " << *p2 << endl; 50 | } 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/useBlob.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced. Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | #include 30 | using std::cout; using std::endl; 31 | 32 | #include 33 | using std::string; 34 | 35 | #include "StrBlob.h" 36 | 37 | int main() 38 | { 39 | StrBlob b1; 40 | { 41 | string temp[] = { "a", "an", "the" }; 42 | StrBlob b2(temp, temp + sizeof(temp)/sizeof(*temp)); 43 | b1 = b2; 44 | b2.push_back("about"); 45 | cout << b2.size() << endl; 46 | } 47 | cout << b1.size() << endl; 48 | 49 | for (StrBlobPtr it = b1.begin(); neq(it, b1.end()); it.incr()) 50 | cout << it.deref() << endl; 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/12/weak.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::weak_ptr; using std::shared_ptr; 32 | 33 | int main() 34 | { 35 | shared_ptr p(new int(42)); 36 | 37 | weak_ptr wp(p); // wp weakly shares with p; use count in p is unchanged 38 | 39 | p.reset(); // assuming p.unique() was true, the int is deleted 40 | 41 | if (shared_ptr np = wp.lock()) { // true if np is not null 42 | // inside the if, np shares its object with p 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/README: -------------------------------------------------------------------------------- 1 | No programs in this chapter read input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | 7 | Programs not listed above print output and do 8 | not read any input 9 | 10 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/StrVec.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "StrVec.h" 31 | 32 | #include 33 | #include 34 | 35 | // errata fixed in second printing -- 36 | // StrVec's allocator should be a static member not an ordinary member 37 | 38 | // definition for static data member 39 | std::allocator StrVec::alloc; 40 | 41 | // all other StrVec members are inline and defined inside StrVec.h 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/copyNoMove.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | // This file illustrates the interaction between move and copy, 31 | // which only exists in C++ 11 32 | 33 | #include 34 | #include 35 | 36 | class Foo { 37 | public: 38 | Foo() = default; 39 | Foo(const Foo&); // copy constructor 40 | // other members, but Foo does not define a move constructor 41 | }; 42 | 43 | Foo::Foo(const Foo&) { std::cout << "Foo copy ctor" << std::endl; } 44 | 45 | int main() 46 | { 47 | Foo x; 48 | Foo y(x); // copy constructor; x is an lvalue 49 | Foo z(std::move(x)); // copy constructor, because there is no move constructor 50 | } 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/data/storyDataFile: -------------------------------------------------------------------------------- 1 | Alice Emma has long flowing red hair. 2 | Her Daddy says when the wind blows 3 | through her hair, it looks almost alive, 4 | like a fiery bird in flight. 5 | A beautiful fiery bird, he tells her, 6 | magical but untamed. 7 | "Daddy, shush, there is no such thing," 8 | she tells him, at the same time wanting 9 | him to tell her more. 10 | Shyly, she asks, "I mean, Daddy, is there?" 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = FolderMain.exe HasPtrUseCount.exe \ 3 | HasPtrValueLike.exe \ 4 | moveHP.exe serial.exe StrFolderMain.exe \ 5 | useStrVec.exe substr.exe 6 | 7 | # the corresponding source file uses c++ 11 features 8 | C11_OBJECTS = copyNoMove.exe 9 | 10 | # tells make to use the file "..\MS_makefile_template", which 11 | # defines general rules for making .obj and .exe files 12 | include ..\MS_makefile_template 13 | 14 | LOCFLAGS = /I..\1 -I..\7 15 | 16 | Folder.obj FolderMain.obj: Folder.h 17 | StrFolder.obj StrFolderMain.obj: StrFolder.h String.h 18 | String.obj: String.h 19 | useStrVec.obj StrVec.obj: String.h StrVec.h 20 | 21 | useStrVec.exe: StrVec.obj useStrVec.obj 22 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) useStrVec.obj StrVec.obj 23 | 24 | FolderMain.exe: Folder.obj FolderMain.obj 25 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) FolderMain.obj Folder.obj 26 | 27 | StrFolderMain.exe: StrFolder.obj StrFolderMain.obj String.obj 28 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) StrFolderMain.obj StrFolder.obj String.obj 29 | 30 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/runpgms.bat: -------------------------------------------------------------------------------- 1 | for %%i in ( FolderMain.exe HasPtrUseCount.exe 2 | HasPtrValueLike.exe moveHP.exe serial.exe 3 | StrFolderMain.exe substr.exe useStrVec.exe ) do %%i 4 | 5 | REM C++ 11 files: 6 | REM copyNoMove.exe 7 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/13/serial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::size_t; 35 | 36 | struct numbered { 37 | static size_t sn; 38 | numbered() : mysn(sn++) { } 39 | numbered(const numbered &) : mysn(sn++) { } 40 | numbered &operator=(const numbered &) { return *this; } 41 | size_t mysn; 42 | }; 43 | 44 | size_t numbered::sn = 0; 45 | 46 | void f (numbered s) { cout << s.mysn << endl; } 47 | 48 | int main() 49 | { 50 | numbered a, b = a, c = b; 51 | f(a); f(b); f(c); 52 | } 53 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add_item add 7 | count-size newcount-size 8 | count-size fcnobj 9 | word_echo readStr 10 | 11 | Programs not listed above print output and do 12 | not read any input 13 | 14 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/data/absInt: -------------------------------------------------------------------------------- 1 | -42 2 | 65 3 | -95 4 | 100 5 | 39 6 | -67 7 | 95 8 | 76 9 | -88 10 | 76 11 | 83 12 | 92 13 | 76 14 | -93 15 | 0 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | 4 | 0-201-78345-X 3 20.00 5 | 0-201-78345-X 2 25.00 6 | 7 | 0-201-78345-X 3 20.00 8 | 0-201-78345-X 2 25.00 9 | 10 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/data/count-size: -------------------------------------------------------------------------------- 1 | the quick red fox jumps over the slow red turtle 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/data/word_echo: -------------------------------------------------------------------------------- 1 | Now is the time for all good boys 2 | to come to the aid of the party 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = absInt.exe add.exe calc.exe directcall.exe \ 3 | fcnobj.exe newcount-size.exe readStr.exe 4 | 5 | # tells make to use the file "..\MS_makefile_template", which 6 | # defines general rules for making .obj and .exe files 7 | include ..\MS_makefile_template 8 | 9 | LOCFLAGS = /I..\1 -I..\6 10 | 11 | add.obj directcall.obj Sales_data.obj: Sales_data.h 12 | 13 | add.exe: add.obj Sales_data.obj 14 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) add.obj Sales_data.obj 15 | 16 | directcall.exe: directcall.obj Sales_data.obj 17 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) directcall.obj Sales_data.obj 18 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/runpgms: -------------------------------------------------------------------------------- 1 | echo "absInt:" && ./absInt.exe < data/absInt 2 | echo "add: " && ./add.exe < data/add_item 3 | echo "fcnobj: " && ./fcnobj.exe < data/count-size 4 | echo "directcall: " && ./directcall.exe < data/add_item 5 | echo "newcount-size: " && ./newcount-size.exe < data/count-size 6 | echo "readStr: " && ./readStr.exe < data/word_echo 7 | 8 | # c++ 11 files: 9 | # ../noinput calc.exe 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/14/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | absInt.exe < data/absInt 3 | add.exe < data/add_item 4 | fcnobj.exe < data/count-size 5 | directcall.exe < data/add_item 6 | newcount-size.exe < data/count-size 7 | readStr.exe < data/word_echo 8 | 9 | for %%i in ( calc.exe ) do %%i 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | storyDatafile andQueryTest 7 | storyDatafile and_orQueryTest 8 | storyDatafile wordQueryTest 9 | two andQueryTest 10 | three and_orQueryTest 11 | querymain wordQueryTest 12 | 13 | Programs not listed above print output and do 14 | not read any input 15 | 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/data/querymain: -------------------------------------------------------------------------------- 1 | Alice 2 | container 3 | Daddy 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/data/storyDataFile: -------------------------------------------------------------------------------- 1 | Alice Emma has long flowing red hair. 2 | Her Daddy says when the wind blows 3 | through her hair, it looks almost alive, 4 | like a fiery bird in flight. 5 | A beautiful fiery bird, he tells her, 6 | magical but untamed. 7 | "Daddy, shush, there is no such thing," 8 | she tells him, at the same time wanting 9 | him to tell her more. 10 | Shyly, she asks, "I mean, Daddy, is there?" 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/data/three: -------------------------------------------------------------------------------- 1 | fiery 2 | bird 3 | wind 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/data/two: -------------------------------------------------------------------------------- 1 | hair 2 | Alice 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = andQueryTest.exe and_orQueryTest.exe \ 3 | Basket_main.exe wordQueryTest.exe \ 4 | sample.exe scope.exe useQuote.exe \ 5 | vecBasket.exe virtualsNscope.exe 6 | 7 | # tells make to use the file "..\MS_makefile_template", which 8 | # defines general rules for making .obj and .exe files 9 | include ..\MS_makefile_template 10 | 11 | LOCFLAGS = /I..\12 -I..\6 12 | 13 | sample.obj useQuote.obj Quote.obj: Quote.h 14 | vecBasket.obj Basket_main.obj Basket.obj: Basket.h Quote.h 15 | 16 | get_print.obj andQueryTest.obj and_orQueryTest.obj \ 17 | wordQueryTest.obj Query.obj: Query.h ..\12\TextQuery.h 18 | 19 | wordQueryTest.exe: Query.obj wordQueryTest.obj ..\12\TextQuery.obj get_print.obj 20 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) wordQueryTest.obj Query.obj \ 21 | ..\12\TextQuery.obj get_print.obj 22 | 23 | andQueryTest.exe: Query.obj andQueryTest.obj ..\12\TextQuery.obj get_print.obj 24 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) andQueryTest.obj Query.obj \ 25 | ..\12\TextQuery.obj get_print.obj 26 | 27 | and_orQueryTest.exe: and_orQueryTest.obj Query.obj ..\12\TextQuery.obj \ 28 | get_print.obj 29 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) and_orQueryTest.obj Query.obj \ 30 | ..\12\TextQuery.obj get_print.obj 31 | 32 | useQuote.exe: useQuote.obj Quote.obj 33 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) useQuote.obj Quote.obj 34 | 35 | vecBasket.exe: Basket.obj vecBasket.obj Quote.obj 36 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) vecBasket.obj Basket.obj Quote.obj 37 | 38 | Basket_main.exe: Basket.obj Basket_main.obj Quote.obj 39 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) Basket_main.obj Basket.obj Quote.obj 40 | 41 | sample.exe: sample.obj Quote.obj 42 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) sample.obj Quote.obj 43 | 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | andQueryTest.exe data/storyDataFile < data/two 3 | and_orQueryTest.exe data/storyDataFile < data/three 4 | wordQueryTest.exe data/storyDataFile < data/querymain 5 | 6 | for %%i in ( Basket_main.exe sample.exe 7 | scope.exe useQuote.exe vecBasket.exe 8 | virtualsNscope.exe ) do %%i 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/15/useQuote.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::ostream; 32 | 33 | #include "Quote.h" 34 | 35 | int main() 36 | { 37 | Quote base("0-201-82470-1", 50); 38 | print_total(cout, base, 10); // calls Quote::net_price 39 | 40 | Bulk_quote derived("0-201-82470-1", 50, 5, .19); 41 | print_total(cout, derived, 10); // calls Bulk_quote::net_price 42 | 43 | Quote *baseP = &derived; 44 | 45 | // calls the version from the base class 46 | // regardless of the dynamic type of baseP 47 | double undiscounted = baseP->Quote::net_price(42); 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | book_sales compareDef 7 | book_trans multiset 8 | Vecmainin Vecmain 9 | 10 | Programs not listed above print output and do 11 | not read any input 12 | 13 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/build.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Blob.h" 31 | #include "compare.h" 32 | 33 | #include 34 | using std::string; 35 | 36 | // templateBuild.cc 37 | // instantiation file must provide a (nonextern) definition for every 38 | // type and function that other files declare as extern 39 | template int compare(const int&, const int&); 40 | template class Blob; // instantiates all members of the class template 41 | template class Blob; // instantiates Blob 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/compare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #ifndef COMPARE_H 31 | #define COMPARE_H 32 | #include 33 | 34 | // implement strcmp-like generic compare function 35 | // returns 0 if the values are equal, 1 if v1 is larger, -1 if v1 is smaller 36 | template 37 | int compare(const T &v1, const T &v2) 38 | { 39 | if (v1 < v2) return -1; 40 | if (v2 < v1) return 1; 41 | return 0; 42 | } 43 | 44 | // special version of compare to handle C-style character strings 45 | template <> 46 | inline 47 | int compare(const char* const &v1, const char* const &v2) 48 | { 49 | return std::strcmp(v1, v2); 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/data/Vecmain: -------------------------------------------------------------------------------- 1 | Although most programmers are familiar with data structures 2 | such as |vector|s and |list|s, many have never used an 3 | associative data structure. 4 | Before we look at the details of how the library supports 5 | these types, it will be helpful to start with 6 | examples of how we can use 7 | these containers. 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/data/book_sales: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | 0-999-78345-X 3 20.00 4 | 0-201-78345-X 2 25.00 5 | 0-201-78345-X 3 20.00 6 | 0-201-78345-X 2 25.00 7 | 0-999-78345-X 3 20.00 8 | 0-201-78345-X 2 25.00 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/data/book_trans: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = Array.exe array-parms4.exe \ 3 | compare.exe compareDef.exe compareSpec.exe \ 4 | debug.exe multiset.exe overloaded.exe overSpec.exe qm.exe \ 5 | SP.exe special.exe specialized.exe \ 6 | useBlob.exe useChcking.exe Vecmain.exe 7 | 8 | # tells make to use the file "..\MS_makefile_template", which 9 | # defines general rules for making .obj and .exe files 10 | include ..\MS_makefile_template 11 | 12 | LOCFLAGS = /I..\14 13 | 14 | SP.obj: DebugDelete.h 15 | 16 | Vecmain.obj: Vec.h 17 | 18 | compareDef.exe: compareDef.obj ..\14\Sales_data.obj 19 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) compareDef.obj ..\14\Sales_data.obj 20 | 21 | qm.exe: qm.obj build.obj 22 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) qm.obj build.obj 23 | 24 | specialized.exe: debug.cpp 25 | $(CPP) /Fespecialized -D SPECIALIZED $(CPPFLAGS) $(LOCFLAGS) debug.cpp 26 | 27 | overloaded.exe: debug.cpp 28 | $(CPP) /Feoverloaded -D OVERCHAR $(CPPFLAGS) $(LOCFLAGS) debug.cpp 29 | 30 | debug.exe: debug.cpp 31 | $(CPP) -D DEBUG $(CPPFLAGS) $(LOCFLAGS) debug.cpp 32 | 33 | multiset.exe: multiset.obj Sales_data.obj 34 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) multiset.obj Sales_data.obj 35 | 36 | 37 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/multiset.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include 37 | using std::cin; using std::cout; using std::endl; 38 | 39 | #include 40 | using std::unordered_multiset; 41 | 42 | #include 43 | 44 | #include "Sales_data.h" 45 | 46 | using std::hash; 47 | 48 | int main() 49 | { 50 | // uses hash and Sales_data operator== 51 | unordered_multiset SDset; 52 | Sales_data item; 53 | while (cin >> item) { 54 | SDset.insert(item); 55 | } 56 | cout << SDset.size() << endl; 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/runpgms: -------------------------------------------------------------------------------- 1 | echo "Vecmain: " && ./Vecmain.exe < data/Vecmain 2 | echo "compareDef: " && ./compareDef.exe < data/book_sales 3 | 4 | ../noinput Array.exe array-parms4.exe \ 5 | compare.exe compareSpec.exe \ 6 | debug.exe overloaded.exe overSpec.exe qm.exe \ 7 | SP.exe special.exe specialized.exe \ 8 | useBlob.exe useChcking.exe 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/16/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | compareDef.exe < data/book_sales 3 | multiset.exe < data/book_trans 4 | Vecmain.exe < data/Vecmain 5 | 6 | for %%i in ( Array.exe array-parms4.exe 7 | compare.exe compareSpec.exe 8 | debug.exe flip.exe 9 | overloaded.exe overSpec.exe qm.exe 10 | SP.exe special.exe specialized.exe 11 | trail-ret.exe useBlob.exe useChcking.exe ) do %%i 12 | 13 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | bits bits 7 | game game 8 | no-skipws no-skipws 9 | skipws getc 10 | skipws badgetc 11 | skipws getput 12 | skipws skipws 13 | store1,store2, 14 | store3,store4 findbook 15 | 16 | Programs not listed above print output and do 17 | not read any input 18 | 19 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/REerrs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::regex; using std::sregex_iterator; using std::smatch; 35 | using std::regex_error; 36 | 37 | int main() 38 | { 39 | try { 40 | // missing close bracket after alnum; the constructor will throw 41 | regex r("[[:alnum:]+\\.(cpp|cxx|cc)$", regex::icase); 42 | } catch (regex_error e) 43 | { cout << e.what() << "\ncode: " << e.code() << endl; } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/badgetc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include // for EOF 31 | #include 32 | using std::cin; using std::cout; using std::endl; 33 | 34 | int main() 35 | { 36 | char ch; // using a char here invites disaster! 37 | 38 | // the return from cin.get is converted to char 39 | // and then compared to an int 40 | while ((ch = cin.get()) != EOF) 41 | cout.put(ch); 42 | cout << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/badgetc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xaxfan/Cpp_Primer_5th/9b2de2a6ccd1833d9e96510cfbd89c859fd05844/C++Primer第五版课本源代码/17/data/badgetc -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/bits: -------------------------------------------------------------------------------- 1 | 11110001 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/files: -------------------------------------------------------------------------------- 1 | badgetc.cpp 2 | bits.cpp 3 | ccpgms.cpp 4 | findbook.cpp 5 | findDups.cpp 6 | findDupsV2.cpp 7 | findgerunds.cpp 8 | game.cpp 9 | getc.cpp 10 | getput.cpp 11 | manips.cpp 12 | manips11.cpp 13 | normalInts.cpp 14 | no-skipws.cpp 15 | phones.cpp 16 | phones2.cpp 17 | phonesFinal.cpp 18 | play.cpp 19 | point.cpp 20 | prec.cpp 21 | rand1.cpp 22 | rand2.cpp 23 | rand4.cpp 24 | rand6.cpp 25 | REerrs.cpp 26 | regex1.cpp 27 | sci_dec.cpp 28 | seed.cpp 29 | seek.cpp 30 | setw.cpp 31 | skipws.cpp 32 | subexpr.cpp 33 | tuple.cpp 34 | validatePhones.cpp 35 | zips.cpp 36 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/findDups: -------------------------------------------------------------------------------- 1 | Some some repeated words words 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/findDupsV2: -------------------------------------------------------------------------------- 1 | some some input that has has some dups 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/findgerunds: -------------------------------------------------------------------------------- 1 | when i was going to saint ives 2 | when going to saint ives 3 | i was going when i went 4 | i was when going 5 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/game: -------------------------------------------------------------------------------- 1 | y y y y y y y y y y y y y q 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/no-skipws: -------------------------------------------------------------------------------- 1 | a b c 2 | d 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/phones: -------------------------------------------------------------------------------- 1 | morgan (201) 555-0168 862-555-0123 2 | drew (973)555.0130 3 | lee (609) 555-0132 2015550175 800.555-0110 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/phones2: -------------------------------------------------------------------------------- 1 | morgan (201) 555-0168 (862) 555-0123 2 | drew (973) 555-0130 3 | lee (609) 555-0132 (201) 555-0175 (800) 555-0110 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/phonesFinal: -------------------------------------------------------------------------------- 1 | (908)555.0136 2 | (908.555.0136 3 | 908).555.0136 4 | 908 555.0136 5 | 908-555.0136 6 | 908 555 0136 7 | 908.555.0136 8 | 908-555-0136 9 | morgan (201) 555-0168 862-555-0123 10 | drew (973)555.0130 11 | lee (609) 555-0132 2015550175 800.555-0110 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/skipws: -------------------------------------------------------------------------------- 1 | a b c 2 | d 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/store1: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/store2: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | 0-999-78345-X 3 20.00 4 | 0-201-78345-X 2 25.00 5 | 0-201-78345-X 3 20.00 6 | 0-201-78345-X 2 25.00 7 | 0-999-78345-X 3 20.00 8 | 0-201-78345-X 2 25.00 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/store3: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/store4: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/data/validatePhones: -------------------------------------------------------------------------------- 1 | (908)555.0106 2 | (908.555.0106 3 | 908).555.0106 4 | 908 555.0106 5 | 908-555.0106 6 | 908 555 0106 7 | 908.555.0106 8 | 908-555-0106 9 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/getc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cin; using std::cout; using std::endl; 32 | 33 | #include // for EOF 34 | 35 | int main() 36 | { 37 | int ch; // use an int, not a char to hold the return from get() 38 | 39 | // loop to read and write all the data in the input 40 | while ((ch = cin.get()) != EOF) 41 | cout.put(ch); 42 | cout << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/getput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cin; using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | char ch; 36 | while (cin.get(ch)) 37 | cout.put(ch); 38 | cout << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = badgetc.exe bits.exe findbook.exe \ 3 | game.exe getc.exe getput.exe manips.exe \ 4 | normalInts.exe no-skipws.exe point.exe \ 5 | prec.exe rand1.exe rand2.exe rand4.exe \ 6 | rand6.exe seed.exe seek.exe setw.exe \ 7 | skipws.exe tuple.exe phones.exe \ 8 | ccpgms.exe validatePhones.exe \ 9 | phonesFinal.exe subexpr.exe \ 10 | regex1.exe zips.exe REerrs.exe 11 | 12 | # tells make to use the file "..\MS_makefile_template", which 13 | # defines general rules for making .obj and .exe files 14 | include ..\MS_makefile_template 15 | 16 | LOCFLAGS = /I..\14 17 | 18 | findbook.obj: ..\14\Sales_data.h 19 | 20 | findbook.exe: findbook.obj ..\14\Sales_data.obj 21 | $(CPP) $(CPPFLAGS) findbook.obj ..\14\Sales_data.obj 22 | 23 | 24 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/no-skipws.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cin; using std::cout; 32 | using std::noskipws; using std::skipws; 33 | 34 | int main() 35 | { 36 | char ch; 37 | cin >> noskipws; // set cin so that it reads whitespace 38 | while (cin >> ch) 39 | cout << ch; 40 | cin >> skipws; // reset cin to the default state 41 | // so that it ignores whitespace 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/ourRandom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced. Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | /* this file defines a C++ 11 facility used by our 31 | * random number programs: 32 | * 33 | * tr1 also did not define lround function, which we define here 34 | */ 35 | 36 | #ifndef OURRANDOM_H 37 | #define OURRANDOM_H 38 | 39 | inline long lround(double d) 40 | { 41 | return (d >= 0) ? long(d + 0.5) : long(d - 0.5); 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/point.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | using std::showpoint; using std::noshowpoint; 33 | 34 | int main() 35 | { 36 | cout << 10.0 << endl; // prints 10 37 | cout << showpoint << 10.0 // prints 10.0000 38 | << noshowpoint << endl; // revert to default format 39 | 40 | cout << 10.0 << endl; // prints 10 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | badgetc.exe < data/skipws 3 | bits.exe < data/bits 4 | ccpgms.exe < data/files 5 | findbook.exe data/store* 6 | game.exe < data/game 7 | getc.exe < data/skipws 8 | getput.exe < data/skipws 9 | no-skipws.exe < data/no-skipws 10 | phones.exe < data/phones 11 | phonesFinal.exe < data/phonesFinal 12 | skipws.exe < data/skipws 13 | subexpr.exe < data/files 14 | validatePhones.exe < data/validatePhones 15 | 16 | for %%i in ( manips.exe normalInts.exe point.exe 17 | prec.exe rand1.exe rand2.exe rand4.exe 18 | rand6.exe regex1.exe REerrs.exe 19 | seed.exe seek.exe setw.exe tuple.exe zips.exe ) do %%i 20 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/17/skipws.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cin; using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | char ch; 36 | while (cin >> ch) 37 | cout << ch; 38 | cout << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | book_sales book 7 | 8 | Programs not listed above print output and do 9 | not read any input 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/book.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Sales_data.h" 31 | #include "bookexcept.h" 32 | 33 | #include 34 | using std::cin; using std::cerr; using std::endl; 35 | 36 | int main() 37 | { 38 | // use the hypothetical bookstore exceptions 39 | Sales_data item1, item2, sum; 40 | while (cin >> item1 >> item2) { // read two transactions 41 | try { 42 | sum = item1 + item2; // calculate their sum 43 | // use sum 44 | } catch (const isbn_mismatch &e) { 45 | cerr << e.what() << ": left isbn(" << e.left 46 | << ") right isbn(" << e.right << ")" << endl; 47 | } 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/class.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | int main() 34 | { 35 | std::string s; 36 | 37 | // ok: calls std::getline(std::istream&, const std::string&) 38 | getline(std::cin, s); 39 | 40 | std::cout << s << std::endl; 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/data/book_sales: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/inherit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | namespace NS { 33 | class Quote { 34 | public: 35 | Quote() { std::cout << "Quote::Quote" << std::endl; } 36 | }; 37 | void display(const Quote&) 38 | { std::cout << "display(const Quote&)" << std::endl; } 39 | } 40 | 41 | // Bulk_item's base class is declared in namespace NS 42 | class Bulk_item : public NS::Quote { 43 | public: 44 | Bulk_item() { std::cout << "Bulk_item::Bulk_item" << std::endl; } 45 | }; 46 | 47 | int main() { 48 | Bulk_item book1; 49 | 50 | display(book1); // calls Quote::display 51 | 52 | return 0; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = Animal.exe book.exe class.exe \ 3 | ex-over.exe inherit.exe mi-scope.exe\ 4 | over.exe over2.exe \ 5 | usingDirective.exe virt-inherit.exe 6 | 7 | # tells make to use the file "..\MS_makefile_template", which 8 | # defines general rules for making .obj and .exe files 9 | include ..\MS_makefile_template 10 | 11 | LOCFLAGS = /I..\14 12 | 13 | Animal.obj: Animal.h 14 | book.obj: ..\14\Sales_data.h bookexcept.h 15 | virt-inherit.obj: Animal_virtual_baseVers.h 16 | 17 | book.exe: book.obj bookexcept.h ..\14\Sales_data.obj 18 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) book.obj ..\14\Sales_data.obj 19 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/over2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | namespace AW { 33 | int print(int i) 34 | { std::cout << "AW::print(int)" << std::endl; return i; } 35 | } 36 | namespace Primer { 37 | double print(double d) 38 | { std::cout << "Primer::print(double)" << std::endl; return d; } 39 | } 40 | 41 | // using directives create an overload set of functions from different namespaces 42 | using namespace AW; 43 | using namespace Primer; 44 | 45 | long double print(long double); 46 | 47 | int main() { 48 | print(1); // calls AW::print(int) 49 | print(3.1); // calls Primer::print(double) 50 | 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/runpgms: -------------------------------------------------------------------------------- 1 | echo "book: " && ./book.exe < data/book_sales 2 | 3 | ../noinput Animal.exe ex-over.exe inherit.exe mi-scope.exe\ 4 | over.exe over2.exe \ 5 | usingDirective.exe virt-inherit.exe 6 | 7 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/18/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | book.exe < data/book_sales 3 | 4 | for %%i in ( Animal.exe ex-over.exe inherit.exe mi-scope.exe 5 | over.exe over2.exe spec.exe 6 | usingDirective.exe virt-inherit.exe ) do %%i 7 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/.calc.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xaxfan/Cpp_Primer_5th/9b2de2a6ccd1833d9e96510cfbd89c859fd05844/C++Primer第五版课本源代码/19/.calc.cpp.swp -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/README: -------------------------------------------------------------------------------- 1 | None of the programs in this chapter read input. 2 | 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/Screen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced. Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Screen.h" 31 | 32 | Screen::Action Screen::Menu[] = { &Screen::home, 33 | &Screen::forward, 34 | &Screen::back, 35 | &Screen::up, 36 | &Screen::down, 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = bitfields.exe calc.exe dyn_cast.exe enum.exe enum-match.exe \ 3 | memFN-bind.exe typeid.exe useScreen.exe 4 | 5 | # tells make to use the file "..\MS_makefile_template", which 6 | # defines general rules for making .obj and .exe files 7 | include ..\MS_makefile_template 8 | 9 | LOCFLAGS = /I..\14 10 | 11 | Screen.obj useScreen.obj: Screen.h 12 | 13 | useScreen.exe: useScreen.obj Screen.obj 14 | $(CPP) $(CPPFLAGS) useScreen.obj Screen.obj 15 | 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/runpgms: -------------------------------------------------------------------------------- 1 | ../noinput bitfields.exe dyn_cast.exe enum.exe \ 2 | enum-match.exe typeid.exe \ 3 | useScreen.exe 4 | 5 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/runpgms.bat: -------------------------------------------------------------------------------- 1 | 2 | for %%i in ( bitfields.exe calc.exe dyn_cast.exe enum.exe 3 | enum-match.exe memFN-bind.exe tok2.exe 4 | typeid.exe ) do %%i 5 | 6 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/tok2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | // This file illustrates use of unions with a class type member 31 | // that has constructors and copy control members 32 | // Such unions are supported only under C++ 11 33 | 34 | #include 35 | using std::string; 36 | 37 | #include 38 | using std::cout; using std::endl; 39 | 40 | #include "Token.h" 41 | 42 | int main() 43 | { 44 | Token token; 45 | Token t2; 46 | Token t3; 47 | cout << t2 << " " << t3 << endl; 48 | t2 = string("hi mom!"); 49 | t3 = "good bye"; 50 | token = t2; 51 | token = "boo"; 52 | cout << token << endl; 53 | t2 = t3; 54 | cout << t2 << endl; 55 | 56 | token = 42; 57 | cout << token << endl; 58 | } 59 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/19/typeid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Sales_data.h" 31 | 32 | #include 33 | using std::cout; using std::endl; 34 | 35 | #include 36 | 37 | #include 38 | using std::string; 39 | 40 | struct Base { 41 | virtual ~Base() { } 42 | }; 43 | 44 | struct Derived : Base { }; 45 | 46 | int main() 47 | { 48 | int arr[10]; 49 | Derived d; 50 | Base *p = &d; 51 | 52 | cout << typeid(42).name() << ", " 53 | << typeid(arr).name() << ", " 54 | << typeid(Sales_data).name() << ", " 55 | << typeid(std::string).name() << ", " 56 | << typeid(p).name() << ", " 57 | << typeid(*p).name() << endl; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add_item Sales_data 7 | 8 | Programs not listed above print output and do 9 | not read any input 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/Sales_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #ifndef SALES_DATA_H 31 | #define SALES_DATA_H 32 | 33 | #include 34 | 35 | struct Sales_data { 36 | std::string bookNo; 37 | unsigned units_sold; 38 | double revenue; 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/data/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/escape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | int main() { 33 | std::cout << '\n'; // prints a newline 34 | std::cout << "\tHi!\n"; // prints a tab followd by "Hi!" and a newline 35 | std::cout << "Hi \x4dO\115!\n"; // prints Hi MOM! followed by a newline 36 | std::cout << '\115' << '\n'; // prints M followed by a newline 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/inits.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Sales_item.h" 31 | #include 32 | #include 33 | 34 | 35 | int main() { 36 | 37 | int v1(1024); // direct-initialization, functional form 38 | int v3 = 1024; // copy-initialization 39 | 40 | 41 | // alternative ways to initialize string from a character string literal 42 | std::string titleA = "C++ Primer, 5th Ed."; 43 | std::string titleB("C++ Primer, 5th Ed."); 44 | std::string all_nines(10, '9'); // all_nines = "9999999999" 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/literals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | int main() 32 | { 33 | std::cout << "Hello World!"; // simple character string literal 34 | std::cout << ""; // empty character string literal 35 | // literal using newlines and tabs 36 | std::cout << "\nCC\toptions\tfile.[cC]\n"; 37 | 38 | // multiline string literal 39 | std::cout << "a really, really long string literal " 40 | "that spans two lines" << std::endl; 41 | 42 | // three ways to print a capital M 43 | std::cout << 'M' << " " << '\115' << " " << '\x4d' << std::endl; 44 | 45 | unsigned long long bigVal = -1ULL; 46 | std::cout << bigVal << std::endl; 47 | 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = compounddecls.exe convs.exe dbl_ptr.exe \ 3 | escape.exe inits.exe \ 4 | literals.exe ref-ex.exe Sales_data.exe \ 5 | scope_levels.exe unsigned.exe 6 | 7 | # these executables are not made by default; 8 | # the corresponding source file uses c++ 11 features 9 | C11_OBJECTS = decl-ex.exe 10 | 11 | # tells make to use the file "..\MS_makefile_template", which 12 | # defines general rules for making .obj and .exe files 13 | include ..\MS_makefile_template 14 | 15 | LOCFLAGS = /I..\1 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/ref-ex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | int main() 32 | { 33 | int i = 0, &ri = i; // ri is a reference to i 34 | // ri is just another name for i; 35 | // this statement prints the value of i twice 36 | std::cout << i << " " << ri << std::endl; 37 | 38 | i = 5; // changing i is reflected through ri as well 39 | std::cout << i << " " << ri << std::endl; 40 | 41 | ri = 10; // assigning to ri actually assigns to i 42 | std::cout << i << " " << ri << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/2/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | Sales_data < data/add_item 3 | 4 | for %%i in (compounddecls.exe convs.exe dbl_ptr.exe 5 | decl-ex.exe escape.exe inits.exe 6 | literals.exe ref-ex.exe 7 | scope_levels.exe unsigned.exe ) do %%i 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add add_using 7 | grades arrayScores 8 | grades vecScores 9 | hexify hexify 10 | ptr_traversal2 ptr_traversal2 11 | string_io string_io 12 | string_io2 string_io 13 | vecStrings2 vecStrings2 14 | word_echo getline 15 | word_echo string_size2 16 | word_echo string_size3 17 | word_echo word_echo 18 | 19 | Programs not listed above print output and do 20 | not read any input 21 | 22 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/add_using.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | 32 | // using declarations for names from the standard library 33 | using std::cin; 34 | using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | cout << "Enter two numbers:" << endl; 39 | 40 | int v1, v2; 41 | cin >> v1 >> v2; 42 | 43 | cout << "The sum of " << v1 << " and " << v2 44 | << " is " << v1 + v2 << endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/add: -------------------------------------------------------------------------------- 1 | 3 7 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/grades: -------------------------------------------------------------------------------- 1 | 45 2 | 65 3 | 99 4 | 100 5 | 34 6 | 67 7 | 95 8 | 76 9 | 88 10 | 75 11 | 83 12 | 92 13 | 76 14 | 93 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/hexify: -------------------------------------------------------------------------------- 1 | 12 0 5 15 8 15 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/iterarith: -------------------------------------------------------------------------------- 1 | now is the time for all good boys to use their sense 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/ptr_traversal2: -------------------------------------------------------------------------------- 1 | 345 42 5 34 8 -20 16 35 100 200 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/string_io: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/vecStrings2: -------------------------------------------------------------------------------- 1 | When we subscript a string, we get back a character. 2 | When we subscript a vector, we get an object of whatever type the vector contains. 3 | We can use the resulting (unnamed) object in exactly the same way we can use any other object of that type. 4 | In particular, if the type is a class type, such as a library string, we can call member functions or use operators defined by the element type. 5 | 6 | As an example, let's write a program to capitalize the first word of every sentence in the first paragraph of some text. 7 | We'll assume that our input contains a series of lines. 8 | Each line is either a complete sentence or it contains only a newline. 9 | Lines containing a only a newline separate paragraphs. 10 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/data/word_echo: -------------------------------------------------------------------------------- 1 | Now is the time for all good boys 2 | to come to the aid of the party 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/getline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; using std::getline; 32 | 33 | #include 34 | using std::cin; using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | string line; 39 | 40 | // read input a line at a time until end-of-file 41 | while (getline(cin, line)) 42 | cout << line << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = add_using.exe arrayScores.exe cctype.exe \ 3 | char_repl.exe cstring_hdr.exe getline.exe \ 4 | hexify.exe multidim.exe \ 5 | ptr_traversal2.exe square.exe strcompare.exe \ 6 | string_add.exe string_io.exe string_io2.exe \ 7 | string_size.exe string_size2.exe string_size3.exe \ 8 | vec_decls.exe vecStrings2.exe vecScores.exe \ 9 | vecSubs.exe word_echo.exe 10 | 11 | # tells make to use the file "..\MS_makefile_template", which 12 | # defines general rules for making .obj and .exe files 13 | include ..\MS_makefile_template 14 | 15 | LOCFLAGS = /I..\1 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | add_using < data/add 3 | arrayScores < data/grades 4 | hexify < data/hexify 5 | ptr_traversal2 < data/ptr_traversal2 6 | string_io < data/string_io 7 | string_io2 < data/string_io 8 | vecStrings2 < data/vecStrings2 9 | vecScores < data/grades 10 | getline < data/word_echo 11 | string_size2 < data/word_echo 12 | string_size3 < data/word_echo 13 | word_echo < data/word_echo 14 | 15 | for %%i in (cctype.exe char_repl.exe cstring_hdr.exe 16 | multidim.exe square.exe strcompare.exe 17 | string_add.exe string_size.exe vec_decls.exe 18 | vecSubs.exe) do %%i 19 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/square.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::vector; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | vector v; 39 | for (size_t i = 1; i != 10; ++i) // give v elements with values from 1...9 40 | v.push_back(i); 41 | for (size_t i = 0; i != v.size(); ++i) // for each element in v 42 | v[i] *= v[i]; // square the element value 43 | for (size_t i = 0; i != v.size(); ++i) // for each element in v 44 | cout << v[i] << " "; // print the element 45 | cout << endl; 46 | 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/strcompare.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | string str = "Hello"; 39 | string phrase = "Hello World"; 40 | string slang = "Hiya"; 41 | 42 | if (str < phrase) cout << "str is smaller" << endl; 43 | if (slang > str) cout << "slang is greater" << endl; 44 | if (slang > phrase) cout << "slang is greater" << endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_add.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::string; 35 | 36 | int main() 37 | { 38 | 39 | string s1 = "hello, ", s2 = "world\n"; 40 | string s3 = s1 + s2; // s3 is hello, world\n 41 | cout << s1 << s2 << s3 << endl; 42 | 43 | s1 += s2; // equivalent to s1 = s1 + s2 44 | cout << s1; 45 | 46 | string s4 = "hello", s5 = "world"; // no punctuation in s4 or s2 47 | string s6 = s4 + ", " + s5 + '\n'; 48 | cout << s4 << s5 << "\n" << s6 << endl; 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_io.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include 34 | using std::cin; 35 | using std::cout; 36 | using std::endl; 37 | 38 | int main() 39 | { 40 | string s; // empty string 41 | cin >> s; // read a whitespace-separated string into s 42 | cout << s << endl; // write s to the output 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_io2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include 34 | using std::cin; using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | string s1, s2; 39 | 40 | cin >> s1 >> s2; // read first input into s1, second into s2 41 | cout << s1 << s2 << endl; // write both strings 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_size.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | string st1; // empty string 37 | string st2(st1); // st2 is a copy of st1 38 | 39 | int main() 40 | { 41 | string st("The expense of spirit\n"); 42 | cout << "The size of " << st << "is " << st.size() 43 | << " characters, including the newline" << endl; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_size2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::string; using std::getline; 35 | 36 | #include 37 | using std::cin; using std::cout; using std::endl; 38 | 39 | int main() 40 | { 41 | string line; 42 | 43 | // read input a line at a time and print lines that are longer than 80 characters 44 | while (getline(cin, line)) 45 | if (line.size() > 80) 46 | cout << line << endl; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/string_size3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; using std::getline; 32 | 33 | #include 34 | using std::cin; using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | string line; 39 | 40 | // read input a line at a time and discard blank lines 41 | while (getline(cin, line)) 42 | if (!line.empty()) 43 | cout << line << endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/3/word_echo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cin; using std::cout; using std::endl; 32 | 33 | #include 34 | using std::string; 35 | 36 | int main() 37 | { 38 | string word; 39 | while (cin >> word) // read until end-of-file 40 | cout << word << endl; // write each word followed by a new line 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | vecSubs cond 7 | 8 | Programs not listed above print output and do 9 | not read any input 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/arith-ex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | cout << -30 * 3 + 21 / 5 << endl; 36 | 37 | cout << -30 + 3 * 21 / 5 << endl; 38 | 39 | cout << 30 / 3 * 21 % 5 << endl; 40 | 41 | cout << 30 / 3 * 21 % 4 << endl; 42 | 43 | cout << -30 / 3 * 21 % 4 << endl; 44 | 45 | cout << 12 / 3 * 4 + 5 * 15 + 24 % 4 / 2 << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/arraysizeof.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::size_t; 35 | 36 | int ia[] = {0,1,2,3,4,5,6,7,8,9}; 37 | 38 | int main() 39 | { 40 | // sizeof(ia)/sizeof(*ia) returns the number of elements in ia 41 | const size_t sz = sizeof(ia)/sizeof(*ia); 42 | 43 | int arr2[sz]; // ok sizeof returns a constant expression 44 | 45 | cout << "ia size: " << sz << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/data/oofe: -------------------------------------------------------------------------------- 1 | 0 -100 1 -1 2 -3 3 -3 4 -4 5 -5 6 -6 7 -7 8 -8 9 -9 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/data/vecSubs: -------------------------------------------------------------------------------- 1 | 42 2 | 65 3 | 95 4 | 100 5 | 39 6 | 67 7 | 95 8 | 76 9 | 88 10 | 76 11 | 83 12 | 92 13 | 76 14 | 93 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/incr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | int i = 0, j; 36 | j = ++i; // j = 1, i = 1: prefix yields the incremented value 37 | cout << i << " " << j << endl; 38 | 39 | j = i++; // j = 1, i = 2: postfix yields the unincremented value 40 | cout << i << " " << j << endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/int-div.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | // ival1 is 3; result is truncated; remainder is discarded 36 | int ival1 = 21/6; 37 | 38 | // ival2 is 3; no remainder; result is an integral value 39 | int ival2 = 21/7; 40 | 41 | cout << ival1 << " " << ival2 << endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = arith-ex.exe arraysizeof.exe cond.exe \ 3 | incr.exe int-div.exe oofe.exe overflow.exe \ 4 | prec.exe shift-prec.exe sizeof_pgm.exe \ 5 | unaryOps.exe vec_init.exe warn_dbltoint.exe 6 | 7 | # tells make to use the file "..\MS_makefile_template", which 8 | # defines general rules for making .obj and .exe files 9 | include ..\MS_makefile_template 10 | 11 | LOCFLAGS = /I..\2 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/overflow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | short short_value = 32767; // max value if shorts are 16 bits 36 | 37 | short_value += 1; // this calculation overflows 38 | cout << "short_value: " << short_value << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | cond < data/vecSubs 3 | 4 | for %%i in (arith-ex.exe arraysizeof.exe 5 | incr.exe int-div.exe oofe.exe overflow.exe 6 | prec.exe shift-prec.exe sizeof_pgm.exe 7 | unaryOps.exe vec_init.exe warn_dbltoint.exe ) do %%i 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/unaryOps.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | int i = 1024; 36 | int k = -i; // i is -1024 37 | 38 | bool b = true; 39 | bool b2 = -b; // b2 is true! 40 | 41 | cout << b << " " << b2 << " " << endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/4/warn_dbltoint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | int main() 34 | { 35 | // the compiler might warn about loss of precision 36 | int ival = 3.541 + 3; // the compiler might warn about loss of precision 37 | cout << ival << endl; // prints 6 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add_item_data add_item2 7 | doWhile doWhile 8 | grades ifgrades 9 | guesses guess 10 | readme othercnt 11 | readme vowels 12 | 13 | Programs not listed above print output and do 14 | not read any input 15 | 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/data/add_item_data: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | 0-999-78345-X 3 20.00 4 | 0-201-78345-X 2 25.00 5 | y 6 | 0-201-78345-X 3 20.00 7 | 0-201-78345-X 2 25.00 8 | 0-999-78345-X 3 20.00 9 | 0-201-78345-X 2 25.00 10 | n 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/data/doWhile: -------------------------------------------------------------------------------- 1 | 10 42 2 | y 3 | 3 17 4 | n 5 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/data/grades: -------------------------------------------------------------------------------- 1 | 42 2 | 65 3 | 95 4 | 100 5 | 39 6 | 67 7 | 95 8 | 76 9 | 88 10 | 76 11 | 83 12 | 92 13 | 76 14 | 93 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/data/guesses: -------------------------------------------------------------------------------- 1 | 5 2 | 9 3 | 7 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/data/readme: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add_item_data add_item2 7 | vecSubs ifgrades 8 | readme othercnt 9 | readme vowels 10 | doWhile doWhile 11 | 12 | Programs not listed above print output and do 13 | not read any input 14 | 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = add_item2.exe doWhile.exe guess.exe ifgrades.exe \ 3 | othercnt.exe rangefor.exe vowels.exe 4 | 5 | # tells make to use the file "..\MS_makefile_template", which 6 | # defines general rules for making .obj and .exe files 7 | include ..\MS_makefile_template 8 | 9 | LOCFLAGS = /I..\1 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/5/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | add_item2 < data/add_item_data 3 | guess < data/guesses 4 | ifgrades < data/grades 5 | othercnt < data/readme 6 | vowels < data/readme 7 | doWhile < data/doWhile 8 | 9 | for %%i in ( rangefor.exe ) do %%i 10 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/LocalMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | // not included in book text, but used by programs in this directory 31 | #ifndef LOCALMATH_H 32 | #define LOCALMATH_H 33 | 34 | //definition in LocalMath.cc 35 | int fact(int); // iterative definition of factorial 36 | int factorial(int); // recrusive version of factorial 37 | int gcd(int, int); // find greatest common divisor 38 | #endif 39 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | mainmath mainmath 7 | refparms refparms 8 | 9 | Programs not listed above print output and do 10 | not read any input 11 | 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/count-calls.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | size_t count_calls() 37 | { 38 | static size_t ctr = 0; // value will persist across calls 39 | return ++ctr; 40 | } 41 | 42 | int main() 43 | { 44 | for (size_t i = 0; i != 10; ++i) 45 | cout << count_calls() << endl; 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/data/mainmath: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/data/refparms: -------------------------------------------------------------------------------- 1 | Hello World! 2 | 42 3 | 65 4 | 95 5 | 100 6 | 39 7 | 67 8 | 95 9 | 76 10 | 88 11 | 76 12 | 83 13 | 92 14 | 76 15 | 93 16 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/fact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | // declarations of our factorial functions 34 | // definitions are in LocalMath.cc 35 | #include "LocalMath.h" 36 | 37 | int main() 38 | { 39 | cout << factorial(5) << endl; 40 | cout << fact(5) << endl; 41 | cout << factorial(0) << endl; 42 | cout << fact(0) << endl; 43 | 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/good_printmain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | // const int ia[] is equivalent to const int* ia 37 | // size is passed explicitly and used to control access to elements of ia 38 | void print(const int ia[], size_t size) 39 | { 40 | for (size_t i = 0; i != size; ++i) { 41 | cout << ia[i] << endl; 42 | } 43 | } 44 | 45 | int main() 46 | { 47 | int j[] = { 0, 1 }; // int array of size 2 48 | 49 | print(j, sizeof(j)/sizeof(*j)); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/mainmath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "LocalMath.h" 31 | #include 32 | using std::cout; using std::endl; 33 | 34 | int main() 35 | { 36 | // pass a literal to fact 37 | int f = fact(5); // f equals 120, i.e., the result of fact(5) 38 | cout << "5! is " << f << endl; 39 | 40 | // call fact on i and print the result 41 | int i = 5; 42 | int j = fact(i); 43 | cout << i << "! is " << j << endl; 44 | 45 | // call fact on a const int 46 | const int ci = 3; 47 | int k = fact(ci); 48 | cout << ci << "! is " << k << endl; 49 | 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/mainret.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | /* EXIT_FAILURE and EXIT_SUCCESS are preprocessor variables 32 | * such variables are not in the std namespace, 33 | * hence, no using declaration and no std:: when we use these names 34 | */ 35 | int main() 36 | { 37 | bool some_failure = false; 38 | if (some_failure) 39 | return EXIT_FAILURE; // defined in cstdlib 40 | else 41 | return EXIT_SUCCESS; // defined in cstdlib 42 | } 43 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/make_plural.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include 37 | using std::cout; using std::endl; 38 | 39 | #ifndef MAKE_PLURAL_H 40 | #define MAKE_PLURAL_H 41 | 42 | // return the plural version of word if ctr is greater than 1 43 | inline 44 | string make_plural(size_t ctr, const string &word, 45 | const string &ending) 46 | { 47 | return (ctr > 1) ? word + ending : word; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = arrRet.exe count-calls.exe errMsg_initList.exe \ 3 | fact.exe fcnptrRet.exe good_printmain.exe \ 4 | inline_shorter.exe mainmath.exe mainret.exe \ 5 | mk_plural.exe ref-fcn.exe refparms.exe refret-ex.exe \ 6 | reset.exe stl-arr-fcns.exe usefcnptr.exe wdebug.exe 7 | 8 | # tells make to use the file "..\MS_makefile_template", which 9 | # defines general rules for making .obj and .exe files 10 | include ..\MS_makefile_template 11 | 12 | LOCFLAGS = 13 | 14 | fact.obj mainmath.obj LocalMath.obj: LocalMath.h 15 | 16 | fact.exe: fact.obj LocalMath.obj 17 | $(CPP) $(CPPFLAGS) fact.obj LocalMath.obj 18 | 19 | mainmath.exe: mainmath.obj LocalMath.obj 20 | $(CPP) $(CPPFLAGS) mainmath.obj LocalMath.obj 21 | 22 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/mk_plural.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include 37 | using std::cout; using std::endl; 38 | 39 | #include "make_plural.h" 40 | 41 | int main() 42 | { 43 | size_t cnt = 1; 44 | cout << make_plural(cnt, "success", "es") << endl; 45 | 46 | cnt = 2; 47 | cout << make_plural(cnt, "failure", "s") << endl; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/printFcns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #ifndef PRINTFCNS_H 31 | #define PRINTFCNS_H 32 | #include 33 | void print(const char *cp); 34 | void print(const int *beg, const int *end); 35 | void print(std::vector::const_iterator beg, 36 | std::vector::const_iterator end); 37 | void print(const int ia[], size_t size); 38 | void print(const std::vector&); 39 | 40 | inline foo() { 41 | int j[2] = {0,1}; 42 | print("Hello World"); // calls print(const char*) 43 | print(j, end(j) - begin(j)); // calls print(const int*, size_t) 44 | print(begin(j), end(j)); // calls print(const int*, const int*) 45 | #endif 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/ref-fcn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::string; 35 | 36 | char &get_val(string &str, string::size_type ix) 37 | { 38 | return str[ix]; // get_val assumes the given index is valid 39 | } 40 | 41 | int main() 42 | { 43 | string s("a value"); 44 | cout << s << endl; // prints a value 45 | 46 | get_val(s, 0) = 'A'; // changes s[0] to A 47 | cout << s << endl; // prints A value 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/refret-ex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | // get returns a reference to an element in the given array 34 | int &get(int *arry, int index) { return arry[index]; } 35 | 36 | int main() { 37 | int ia[10]; // array of ten uninitialized ints 38 | 39 | for (int i = 0; i != 10; ++i) 40 | get(ia, i) = i; // call get to assign values to the elements 41 | 42 | for (int i = 0; i != 10; ++i) // print the elements 43 | cout << ia[i] << " "; 44 | 45 | cout << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | mainmath < data/mainmath 3 | refparms < data/refparms 4 | 5 | for %%i in ( arrRet.exe count-calls.exe 6 | errMsg_initList.exe fact.exe fcnptrRet.exe 7 | good_printmain.exe inline_shorter.exe 8 | mainret.exe mk_plural.exe 9 | ref-fcn.exe refret-ex.exe reset.exe 10 | stl-arr-fcns.exe usefcnptr.exe wdebug.exe ) do %%i 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/6/use_mk_plural.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::size_t; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include 37 | using std::cout; using std::endl; 38 | 39 | // return the plural version of word if ctr is greater than 1 40 | string make_plural(size_t ctr, const string &word, 41 | const string &ending) 42 | { 43 | return (ctr > 1) ? word + ending : word; 44 | } 45 | 46 | int main() 47 | { 48 | size_t cnt = 1; 49 | cout << make_plural(cnt, "success", "es") << endl; 50 | cnt = 2; 51 | cout << make_plural(cnt, "failure", "s") << endl; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/Account.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include "Account.h" 34 | 35 | // define static data and function members 36 | const string Account::accountType("Savings Account"); 37 | double Account::interestRate = initRate(); 38 | 39 | void Account::rate(double newRate) 40 | { 41 | interestRate = newRate; 42 | } 43 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/Debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | // This file illustrates a literal class, which is a C++ 11 feature 31 | 32 | #include "Debug.h" 33 | // only implementation for the Debug classes are definitions 34 | // for static members named enable 35 | constexpr Debug HW_Subsystem::enable; 36 | constexpr Debug IO_Subsystem::enable; 37 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | book_sales avg_price 7 | add_item add_item 8 | 9 | Programs not listed above print output and do 10 | not read any input 11 | 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/add_item.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cerr; using std::cin; using std::cout; using std::endl; 32 | 33 | #include "Sales_data.h" 34 | 35 | int main() 36 | { 37 | Sales_data data1, data2; 38 | if (read(cin, data1) && read(cin, data2)) { // read the transactions 39 | if (data1.isbn() == data2.isbn()) { // check isbns 40 | data1.combine(data2); // add the transactions 41 | print(cout, data1); // print the results 42 | cout << endl; // followed by a newline 43 | } 44 | } else 45 | cerr << "Input failed!" << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/data/book_sales: -------------------------------------------------------------------------------- 1 | 0-201-70353-X 4 24.99 2 | 0-201-82470-1 4 45.39 3 | 0-201-88954-4 2 15.00 4 | 0-201-88954-4 5 12.00 5 | 0-201-88954-4 7 12.00 6 | 0-201-88954-4 2 12.00 7 | 0-399-82477-1 2 45.39 8 | 0-399-82477-1 3 45.39 9 | 0-201-78345-X 3 20.00 10 | 0-201-78345-X 2 25.00 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = add_item.exe avg_price.exe \ 3 | useAccount.exe useScreen.exe 4 | 5 | # the corresponding source file uses c++ 11 features 6 | C11_OBJECTS = useDebug.exe 7 | 8 | # tells make to use the file "..\MS_makefile_template", which 9 | # defines general rules for making .obj and .exe files 10 | include ..\MS_makefile_template 11 | 12 | LOCFLAGS = /I..\1 13 | 14 | useScreen.exe: Screen.h 15 | 16 | Account.obj useAccount.obj: Account.h 17 | Debug.obj useDebug.obj: Debug.h 18 | 19 | useAccount.exe: Account.obj useAccount.obj 20 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) useAccount.obj Account.obj 21 | 22 | useDebug.exe: Debug.obj useDebug.obj 23 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) useDebug.obj Debug.obj 24 | 25 | add_item.exe: add_item.obj Sales_data.obj 26 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) add_item.obj Sales_data.obj \ 27 | 28 | avg_price.exe: avg_price.obj Sales_data.obj 29 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) avg_price.obj Sales_data.obj \ 30 | 31 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | avg_price < data/book_sales 3 | add_item < data/add_item 4 | 5 | for %%i in ( useAccount.exe useScreen.exe ) do %%i 6 | 7 | REM c++ 11 files: 8 | REM useDebug.exe 9 | 10 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/7/useAccount.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::cout; using std::endl; 32 | 33 | #include 34 | using std::string; 35 | 36 | #include "Account.h" 37 | 38 | int main() 39 | { 40 | Account a1("bem", 42); 41 | cout << a1.balance() << endl; 42 | a1.calculate(); 43 | cout << a1.balance() << endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | add_item add_item 7 | add_item add_itemV2 8 | add_item fileio 9 | sstream sstream 10 | sstream fileio (Note, fileio reads both add_item and sstream) 11 | 12 | Programs not listed above print output and do 13 | not read any input 14 | 15 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/add_item.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Sales_data.h" 31 | #include 32 | 33 | using std::cerr; using std::cin; using std::cout; using std::endl; 34 | 35 | int main() 36 | { 37 | Sales_data data1, data2; 38 | read(cin, data1); // read the transactions 39 | read(cin, data2); 40 | // code to add into data1 and data2 unchanged from chapter 7 41 | if (data1.isbn() == data2.isbn()) { // check isbns 42 | Sales_data sum = add(data1, data2); // add the transactions 43 | print(cout, sum); // print the results 44 | cout << endl; // followed by a newline 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/add_itemV2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include "Sales_data.h" 31 | #include 32 | 33 | using std::cerr; using std::cin; using std::cout; using std::endl; 34 | 35 | int main() 36 | { 37 | Sales_data data1, data2; 38 | if (read(cin, data1) && read(cin, data2)) { // read the transactions 39 | if (data1.isbn() == data2.isbn()) { // check isbns 40 | Sales_data sum = add(data1, data2); // add the transactions 41 | print(cout, sum); // print the results 42 | cout << endl; // followed by a newline 43 | } 44 | } else 45 | cerr << "Input failed!" << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/data/add_item: -------------------------------------------------------------------------------- 1 | 0-201-78345-X 3 20.00 2 | 0-201-78345-X 2 25.00 3 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/data/sstream: -------------------------------------------------------------------------------- 1 | morgan 2015552368 8625550123 2 | drew 9735550130 3 | lee 6095550132 2015550175 8005550000 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = buf.exe clearIO.exe fileIO.exe add_item.exe \ 3 | add_itemV2.exe sstream.exe 4 | 5 | # tells make to use the file "..\MS_makefile_template", which 6 | # defines general rules for making .obj and .exe files 7 | include ..\MS_makefile_template 8 | 9 | LOCFLAGS = /I..\7 10 | 11 | add_itemV2.exe: add_itemV2.obj ..\7\Sales_data.obj 12 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) add_itemV2.obj ..\7\Sales_data.obj 13 | 14 | add_item.exe: add_item.obj ..\7\Sales_data.obj 15 | $(CPP) $(CPPFLAGS) $(LOCFLAGS) add_item.obj ..\7\Sales_data.obj 16 | 17 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/8/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | add_item < data/add_item 3 | add_itemV2 < data/add_item 4 | fileIO data/add_item data/sstream 5 | sstream < data/sstream 6 | 7 | for %%i in ( buf.exe clearIO.exe ) do %%i 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/README: -------------------------------------------------------------------------------- 1 | Some programs read cin for their input. 2 | Sample data files are in the data directory: 3 | 4 | File Programs that use that input file 5 | ---- -------- 6 | erase erase 7 | 8 | Programs not listed above print output and do 9 | not read any input 10 | 11 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/StrConvs.h: -------------------------------------------------------------------------------- 1 | #ifndef STRCONVS_H 2 | #define STRCONVS_H 3 | 4 | // Readers can ignore the implemnetations of to_string 5 | // but can use these functions in their code. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | // we use sprintf from stdio to implement to_string 12 | #include 13 | 14 | inline 15 | std::string to_string(int i) 16 | { 17 | char buf[100]; 18 | std::sprintf(buf, "%d", i); 19 | return buf; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/data/erase: -------------------------------------------------------------------------------- 1 | Esmeralda 2 | Frollo 3 | Hunckback 4 | Pierre 5 | Quasimodo 6 | Torterue 7 | Tristan 8 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/find-str.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. 3 | * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the 4 | * copyright and warranty notices given in that book: 5 | * 6 | * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." 7 | * 8 | * 9 | * "The authors and publisher have taken care in the preparation of this book, 10 | * but make no expressed or implied warranty of any kind and assume no 11 | * responsibility for errors or omissions. No liability is assumed for 12 | * incidental or consequential damages in connection with or arising out of the 13 | * use of the information or programs contained herein." 14 | * 15 | * Permission is granted for this code to be used for educational purposes in 16 | * association with the book, given proper citation if and when posted or 17 | * reproduced.Any commercial use of this code requires the explicit written 18 | * permission of the publisher, Addison-Wesley Professional, a division of 19 | * Pearson Education, Inc. Send your request for permission, stating clearly 20 | * what code you would like to use, and in what specific way, to the following 21 | * address: 22 | * 23 | * Pearson Education, Inc. 24 | * Rights and Permissions Department 25 | * One Lake Street 26 | * Upper Saddle River, NJ 07458 27 | * Fax: (201) 236-3290 28 | */ 29 | 30 | #include 31 | using std::string; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | int main() 37 | { 38 | string name("AnnaBelle"); 39 | string::size_type pos1 = name.find("Anna"); // pos1 == 0 40 | cout << pos1 ; 41 | string lowercase("annabelle"); 42 | pos1 = lowercase.find("Anna"); // pos1 == npos 43 | cout << " " << pos1 << endl; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/makefile: -------------------------------------------------------------------------------- 1 | # executable files for this directory 2 | OBJECTS = capacity.exe erase1.exe erase2.exe find_ops.exe \ 3 | find-str.exe refreshIter.exe stack.exe \ 4 | str_assignOps.exe substr.exe useConvs.exe 5 | 6 | # tells make to use the file "..\MS_makefile_template", which 7 | # defines general rules for making .obj and .exe files 8 | include ..\MS_makefile_template 9 | 10 | LOCFLAGS = /I..\7 11 | 12 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/9/runpgms.bat: -------------------------------------------------------------------------------- 1 | echo on 2 | erase1 31 | using std::string; 32 | 33 | #include 34 | using std::cout; using std::endl; 35 | 36 | #include 37 | using std::out_of_range; 38 | 39 | int main() 40 | { 41 | try { 42 | string s("hello world"); 43 | cout << s.substr(0, 5) << endl; // prints hello 44 | cout << s.substr(6) << endl; // prints world 45 | cout << s.substr(6, 11) << endl; // prints world 46 | cout << s.substr(12) << endl; // throws out_of_range 47 | } catch(out_of_range) {cout << "caught out_of_range" << endl; } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/CompilerNotes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xaxfan/Cpp_Primer_5th/9b2de2a6ccd1833d9e96510cfbd89c859fd05844/C++Primer第五版课本源代码/CompilerNotes.pdf -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xaxfan/Cpp_Primer_5th/9b2de2a6ccd1833d9e96510cfbd89c859fd05844/C++Primer第五版课本源代码/README.pdf -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/makefile: -------------------------------------------------------------------------------- 1 | DIRS = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 | 3 | all: 4 | cd 1 && nmake 5 | cd 2 && nmake 6 | cd 3 && nmake 7 | cd 4 && nmake 8 | cd 5 && nmake 9 | cd 6 && nmake 10 | cd 7 && nmake 11 | cd 8 && nmake 12 | cd 9 && nmake 13 | cd 10 && nmake 14 | cd 11 && nmake 15 | cd 12 && nmake 16 | cd 13 && nmake 17 | cd 14 && nmake 18 | cd 15 && nmake 19 | cd 16 && nmake 20 | cd 17 && nmake 21 | cd 18 && nmake 22 | cd 19 && nmake 23 | 24 | clean: 25 | cd 1 && nmake clean 26 | cd 2 && nmake clean 27 | cd 3 && nmake clean 28 | cd 4 && nmake clean 29 | cd 5 && nmake clean 30 | cd 6 && nmake clean 31 | cd 7 && nmake clean 32 | cd 8 && nmake clean 33 | cd 9 && nmake clean 34 | cd 10 && nmake clean 35 | cd 11 && nmake clean 36 | cd 12 && nmake clean 37 | cd 13 && nmake clean 38 | cd 14 && nmake clean 39 | cd 15 && nmake clean 40 | cd 16 && nmake clean 41 | cd 17 && nmake clean 42 | cd 18 && nmake clean 43 | cd 19 && nmake clean 44 | 45 | clobber: 46 | cd 1 && nmake clobber 47 | cd 2 && nmake clobber 48 | cd 3 && nmake clobber 49 | cd 4 && nmake clobber 50 | cd 5 && nmake clobber 51 | cd 6 && nmake clobber 52 | cd 7 && nmake clobber 53 | cd 8 && nmake clobber 54 | cd 9 && nmake clobber 55 | cd 10 && nmake clobber 56 | cd 11 && nmake clobber 57 | cd 12 && nmake clobber 58 | cd 13 && nmake clobber 59 | cd 14 && nmake clobber 60 | cd 15 && nmake clobber 61 | cd 16 && nmake clobber 62 | cd 17 && nmake clobber 63 | cd 18 && nmake clobber 64 | cd 19 && nmake clobber 65 | 66 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/runp.bat: -------------------------------------------------------------------------------- 1 | cd %1 2 | call runpgms 3 | cd .. 4 | -------------------------------------------------------------------------------- /C++Primer第五版课本源代码/runpgms.bat: -------------------------------------------------------------------------------- 1 | for %%i in ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ) do runp %%i 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 书籍请移步网盘 2 | 3 | * [C++ Primer中文版(第五版)](https://pan.baidu.com/s/1i48my3b) 4 | 5 | * [C++primer第五版(英文版)](https://pan.baidu.com/s/1nvuhuit) 6 | 7 | * [C++ Primer习题集 第5版](https://pan.baidu.com/s/1eSqrQlO) 8 | --------------------------------------------------------------------------------