CSSE 120 — Intro. to Software Development

Final C Project — Ascii Art

Overview

You will create a menu-driven system that can display and transform ASCII art and read and write ASCII art data files.

This is an individual project. We want everyone to keep practicing their C programming so you do well on the final exam!

Your work for this project should be done in the AsciiArtPart2 project that you can check out from your individual or pair SVN repository.

Sample Input and Output

The main menu should look something like:

1. Change the base filename.
2. Change the number of rows and columns to use (optional).
3. Load a coordinate file.
4. Load an image file.
5. Display the image on the console.
6. Save a coordinate file.
7. Save an image file.
8. Transform the data by ...
(possibly more transformations here)
99. Exit
Enter your choice now: 

Note that you already completed options 3 and 8 in part 1 of this project.

Ideas for Transformations

  1. Replace one set of letters with another set of letters, hardcoding the sets as strings.
  2. Translation (shift image by a number of rows and columns specified by the user).
  3. Reflection (mutating matrix so that the image is mirrored. Could mirror vertically, horizontally, even diagonally).
  4. Rotation (rotate the matrix by a multiple of 90 degrees).
  5. Scale (for example, double size the image, so the upper-left 50x50 expends to fill entire image, with each letter becoming a 2x2 block of letters).

How to Create Images Using Eclipse's Text Editor

  1. Images must be exactly 100x100 (unless you allow for variables sizes, see below).
  2. Make a copy of the blank.txt file
  3. Show whitespace so you can see that all rows have the right number of spaces. Windows > Preferences > General > Editors > Text Editors:

  4. Press insert key on keyboard to go into OVERWRITE (vs insert) mode. Your cursor will change from a flashing line to a flashing block. Type your pic. If it's small, put it roughly in the upper-left corner of the matrix.
  5. Some text editors allow you to select a vertical block of text for copy-paste, which can be pretty handy. For example, in Notepad++ (which is available for free online), just hold down the alt key while you move the mouse.

Other Requirements

It is not enough to just get the program to work!

Programming style will also affect your grade. An A or B program will use functions correctly, willl have well-named variables and functions, and will avoid global variables and magic numbers. 

Grading: 100 points total

Basic features (70 points; get these working first):

  1. (5) Allows the user to input the basename.
  2. (5) Reads in a coordinate file
  3. (15) Read in an image file
  4. (10) Writes a coordinate file
  5. (5) Writes an image file
  6. (5) Menu works appropriately in a loop, exiting when specified.
  7. (5) The code has appropriate documentation (comments).
  8. (10) The code uses appropriate style regarding: variable names, breakdown into functions and structures, indenting, use of white space, and so forth.
  9. (10) Allows the user to transform the matrix in any one of the ways specified above.

Intermediate features (20-35 points)

  1. (10) Allows the user to transform the matrix in a second of the ways specified above.
  2. (10-25) Adds one other function to your code. A third transformation from the list above would earn you 10 points (and thus a total of 90 points). A totally different kind of transformation could earn you 15-25 points depending on how challenging and creative it is. I'm pretty flexible, but feel free to ask me.
    1. One "interesting" (= 25 points) new function to your code is to deal with images that have dimensions other than 100x100. Input files, whether coordinates or image data, will start with the number of rows and columns, which must each be less than SIZE. Look at the data files named "withSize" for examples. You must store the size in a struct. You may continue to declare your matrix as 100x100, and leave some part of it unused. But I'm requiring you to store and pass around the dimensions in a struct, not two separate parameters and not as global variables. You must implement option 2 in the sample menu and experiment with data files that are non-100x100. Hint: structs in C are like ints: you can return them, but you can't mutate them unless you use a pointer to one (which shouldn't be necessary in this program, just return it if needed).

 

Suggestions for C Projects —Read and Obey These! You'll be sorry if you don't!

Iterative enhancement

This is critical: For the rest of your coding, identify one TEENY additional functionality that seems right to do next. Implement and test. Don't proceed until you get that teeny functionality working.

  • The key is testing as you go. Work through the problem in an order than helps you accomplish that.
  • Gotcha's

    As you have seen, the hard part of C is avoiding mistakes. Once you make a mistake, it is often time-consuming to track down the error.
    So try to avoid these common mistakes:

    1. Abusing scanf.
    2. Abusing printf. Likewise, make sure that printf has exactly as many variables to be set as there are % signs in the format string, and that the types match.
    3. Mixing scanf with other input functions. Don't, unless you know what you are doing. Instead, stick to scanf (and fscanf for reading from a file).
    4. Launching with errors. Never run the program if you see compiler error-messages. If you see:
          Errors exist in a required project.  Continue launch?
      
      always respond No. If you see a little asterisk by the name of the file on the tab in the Editor, that means that file has not been saved. Never run unless it has been saved (for most of you, running asks if you want to save it).
    5. Mysterious compile-time error messages. If you experience this, here are several things to try:
    6. Compiling while running. If you get an error message that is something like:
          mingw32\bin\ld.exe: cannot open output file [SOMETHING HERE].exe: Permission denied
      
      that almost certainly means that you are still running the program in this or another console. To fix this, you often have to use the pull-down menu on the right-hand-side of Console et al windows that says Display Selected Console. Select it, find the running programs and stop them with the usual red boxes. There are often MANY running programs in this situation; you must stop them all.
    7. Missing functions. Suppose you get a compile-time error message like:
      implicit declaration of function 'foo'
      
      or perhaps:
      conflicting types for 'foo'
      
      Any of the following could be the problem:
      1. You misspelled the name of the function, either in the call or the definition of the function.
      2. You called or defined the function with the wrong number or wrong type(s) of arguments.
      3. The function belongs to a library that you failed to #include.
      4. You defined the function BELOW the place in the file where you called it.
        • The C compiler barfs at this because it processes a source file from top to bottom, so when it hits the function call it does not yet know what it needs to know about the function.
        • One way to solve this problem is to move the function definition ABOVE its call(s).
        • Another, perhaps better, way is to put prototypes near the top of the file (before any function definitions), like this:
          double foo(double y[], int size); // Prototype, near the top of the file.
          
             ...
          double foo(double y[], int size) {
             ... // Code for the function here
          }
          
          The prototype is shown in red. It's easy to obtain — just copy the first line of the function definition and replace the curly-brace (and its preceding space, if any) by a semicolon. Its a good habit to make a prototype every time you define a function, because it avoids this problem and provides a handy list of your functions at the top of the file.
    8. Messy code is almost impossible to get correct. Keep things simple and clean. Refactor often to maintain that simplicity and cleanliness.
    9. Waiting to the last minute guarantees failure.
    10. Turn In

      Submit your work by committing it to your individual SVN repository. Commit often since that backs up your work.