Programming Assignment 1

This assignment is due Tuesday, September 9, by the start of class.

Write a program that does the following:

  1. Prompt the user to enter a file name for input.

  2. Open the specified file. If the file doesn't exist, print an error message and exit the program.

  3. Read in all the words from the input file. You may assume that there are no more than 250 words in the file.

    You may also assume that a ``word'' is a contiguous group of non-white space characters. This sounds complicated, but is really not. For example, in the previous sentence, not. would be a word, as would "word" in the sentence before that--note the inclusion of the period and the quotation marks.

  4. Sort the set of words into alphabetical order. Remember that alphabetical order in C++ means that capital words come first, then non-capitalized, etc. Keep in mind that you can compare strings using the same comparison operators (<, >, etc.) that you use with numbers.

  5. Prompt the user to enter a file name for output.

  6. Write the words, in alphabetical order, to the output file.

Place the work for this assignment in your personal I:\CSC122 folder in a folder called HW1. See below for how to create a project from scratch - call the project hw1.ide. Turn in a printout of this assignment on the due date in class. There is a file called sample.txt in the public\Thede folder that you can use to test your program.

There are a number of topics that will be useful for the assignment:

You may want to brush up on these, either with your CS1 books or Appendix A in the textbook.

Creating a Borland C++ Project from Scratch

From the File menu, choose Project... out of the New submenu. The ``New Target'' dialog box will appear. Enter the correct project path and name in the first text box; for this assignment, you would enter I:\CSC122\YourName\HW1\hw1.ide. Make sure that ``Application [.exe]'' is selected under ``Target Type,'' and that the ``Platform'' and ``Target Model'' are ``Win32'' and ``Console'' (it will probably default to ``GUI,'' so you will need to be sure this gets changed). Now click the ``Advanced'' button and uncheck the boxes labeled .rc and .def, then click ``OK'' twice to make each dialog go away. Finally, double-click the .cpp node in the project window that appears and you will get an editor window where you can start entering your program.

To attach additional source files to a project, choose File/New/TextEdit and then File/Save as... from the menu. Give your file an appropriate name in the ``Save File'' dialog and click ``OK.'' Now, in the project window, right-click on the .exe node (at the top) and choose ``Add node'' from the context menu. This will bring up a file chooser; select the new file you just created and click ``OK.'' The next time you build the project, this new file will be compiled in with the rest of the program.