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

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


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, or experience in at least one other programming language (preferably Java).


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.


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

Code examples from the book
Introduction to C++ (The short version)
C++ Reference (The long version)
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. Grade = (highest 3 of 4 exams)/6 + (sum of homework grades)/2.

Tests, 50% of grade

There will be 4 tests during the term including the final exam (on Apr. 28, 3:30 PM). 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.

Spring 2004 Exam solutions

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

Fall 2003 Homework and Exam Solutions

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

Spring 2003 Homework and Exam Solutions

Spring 2003 syllabus and homework
Exam 1 solution.
Exam 2 solution.
Exam 3 solution.
Final Exam solution.

Fall 2002 Homework and Exam solutions:

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

Spring 2002 Homework and Exam solutions:

Spring 2002 syllabus and homework
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 support 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.


All programs should have as comments:


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 Thurs, Jan. 15, 2004. (5 pts). Obtain an FIT system-wide TRACKS 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 http://www.it.fit.edu/tracks/. 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 Thurs. Jan. 22, 2004 (10 pts). Write a C++ program like the one in chapters 1 and 2, except that it prints a right 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 exactly how many stars are on each side as a function of the length of the name. You have some flexibility here, but your program must do exactly what your analysis says it does.

Assignment 3

Due Thurs. Jan. 29, 2004 (10 pts). Write an analysis (but NO CODE) for a program that counts the number of words, sentences, and paragraphs in a text file. The assignment is deliberately vague, however your analysis must not be. It should be precise enough that I could take any file and tell exactly what I should type to run your program, and exactly what output I should see. You may use any reasonable definition of "word", "sentence", and "paragraph" that you want, but your definitions must handle every possible input with no ambiguity. For example, how would you count the following:

  don't-know   (how many words?)
  !3.1...      (how many sentences?  Is this a new paragraph?)
Don't forget to describe how the user specifies the input file. Submit your homework as plain text (.txt or .cpp as one big comment).

Assignment 4

Due Thurs. Feb. 5, 2004 (10 pts). Write the code for assignment 3. Include your analysis from assignment 3 as a comment. You may update the analysis if needed. You will be graded on how well your code agrees with the analysis.

Solution. Generally, keeping the description in part 3 simple (but precise) made for less work and fewer errors in part 4.

Assignment 5

Due Mar. 11, 2004 (30 pts). Write a rational number calculator. Your program should accept input lines consisting of integer expressions on one line with the symbols + - * / ( ), with or without spaces, and print the exact result as a rational number. It should continue accepting input until the user enters a blank line or end of file. For example:

  -4 + 5 / -2
  Division by 0 error
  Syntax error at )

The operators * and / should have higher precedence than + and -, unless overridden with parenthesis. Operations with equal precedence should evaluate left to right. Division must be exact. The result should be printed in the form n/d where n and d have no common factors and d > 0, except for the case where d = 1, in which case the output is just n. Division by 0 is an error.

Your program should have a class Rational. It should be able to represent any number of the form n/d where n and d are type int and d != 0. Overload (at least) operators +, - (unary and binary), *, and /, either as member or nonmember functions. Operator / should throw an exception for division by 0. Use good object-oriented techniques (private data, constructors, etc). Be sure to document your program.


Assignment 6

Due midnight Tues. Apr. 20, 2004 (35 points). Write a templated singly linked list container class called Slist with forward iterators similar to list<T>. It should support the following operations as member functions:

  Slist<T>();  // Initially empty list of elements of type T
  size();   // The number of elements (as int)
  empty();  // true if size is 0
  push_front(x);  // Increase size by 1 and store x (type T) at front
  front();  // Reference to x just pushed (type T&)
  pop_front();  // Remove x, decrease size by 1
  begin();  // Forward iterator pointing to front (type Slist<T>::iterator)
  end();    // Points 1 past last element
  ==, !=, <, <=, >, >=    // Comparison starting at front (need not be member functions)
Copying and assignment must work correctly. Iterators should work with any algorithm accepting forward iterators (requiring operators *, ->, ++ (pre and post), ==, !=). for example:
  Slist<string> a, b;
  string s;
  while (cin >> s)
    a.push_front(s);  // Read a list of words
  b = a;  // Assignment
  Slist<string> c = b;  // Copy
  if (a.size()!=c.size() || !equal(a.begin(), a.end(), c.begin()) || a!=b || !(b==c))
    cout << "Test fails\n";
  while (!c.empty()) {  // Print list in reverse order
    cout << c.front() << endl;

Implement your class as a linked list starting at the front. Use good object-oriented technique. All implementation details (including any types or structs you define) must be hidden from the user. Be sure to test your program thoroughly with several different types, such as Slist<int>, map<Slist<string>, Slist<Slist<int> > >, etc. Use your imagination. Document any details I omitted from the specification (what happens to front() or pop_front() on an empty Slist? What is the meaning of comparison on Slists of unequal length? What are the requirements of type T?)

Turn in a header file named slist.h. I will #include it from a test file such as slistest.cpp