March 24, 1999 LAWRENCEVILLE PRESS LIBRARIES The Lawrenceville Press libraries needed by most of the programs presented in A Guide to Programming in C++ have been modified to work with CodeWarrior version 3.3. In order for programs to have access to these library files, copy the library files to your compiler's INCLUDE folder in the compiler's root directory. For example, for CodeWarrior version 3.3, the directory structure may appear similar to: hard drive:Metrowerks:Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C++:Include IMPORTANT************************************************************************************* The lvp libraries are functionally equivalent to the AP libraries. Therefore, the lvp libraries are updated when the AP libraries are updated. To insure that you are using the most up-to-date libraries, please periodically download the library files from the Lawrenceville Press web site by going to http://www.lvp.com, clicking on the Download Files button, scrolling to the bottom of the download files pages, and then clicking on the appropriate link. To create a project and run an existing program, such as a program on the master diskettes, use the following instructions: 1. Start CodeWarrior. 2. From the File menu, select the New Project command. 3. Select MACOS/C_C++/Standard Console/Std C++ Console 68K or Std C++ Console PPC and then OK. 4. Enter a descriptive name for the new project in the Name new project as dialog box and then select Save. This will create a template project that contains source files, ANSI Library files, and Mac library files. The example source file is HelloWorld.cp. 5. Click on HelloWorld.cp under Sources to select it. 6. From the Project menu, select the Remove Selected Items command to remove the file. 7. Click on Sources to select it. 8. From the Project menu, select the Add Files command. 9. Select the appropriate C++ file. 10. From the Project menu, select the Run command to compile, link, and run the program. To create a new project and create and run a new program, use the instructions above substituting steps 7 through 10 for the ones below: 6. From the File menu, select the New command. 7. Create the program. 8. From the File menu, select the Save command. Select the appropriate folder and save it using a descriptive name. 9. Click on Sources to select it. 10. From the Project menu, select the Add Files command. 11. Select the C++ file you just created. 12. From the Project menu, select the Run command to compile, link, and run the program. The programs in Chapter Six that use the college library require the colleges.txt file. This file is stored in the TEXT folder on master diskette 3. Many of the programs in Chapter Nine require text (.txt or .dat) files. These files are stored in the TEXT folder on master diskette 3. Data files need to be copied from the master diskette to the project folder on the hard disk for the project which is using the data file. The library files have been modified to operate with CodeWarrior version 3.3. Due to these changes and differences in CodeWarrior, the following modifications need to be made to all programs that use the libraries provided by Lawrenceville Press: #include Because the library files are copied directly to the Include folder and not placed in a lvp subfolder, the lvp directory path in any include statements needs to be deleted. string.h Because CodeWarrior also has a string library file, the library files string.h and string.cpp have been renamed lvpstring.h and lvpstring.cpp. Any programs that use the string.h library needs to be modified so that the include statement reads #include . Also, in every program that uses the lvpstring library, the String class needs to be modified so that it reads lvpstring. The easiest way to do this is to use the Find command from the Search menu. vector.h Because CodeWarrior also has a vector library file, the library files vector.h and vector.cpp have been renamed lvpvector.h and lvpvector.cpp. Any programs that use the vector.h library needs to be modified so that the include statement reads #include . Also, in every program that uses the lvpvector library, the vector class needs to be modified so that it reads lvpvector. The easiest way to do this is to use the Find command from the Search menu. random.h Because CodeWarrior also has a random library file, the library files random.h has been renamed lvprandom.h. Any programs that use the random.h library needs to be modified so that the include statement reads #include . Also, in every program that uses the lvprandom library, the random(...) statement needs to be modified so that it reads lvprandom(...). The easiest way to do this is to use the Find command from the Search menu. stack.h Because CodeWarrior also has a stack library file, the library files stack.h and stack.cpp have been renamed lvpstack.h and lvpstack.cpp. Any programs that use the stack.h library needs to be modified so that the include statement reads #include . Also, in every program that uses the lvpstack library, the stack class needs to be modified so that it reads lvpstack. The easiest way to do this is to use the Find command from the Search menu. queue.h Because CodeWarrior also has a queue library file, the library files queue.h and queue.cpp have been renamed lvpqueue.h and lvpqueue.cpp. Any programs that use the queue.h library needs to be modified so that the include statement reads #include . Also, in every program that uses the lvpqueue library, the queue class needs to be modified so that it reads lvpqueue. The easiest way to do this is to use the Find command from the Search menu. bool.h Because CodeWarrior also have a bool library, the bool.h and bool.cpp library files are not included. Also, the #include statement needs to be commented out of all programs that it is in. conio.h Because CodeWarrior does not support conio.h, the #include statement needs to be commented out of all programs that it is in. The PROGS_CW folder on this diskette correspond to the programs presented in the text. The programs have been given descriptive names according to their opening comments. Some of the programs have been modified to run under CodeWarrior as noted below: sturecs.cpp Because CodeWarrior does not support conio.h, the line of code in main() that reads char Choice = getche(); in the text has been changed to the lines char Choice; cin >> Choice; in the program on diskette. case3.cpp The iostream library included with CodeWarrior requires a call to unsetf() in order to change alignment of output, as stated in Appendix B of A Guide to Programming in C++. Therefore, the line cout.unsetf(ios::left); was added prior to every line that reads cout.setf(ios::right); and the line cout.unsetf(ios::right); was added prior to every line that reads cout.setf(ios::left). Five of these lines were added to case3.cpp. case6 Because of a change in a library file, the line of code in main() that reads EnrollmentList.Clear(); has been changed to EnrollmentList.ClearData(); The iostream library included with CodeWarrior requires a call to unsetf() in order to change alignment of output, as stated in Appendix B of A Guide to Programming in C++. Therefore, the line cout.unsetf(ios::left); was added prior to every line that reads cout.setf(ios::right); and the line cout.unsetf(ios::right); was added prior to every line that reads cout.setf(ios::left). Two of these lines were added to case6.cpp. case7.cpp Because CodeWarrior does not support conio.h, clrscr() was commented out in main(). case8.cpp The iostream library included with CodeWarrior requires a call to unsetf() in order to change alignment of output, as stated in Appendix B of A Guide to Programming in C++. Therefore, the line cout.unsetf(ios::left); was added prior to every line that reads cout.setf(ios::right); and the line cout.unsetf(ios::right); was added prior to every line that reads cout.setf(ios::left). Two of these lines were added to case8.cpp. case9.cpp Because CodeWarrior does not support conio.h, the two lines of code that read Choice = getche(); cout << endl; needed to be changed to cin >> Choice; cin.ignore(80, '\n'); The cin.ignore() function is needed because getline() will read the end of line character that is still in the stream. Refer to Chapter Three (p. 3-11). This change was made in ChangeBook() and main(). The lines of code in the NumRecords() function have been changed to: { streampos Position; F.seekp(0, ios::end); Position = F.tellp(); if (Position.offset()==0) { return(0); } else return(1+Position.offset()/MaxRecSize); } The line of code in main() that reads: fstream BookFile("BookData.txt", ios::in | ios::out); has been changed to the following lines of code: fstream CheckFileExist; CheckFileExist.open("BookData.txt", ios::in | ios::out); if (CheckFileExist.fail()) { ofstream CreateFile("BookData.txt"); CreateFile.close(); } CheckFileExist.close(); fstream BookFile; BookFile.open("BookData.txt", ios::in | ios::out); case10.cpp Because CodeWarrior does not support conio.h, the lines of code above the case statement that read Choice = getche(); cout << endl; needed to be changed to cin >> Choice; cin.ignore(80, '\n'); The cin.ignore() function is needed because getline() will read the end of line character that is still in the stream. Refer to Chapter Three (p. 3-11.) The line of code in the beginning of main() that reads fstream BankData; needed to be deleted. The line of code in the beginning of main() that reads BankData.open("Bankdata.dat",ios::in); has been changed so that it reads ifstream BankData("bankdata.dat");. Change the line of code in the end of main() that reads BankData.open("bankdata.dat",ios::out); so that it reads ofstream BankDataOut("bankdata.dat"); and BankData in the following lines of code has been changed to BankDataOut: BankData << NumAccounts << endl; Bank[AcctNum].Store(BankData); BankData.close(); utility.h Because CodeWarrior does not support conio.h, the #include statement has been commented out. Because CodeWarrior does not support getch(), the lines of code in Pause() needed to be changed to: char choice; cout << "Press a key and then Return to continue"; cin >> choice; //Pause for the user to hit a key and then Return cout << endl; hanoir.cpp Because CodeWarrior does not support getch(), the line of code in Hanoi() that reads getch() needed to be changed to Pause(). When using files and steams: * ifstream does not create a file if it does not exist * ofstream does create a file if it does not exist * fstream does not create a file if it does not exist and open() needs to be used to check if the file exists * CodeWarrior does not support nocreate * to find the number of characters in a file, use the following instead of the code in section 9.14: streampos Position; MyFile.seekg(0,ios::end); Position = MyFile.tellg(); cout << Position.offset(); readfile.cpp Because CodeWarrior does not support nocreate, the line of code in main() that reads ifstream InFile("ask-not.txt", ios::nocreate); has been changed to ifstream InFile("ask-not.txt"); readscor.cpp Because CodeWarrior does not support nocreate, the line of code in main() that reads ifstream InFile("scores.dat", ios::nocreate); has been changed to ifstream InFile("scores.dat"); readchar.cpp Because CodeWarrior does not support nocreate, the line of code in main() that reads ifstream InFile("quick.txt", ios::nocreate); has been changed to ifstream InFile("quick.txt"); filestat.cpp Because CodeWarrior does not support nocreate, the line of code in main() that reads InFile.open(FileName.c_str(),ios::nocreate); has been changed to InFile.open(FileName.c_str());. The line of code in main() that reads ifstream InFile; has been moved to before the line of code that reads InFile.open(FileName.c_str());. rwfile.cpp The line of code in main() that reads fstream MyFile("composer.txt", ios::in | ios::out); has been changed to: fstream MyFile; MyFile.open("composer.txt",ios::in | ios::out); doodle.cpp Because CodeWarrior does not support conio.h, the doodle program will not run in CodeWarrior and therefore is not included in the PROGS_CW folder. Chapter Eleven programs Because chapter 11 was written for the Windows environment, none of the Chapter Eleven programs will work with CodeWarrior. The GUI_BOT.h and GUI_TOP.h library files are therefore not included. stopwatc.h Because stopwatc.h was written for the Windows environment, it will not work with CodeWarrior programs. TECHNICAL SUPPORT Lawrenceville Press Technical Support (561) 451-2051 phone 9 a.m. to 5 p.m. EST (561) 488-4436 fax 24 hours cpphelp@lvp.com