Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 43c0243361afd629be91f5482e487e44c602bef8 @bitsai committed Aug 24, 2010
Showing 538 changed files with 32,320 additions and 0 deletions.
@@ -0,0 +1,82 @@
+The files in this directory and its associated subdirectories contain
+the source code from the book ``Accelerated C++: Practical Programming
+by Example'' by Andrew Koenig and Barbara E. Moo (Addison-Wesley 2000,
+ISBN 0-201-70353-X). They are mechanically extracted from the files
+that are used to produce the book. Accordingly, they should match the
+book exactly--specifically, the fifth printing, which isn't out
+yet--except for some deliberate changes that are needed to deal with
+the realities of running C++ programs.
+
+We have compiled and run these files on two different compilers:
+
+ The GNU ``g++'' compiler, version 2.95.2, under both
+ the Solaris operating system and Microsoft Windows,
+ the latter under the Cygwin programming environment
+ available from http://sources.redhat.com/cygwin
+
+ The Microsoft Visual C++ compiler, version 6.0, with
+ Service Pack 4 installed.
+
+In order to run these files under these compilers, we have had to
+change them slightly from what appears in the book. In all cases, we
+have identified these changes with #ifdef directives of the form
+
+ #ifdef __GNUC__
+ code that will work under the g++ compiler
+ #else
+ code as it appears in the book
+ #endif
+
+or
+ #ifdef _MSC_VER
+ code that will work under the Microsoft compiler
+ #else
+ code as it appears in the book
+ #endif
+
+or variations on this theme.
+
+In addition, we have added main programs, test data, and makefiles to
+enable you to compile and run the code.
+
+For each chapter in the book, there is a corresponding directory that
+contains the source code from that chapter. Assuming that your
+system is configured correctly, you should be able to go into any of
+these directories and say
+
+ make
+
+to compile the programs,
+
+ make test
+
+to execute them, and
+
+ make clobber
+
+to remove all the files that were generated during compilation.
+
+
+
+All of the files in these directories are copyrighted by AT&T and
+Barbara E. Moo, and they come with absolutely no warranty whatsoever.
+Permission is hereby granted to use these programs for educational
+purposes.
+
+We would like to know about errors in these files and suggestions for
+making them easier to use with other compilers.
+
+
+
+
+
+
+ Regards,
+
+
+ Andrew Koenig
+ ark@research.att.com
+
+
+ Barbara E. Moo
+ bmoo@att.net
@@ -0,0 +1,21 @@
+#include <iostream>
+
+int
+main
+(
+)
+{
+std
+::
+cout
+<<
+"Hello, world!"
+<<
+std
+::
+endl
+;
+return
+0
+;
+}
@@ -0,0 +1,8 @@
+#include <iostream>
+
+int main() {
+ std::cout << "This (\") is a quote, and this (\\) is a backslash."
+ << std::endl;
+
+ return 0;
+}
@@ -0,0 +1,16 @@
+#include <iostream>
+
+int main() {
+ std::cout <<
+ "// a small C++ program\n"
+ "#include <iostream>\n"
+ "\n"
+ "int main()\n"
+ "{\n"
+ "\tstd::cout << \"Hello, world!\" << std::endl;\n"
+ "\treturn 0;\n"
+ "}" <<
+ std::endl;
+
+ return 0;
+}
@@ -0,0 +1 @@
+int main(){}
@@ -0,0 +1,8 @@
+// a small C++ program
+#include <iostream>
+
+int main() {
+ std::cout << "Hello, world!" << std::endl;
+
+ return 0;
+}
@@ -0,0 +1,10 @@
+CXX = g++
+CC = g++
+
+all: hello
+
+test: all
+ ./hello
+
+clobber:
+ rm -f *.o core *.exe hello
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <string>
+
+int main() {
+ std::cout << "What is your name? ";
+ std::string name;
+ std::cin >> name;
+ std::cout << "Hello, " << name
+ << std::endl << "And what is yours? ";
+ std::cin >> name;
+ std::cout << "Hello, " << name
+ << "; nice to meet you too!" << std::endl;
+
+ return 0;
+}
@@ -0,0 +1,29 @@
+// ask for a person's name, and generate a framed greeting
+#include <iostream>
+#include <string>
+
+int main() {
+ std::cout << "Please enter your first name: ";
+ std::string name;
+ std::cin >> name;
+
+ // build the message that we intend to write
+ const std::string greeting = "Hello, " + name + "!";
+
+ // build the second and fourth lines of the output
+ const std::string spaces(greeting.size(), ' ');
+ const std::string second = "* " + spaces + " *";
+
+ // build the first and fifth lines of the output
+ const std::string first(second.size(), '*');
+
+ // write it all
+ std::cout << std::endl;
+ std::cout << first << std::endl;
+ std::cout << second << std::endl;
+ std::cout << "* " << greeting << " *" << std::endl;
+ std::cout << second << std::endl;
+ std::cout << first << std::endl;
+
+ return 0;
+}
@@ -0,0 +1,17 @@
+// ask for a person's name, and greet the person
+#include <iostream>
+#include <string>
+
+int main() {
+ // ask for the person's name
+ std::cout << "Please enter your first name: ";
+
+ // read the name
+ std::string name; // define `name'
+ std::cin >> name; // read into `name'
+
+ // write a greeting
+ std::cout << "Hello, " << name << "!" << std::endl;
+
+ return 0;
+}
@@ -0,0 +1,11 @@
+CXX = g++
+CC = g++
+
+all: frame greet
+
+test: all
+ ./greet <../data/name1
+ ./frame <../data/name2
+
+clobber:
+ rm -f *.o *.exe core frame greet
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <string>
+
+// say what standard-library names we use
+using std::cin; using std::endl;
+using std::cout; using std::string;
+
+int main() {
+ // ask for the person's name
+ cout << "Please enter your first name: ";
+
+ // read the name
+ string name;
+ cin >> name;
+
+ // build the message that we intend to write
+ const string greeting = "Hello, " + name + "!";
+
+ // the number of blanks surrounding the greeting
+ const int pad = 0;
+
+ // the number of rows and columns to write
+ const int rows = pad * 2 + 3;
+ const string::size_type cols = greeting.size() + pad * 2 + 2;
+
+ // write a blank line to separate the output from the input
+ cout << endl;
+
+ // write `rows' rows of output
+ // invariant: we have written `r' rows so far
+ for (int r = 0; r != rows; ++r) {
+ string::size_type c = 0;
+
+ // invariant: we have written `c' characters so far in the current row
+ while (c != cols) {
+ // is it time to write the greeting?
+ if (r == pad + 1 && c == pad + 1) {
+ cout << greeting;
+ c += greeting.size();
+ } else {
+ // are we on the border?
+ if (r == 0 || r == rows - 1 ||
+ c == 0 || c == cols - 1)
+ cout << "*";
+ else
+ cout << " ";
+ ++c;
+ }
+ }
+
+ cout << endl;
+ }
+
+ return 0;
+}
+
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <string>
+
+// say what standard-library names we use
+using std::cin; using std::endl;
+using std::cout; using std::string;
+
+int main() {
+ // ask for the person's name
+ cout << "Please enter your first name: ";
+
+ // read the name
+ string name;
+ cin >> name;
+
+ // build the message that we intend to write
+ const string greeting = "Hello, " + name + "!";
+
+ // the number of blanks surrounding the greeting
+ const int h_pad = 1;
+ const int v_pad = 2;
+
+ // the number of rows and columns to write
+ const int rows = v_pad * 2 + 3;
+ const string::size_type cols = greeting.size() + h_pad * 2 + 2;
+
+ // write a blank line to separate the output from the input
+ cout << endl;
+
+ // write `rows' rows of output
+ // invariant: we have written `r' rows so far
+ for (int r = 0; r != rows; ++r) {
+ string::size_type c = 0;
+
+ // invariant: we have written `c' characters so far in the current row
+ while (c != cols) {
+ // is it time to write the greeting?
+ if (r == v_pad + 1 && c == h_pad + 1) {
+ cout << greeting;
+ c += greeting.size();
+ } else {
+ // are we on the border?
+ if (r == 0 || r == rows - 1 ||
+ c == 0 || c == cols - 1)
+ cout << "*";
+ else
+ cout << " ";
+ ++c;
+ }
+ }
+
+ cout << endl;
+ }
+
+ return 0;
+}
Oops, something went wrong.

0 comments on commit 43c0243

Please sign in to comment.