CSE2050 Syllabus
Programming in a Second Language (C++)

Florida Tech, Spring 2002 - Jan. 8 to Apr. 25 - Tues. and Thurs., 12:30-1:45 PM, room 137EC

http://cs.fit.edu/~mmahoney/cse2050/

Syllabus - short version

Course Description

Students will learn to program in C++. Topics include the standard library, object oriented programming (data abstraction, inheritance, polymorphism), implementing data structures, and the UNIX development environment and portability considerations. Prerequisites: CSE2010 (Algorithms and Data Structures) or equivalent, experience in at least one other programming language.

Instructor

Matt Mahoney, mmahoney@cs.fit.edu or if that doesn't work, then matmahoney@yahoo.com Office hours are immediately after class.

How is my teaching? Review this course anonymously at TeacherReviews.com.

Textbook

Accelerated C++, Koenig and Moo, Addison Wesley, 2000

Code examples from the book
C++ Reference
Guidelines for Object Oriented Programming

Grading Policy

Based on 100 points. 90-100=A, 80-89=B, 70-79=C, 60-69=D, 0-59=F

Tests, 50% of grade

There will be 4 tests during the term including the final exam. Each will count equally. Your grade will be based on the highest 3 tests after dropping the lowest score. There will be no make-up tests for any reason. Fall 2001 exam solutions:

Spring 2002 Exam solutions:

Exam 1 solution.
Exam 2 solution.
Exam 3 solution.
Final Exam solution.

Fall 2001 Exam solutions:

Fall 2001 syllabus and homework
Exam 1 solution.
Exam 2 solution.
Exam 3 solution.
Final Exam solution.

Spring 2001 Exam solutions:

Exam 1 solution.
Exam 2 solution.
Exam 3 solution.
Final Exam solution.

Programming assignments, 50% of grade

Assignments will be graded equally on documentation and readability and on whether it actually works. Programs are due at midnight. Programs turned in late will be penalized 20% per day, including non-class days, weekends, and holidays.

Programs must be turned in by email. I prefer that you send me one source code (.cpp) file as an attachment, or in the body of the mail message if your mailer doesn't supoort attached files. Limit line length to 80 characters. I do not need test cases by email, since I can test it myself. Do not send me executables, zip files, Word files, project files, etc.

You are permitted to receive help from other students or outside sources, however you must cite your sources in your program comments and your work must still demonstrate that you are capable of writing the program yourself. Copying code or allowing your code to be copied by other students is not allowed. See the Florida Tech Computer Science Honor Code for details.

Documentation

All programs should have as comments:

Compilers

All programs must be tested with g++ under UNIX (Solaris, Linux, etc.). You may use other systems for development if you wish (Windows or Mac), and then port them. If you do, your C++ compiler should be produced since 1998 so that it supports the standard library. If you prefer to develop under Windoes and port to UNIX, then I recommend DJGPP, available at www.delorie.com. Other free compilers are available at www.cplusplus.com/info/compilers/

Mailing List

All students will be enrolled in a mailing list and will be responsible for announcements posted to this list. You should be enrolled automatically, but I sometimes miss a few people, so if you do not receive an email by the second class letting you know, then you should subscribe by sending a blank email to fit-cse2050-subscribe@yahoogroups.com. You are also encouraged to post questions about C++ or your assignments to this list, and to answer questions posted by other students. To post messages, mail them to fit-cse2050@yahoogroups.com. Archived messages may be found at groups.yahoo.com/group/fit-cse2050/

Assignment 1

Due Tues. Jan 15, 2002. (10 pts). Obtain an FIT system-wide account (if you don't already have one) from the Help Desk in the Quadrangle, room Q7. This will allow you to use all the student machines (UNIX, Windows, and Windows NT) in the Olin Engineering and Life Sciences buildings and in rooms A110 (Aeronautics bldg.) and S210/S220 (Crawford Science bldg). See cs.fit.edu/wds/labs/openlabs/. Also, you may want to obtain an account on zach.cs.fit.edu (another UNIX machine with g++). See http://www.fit.edu/acs/userservices/apply_account.htm You should be familiar with UNIX to use these systems. If not, see http://www.emba.uvm.edu/CF/basic.html

Compile and run the "hello world" program on page 1 using g++. Add comments as described above.

Assignment 2

Due Tues. Jan 22, 2002 (10 pts). Write a C++ program like the one in chapters 1 and 2, except that it prints a triangle around the greeting instead of a rectangle. For instance:

Please enter your first name: Matt

          *
         * *
        *   *
       *     *
      *       *
     *         *
    *           *
   *             *
  * Hello, Matt!  *
 *                 *
*********************

Be sure your documentation describes the program completely, including how you handle the case where the greeting can't be centered exactly.

Solution

Assignment 3

Due Tues. Jan. 29, 2002 (10 pts). Write a program to sort files. This assignment is deliberately vague (like real world programming assignments), so you will need to write an analysis (program description) describing what it means for a file to be sorted and how the user specifies the file names. Give an example showing how your program would be run (what does the user type?), and a sample file before and after sorting. Put all of this in your documentation before the first line of code. I suggest you try man sort in UNIX for some ideas, but you don't have to do it this way.

You do not need to write a sorting algorithm. You can use the standard library function sort() on a vector of strings to do most of the work.

Solution

Assignment 4

Due Feb. 12, 2002 (10 pts). Write a program to index a text file by line number. The program should take a file name as an argument, then print an alphabetical listing of all the words in the file, in lower case. Each word should be followed by a list of line numbers (separated by spaces on the same line of output) where the word appears. A word is any sequence of letters from a to z with no other characters in between. Upper and lower case are considered equivalent, i.e. "The", "the", and "THE" are all the same word and are listed as "the". If a word appears on more than 10 lines, list only the first 10 line numbers followed by "...". If a word appears more than once on a line, list the line number only once. The first line is line 1. If the program is run without a file name argument, read from standard input (cin). If the file does not exist, print an appropiate error message to cerr (so that the message will appear on the screen even when the output is redirected).

For example, suppose the file test.txt contains the following:

  This is
  a test.  THIS and this is
    another test.

  index test.txt     (or index <test.txt)
  a 2
  and 2
  another 3
  is 1 2
  test 2 3
  this 1 2

Solution

Assignment 5

Due Tues. Feb. 26, 2002 (15 pts). Write a program to print calendars for any given month, for example:

  cal Feb 2002

  February 2002
  Su Mo Tu We Th Fr Sa
                  1  2
   3  4  5  6  7  8  9
  10 11 12 13 14 15 16
  17 18 19 20 21 22 23
  24 25 26 27 28

Your program should take as arguments:

Your program should define a class Month to represent a month and year using your choice of private representation. It must have the following public members:

Your program should catch any excptions thrown by Month.

Hints:

Solution

Assignment 6

Due Mar. 26, 2002 (15 points). Modify assignment 4 (the file index program) to use a binary tree instead of a map. The output of the program should be the same. However, instead of a map<string, vector<int> >, you will use a Tree<string, vector<int> >. The templated class Tree<K, V> should have the following public members:

The implementation must be hidden (but documented). This includes any new types or structs needed to implement your tree. You should assume that type K supports ordering by <, but do not assume that the other comparison operators are defined (like == or >). You may assume that K and V support assignment, copying, and default initialization.

Since a Tree does not support iterators, you need to use the transform() function to print the index. For example, the word count program on p. 124 could be implemented as follows. (This would also be a good way to test your program).

  // Print s and i on one line
  void print(const string& s, int& i) {
    cout << s << "\t" << i << "\n";
  }

  // Prints an alphabetical list of words from input and number of times they each appear
  int main() {
    string s;
    Tree<string, int> counters;  // Maps words to counts
    while (cin >> s)  // Build the tree
      ++counters[s];
    counters.transform(print);  // Print the tree
    return 0;
  }

Solution

Assignment 7

Due Apr. 23, 2002 (30 pts). Write a program for displaying ASCII graphics. The input should be a series of graphics commands from a file or standard input to draw lines, rectangles, text labels, etc. The output should be a drawing suitable for display on a text terminal of unknown dimensions. A drawing command is one line containing a keyword (not case sensitive) followed by a list of numbers separated by white space.

HLINE x y w
Draws a horizontal line of width w, from (x, y) to (x+w, y) consisting of w+1 "-" characters. For example, HLINE 1 2 3 draws ---- with the first character at (1, 2) and the last at (4, 2).
VLINE x y h
Draws a vertical line of height h from (x, y) upward to (x, y+h) consisting of h+1 "|" characters.
LINE x y w1 h1 w2 h2 w3 h3 ...
Draws a series of lines connected by "+" at their endpoints, starting at (x, y), then alternating right and up by w1, h1, w2, h2, etc. (or left and down if negative). There may be any number of widths and heights. Each segment consists of |w|+1 "-" characters horizontally or |h|+1 "|" characters vertically, except that the first character is replaced by "+" when it overlaps the last character of the previous line segment, unless the previous segment has length 0. Note that LINE x y w1 is equivalent to HLINE x y w1, and LINE x y 0 h1 is equivalent to VLINE x y h1.
BOX x y w h
Draws a filled rectangle with width w and height h and with lower left corner at (x, y). Equivalent to LINE x y w h -w -h w (drawing the bottom twice so there is a + at every corner) except that the interior is also filled with spaces.
LABEL x y text...
Draws a text label with the first character at (x, y). The text label starts with the first printable character but may contain spaces.
plus one graphical element of your choice. The origin of the coordinate system is (x,y) = (0,0) at the lower left corner, with x going right and y going up. There is no upper bound on the coordinates, but because the text display could be any width, the last printable character on each line should be followed by a newline with no additional spaces to avoid unnecessary text wrapping of the output. If two graphical elements overlap, then the first one should be on top. For example, if the input is:
hline 0 2 9
line 0 0 0 4 3 -4 3 4 3 -4
then the output is:
+--+  +--+
|  |  |  |
----------
|  |  |  |
|  +--+  |
If the input is:
label 4 4 Hello World!
box 2 2 15 4
vline 9 0 9
box 4 4 15 4
vline 10 0 9
Then the output is
         ||
    +----|---------+
    |    |         |
  +--------------+ |
  |              | |
  | Hello World! |-+
  |              |
  +--------------+
         ||
         ||

Your program should make appropriate use of object oriented programming techniques (data abstraction, inheritance, and polymorphism). For example, you might have classes Hline, Vline, Line, Box, and Label (some may be derived from others or contain others) with a common abstract base class Shape with a pure virtual method draw(). You should read the input into a polymorphic data structure such as a linked list of Shape or vector<Shape*> so that the objects can be drawn in reverse order of the input so that the first object appears on top. Objects could be drawn into a Buffer (another class), whose dimensions might be found by scanning the list of Shapes to find the maximum x and y, or be determined dynamically for each row during drawing. Then the Buffer would be printed to the screen using the << operator.

Be sure your analysis is clear, especially with regard to your extra graphical element, and any other details not specified in the assignment. For example, how is the input file specified? What happens if you draw at negative coordinates? What happens for invalid commands, the wrong number of parameters, or the parameters are not integers? In the code, be sure to comment classes, data structures, functions, methods, etc. so that I can understand how you applied object-oriented principles.

Solution