[ Viewing Hints ] [ Book Home Page ] [ Free Newsletter ] [ Seminars ] [ Seminars on CD ROM ] [ Consulting ] Annotated Solution Guide Revision 1.0 for Thinking in C++, 2nd edition, Volume 1by Chuck Allison ? 2001 MindView, Inc. All Rights Reserved.[ Previous Chapter ] [ Table of Contents ] [ Next Chapter ] Chapter 77-1Create a Text class that contains a string object to hold the text of a file. Give it two constructors: a default constructor and a constructor that takes a string argument that is the name of the file to open. When the second constructor is used, open the file and read the contents into the stringmember object. Add a member function contents( ) to return the string so (for example) it can be printed. In main( ) , open a file using Text and print the contents. Solution://: S07:Text.cpp#include #include #include using namespace std; class Text { string text; public: Text() {} Text(const string& fname) { ifstream ifs(fname.c_str()); string line; while (getline(ifs, line)) text += line + '\n'; } string contents() { return text; } }; int main(int argc, char* argv[]) { if (argc > 1) { Text t1; Text t2(argv[1]); cout << "t1 :\n" << t1.contents() << endl; cout << "t2 :\n" << t2.contents() << endl; } } ///:~When creating a Text object, the compiler guarantees that the text data member has its default constructor (string::string( )) executed before either Text constructor runs, hence the default Textconstructor just builds an empty string. This program prints an empty string for t1 followed by the contents of the file named in the first command-line argument. Note the use of string::c_str( ) in the second constructor. That’ s because the ifstr...