CS-1030 Software Design 2
Lab 2: Multi-module application

Objectives

Assignment

This is a 1-week lab.

Create an application that accepts a line of arbitrary alphanumeric text as input, and stores that text internally in a string object. Using methods  from the C++ string class, have your program examine each of the tokens within the string (tokens are groups of characters separated by whitespace, and not including the whitespace). Below the originally input string, have your program print one or more of the following results:

  1. the number of non-alphanumeric characters found in each token directly under the token.
  2. the number of alphabetic characters found in each token directly under the token
  3. the number of numeric characters found in each token directly under the token
  4. the number of individual tokens found within the input string

As an example, your program should produce output similar to the following when all three results are printed:

Enter some text: This is some input to a C++ program for CS-1030.
Non-alphanumeric    0  0    0     0  0 0   2       0   0        2
Alphabetic:         4  2    4     5  2 1   1       7   3        2
Numeric:            0  0    0     0  0 0   0       0   0        4
The input contains 10 tokens.
 

You'll have to do some reading on the string class and related functions to figure out how to count the various characters - there are library functions available that make this rather easy. Note that even though you are writing a program that implements no classes of your own, you can still use any class (or global function) available to you from the C++ class libraries. It might be a little tricky to print the results formatted as shown - you'll have to determine the length of each token in order to adjust output formatting.

You are to use conditional compilation (rather than conditional logic) in order to change the behavior of your program; that is, whether it prints all three lines of output, or only just one or two. Use the preprocessor directives (#ifdef, #if, #define, etc) you learned about in lecture, and use them to conditionally compile the code which outputs each result. When a preprocessor constant STANDARD is #defined, your program should generate the first line of output; when the constant DELUXE is #defined, the second line of output should be generated; when the constant PREMIUM is #defined, the third line of output should be generated. Depending on which constants are #defined, your program should conditionally compile to produce different combinations of results. For example, when both STANDARD and PREMIUM are both #defined, then the output should include both the Non-alphanumeric and Numeric results.

The fourth line of output (that reports the total number of tokens in the input string) should always be produced and not conditionally compiled.

Derive the syntax for your preprocessor directives from what was demonstrated to you in lecture (there is sample code posted on the course schedule page).

Implement this program in multiple source modules, as illustrated in the UML-like diagram below. Here, the main() function resides in a source file called lab2.cpp. The implementation for the functions getUserInput and printOutput resides in a second source file named lab2io.cpp. The functions that analyze the input text and the tokens that comprise the input are in a third source file named lab2analyzer.cpp.

Use header (.h) files when necessary for external function and variable declarations, and use the C++ preprocessor's #include directive to include those header files where necessary. By convention, the functions and variables defined in a .cpp have their corresponding definitions in a .h file with the same base filename. For example, lab2io.h should contain the declarations for those functions (and only those functions) implemented within lab2io.cpp. You can, however, place all declarations in a single lab2.h file if you wish.

Once you have this program working, demonstrate it to your instructor. 

Lab Report (due 11:00pm, the day before Lab 3 begins)

This program  should be completed within the lab period.
If you cannot complete it, then you'll have to submit a complete Lab Report
.

Use this Word document as a template for your report.

Submit your assignment following these instructions:
  1. Navigate to your VS .NET project directory (see this note on configuring the workspace).
  2. You should have a subdirectory under your VS .NET project directory with the name of the project you used for this lab. 
  3. Upload your submission through WebCT (assignment "Lab 2"), selecting only the .cpp, .h, .sln, .vcproj, and .doc files from this directory. Upload each file separately; do not zip files.
  4. Enter the overall time you spent on this lab into the FAST system (for week 2).
Be sure to keep copies of all your files, in case something gets lost.

Program quality

Report quality