CSE1502 - Introduction to Software Development with C++

Matt Mahoney
Spring 2008

Instructor Schedule

Jan. 7 to Apr. 25, 2008. No classes on Jan. 21, Feb. 18, or Mar. 3-7. Final exam Apr. 29, 8:00-10:00 AM in A110.

Labs, depending on your section, one of:

You may switch lab sections if space is available and with permission from the two lab instructors involved. (Currently only the 9:30 AM lab has space).


Accelerated C++ by Koenig and Moo. Read through chapter 9. Also read the tutorial and Introduction to C++.

Mailing list

All students are expected to join the CSE 1502 mailing list. You are responsible for material posted to this list by instructors. You are also encouraged to post questions or answers about your homework or about C++ in general here, because other students might have the same questions.

To post a message, send email to cse1502@lists.fit.edu. When replying to a post, remember to check the "to" address before sending, depending on whether you want to reply to the sender or the whole class. Please do not post your homework to the list.

Grading policy

Exams (40% of grade)

Your exam grade is the average of the best three grades after dropping the lowest grade. There are no makeup exams for any reason. All exams are weighted equally. If you miss an exam (including the final), then that is your drop. All exams are open book and open notes, but no computers or electronic devices are allowed. Exams 1-3 will be given in the labs and administered by the lab instructors (but graded by me). The final exam will be in the lecture hall.

Fall 2006 exams
Exam 3
Final exam

Spring 2007 exams
Exam 1
Exam 2
Exam 3

Fall 2007 exams
Exam 1
Exam 2
Exam 3

Lab assignments (30% of grade)

Your lab instructors will be responsible for assigning and grading your labs and establishing grading policy, which may be different from my policy. They will have the final decision on your lab grades.

The lab computers have g++ and Visual Studio installed. You will need a TRACKS password to use the computers.

Homework (30% of grade)

Homework assignments will be longer programming assignments graded manually for correct design, function, documentation, and neatness. Partial credit is given based on my subjective opinion of how well you understand and describe the problem in comments (the specification), your approach (design), and testing (whether it works or gives appropriate error messages for unusual or unexpected inputs). Grading depends on human readability as well as machine readability. Code should be indented using the style in the book. Major sections should be commented. Variable names should be self documenting or their purpose should be commented as appropriate. Your homework should include your name and email address in the comments.

Homework must be submitted by email by midnight of the due date. Late assignments are penalized 20% per day. I encourage you to submit homework early for me to comment on, and submit revised versions later without penalty. I will grade only the best version.

You must cite all sources of outside help in your comments, including help received from other students or the Internet. Copying code or allowing your code to be copied is not allowed. Group assignments are not allowed. You are expected to know the CS department policy on academic honesty. Penalties for cheating can range from a zero on the assignment to expulsion from the university. I report incidents of cheating to the department head.

Final grade = (average of top 3 exams) * 0.4 + (lab grades) * 0.3 + (average of homework grades) * 0.3.
90-100=A, 80-89=B, 70-79=C, 60-69=D, 0-59=F.

Fall 2006 syllabus
Spring 2007 syllabus
Fall 2007 syllabus


You will need a C++ compiler for your home computer. You may use any standard ANSI C++ (released since 1999) compiler under any operating system (Windows, UNIX, Linux, Mac). I recommend (but don't require) MinGW g++ for Windows or GNU g++ for other operating systems. All of the following are free under Windows:

MinGW g++. This runs from a command window only. Download and run the installer (MinGW_Toolbox_Setup.exe, 23 MB). Add C:\mingw\bin to your PATH. In Vista, you may also have to copy the file cc1plus.exe from c:\mingw\libexec\gcc\mingw32\3.4.5 to c:\mingw\bin.

Visual Studio 2005 Pro or Standard. You will need a TRACKS account and be registered for this class to download it. This has a GUI and lots of features. The Pro version download is 2.8 GB (DVD image). Not recommended for older machines or slower connections. To install, download the 4 .rar files, unrar e *.rar, then burn a DVD from the .iso file or use the provided program to mount the .iso to disk and run vs\autorun.exe as administrator.

Borland C++ 5.5. This runs from a command window only. Works on old machines. Click on "compiler", register, and download the installer (8.7 MB). After installing, add C:\Borland\BCC55\bin to your PATH and create the file C:\Borland\BCC55\bcc32.cfg exactly as shown below:


Digital Mars C++ Compiler 8.49. This runs from a command window only. Works on old machines. Unzip stlport.zip (2 MB) and dm849c.zip (3 MB) in C:\ to install in C:\dm and add C:\dm\bin to your PATH.

Be sure to test your compiler by writing a simple program, compiling, and running it, e.g.

// Paste this file into notepad and save as hello.cpp
// To compile from a command window:
//   MinGW:   g++ -Wall hello.cpp -o hello.exe
//   Borland: bcc32 hello.cpp
//   Mars:    dmc hello.cpp -IC:\dm\stlport\stlport
// To run: hello
// In Visual Studio: create new project, select Win32 console application, 
//   uncheck "precompiled headers", delete the supplied code, replace with this code
//   and click Build project, Debug/Start debugging.
#include <iostream>
using namespace std;
int main()
  cout << "Hello world\n";
  return 0;

Homework 1

Due Wed. Jan. 30, 2008 at midnight (20 out of 100 homework points). Write a calculator program. The program should prompt the user to enter an expression of the form number operator number such as 5.2 * 3, then print the answer (15.6) and ask if the user wants to enter another problem. If the user answers y (for yes), then prompt for another problem. If the user answers n (for no) or anything else, then exit. Operators may be + - * or /. Numbers may have decimal points and/or a leading - sign. You may assume the user enters a space between the numbers and operator. For example (bold is user input):

  Enter a problem: 3 + 10.5
  Another problem (y/n)? y
  Enter a problem: -2 / 3
  Another problem (y/n)? y
  Enter a problem: -2 - 3.1
  Another problem (y/n)? n

Submit one plain text source code (.cpp) file as an attached file by email to Matt Mahoney at mmahoney@cs.fit.edu or matmahoney@yahoo.com Do not send executables, project files, etc.

I will test your program with g++. If you use Visual Studio, be sure when you create a new project to select "Win32 console program" and uncheck the box "use precompiled headers". VS will create a new project with some initial code that you should delete. You should not have any code that looks like this:

  #include "stdafx.h";  // no, this is not a standard header file
  int _tmain(int argc, TCHAR* argv)   // no, int main() with no parameters

Be sure that your program includes a specification - about a paragraph of comments at the beginning that describe what the program does, even if it is different from the description above. The specification does not say how the program works. It describes the input and output from the user's point of view, and does not mention anything about the code. The specification is 20% of your grade.

Also be sure to put your name in the comments.


Homework 2

Due Wed. Feb. 20, 2008 by midnight (25 points). Write a program to read text from standard input and print a list of palindromes with length at least 2 sorted by increasing length. A palindrome is a word spelled the same forwards and backwards (not case sensitive), such as "Madam". Palindromes of the same length should be printed in the same order they were input and in their original upper and lower case. Each palindrome should be printed on a separate line. A "word" is any sequence of characters containing only A-Z and a-z and separated by other character values. You may assume the input ends with a newline. Your program should not prompt for input. The program should read to end of file (or Ctrl-Z if from the keyboard in Windows). For example, if your compiled program is a.exe, then (user input in bold):

Madam, I'm Adam.
Hah! I said.  A bird replied, "Peep-peep-peep".
I'll see u later.

Hint: read a list of palindromes into a vector<string>.

Reminder: the specification is 20% of your grade. No group projects allowed.


Homework 3

Due Wed. Mar. 19 by midnight (25 points). Write a spell checker. Your program should take as command line arguments (not input) the name of a dictionary file and a list of words to be checked. For each word, print whether the word is correctly spelled, and if not, suggest a list of 5 of the most likely alternate spellings.

The dictionary file will be a list of words such as words. For each word not found in this list, your program will choose the 5 words that have the fewest points according to the following rules:

For example, the pair "bananas" and "band" would get 2 points because "s" and "d" are in one word but not the other, 6 points because the lengths differs by 3, and 2 points because they end with a different letter, for a total of 10 points.

Suppose that dict is a text file with the following 9 lines, and words is the file linked above with 25143 lines.


In the following examples, the compiled program is a.exe. User input (on the command line) is shown in bold. The numbers in parenthesis after each word are scores. Printing the scores is optional. In case of tie scores, you are not required to list them in the same order as this example, so your output could be diferent.

a dict star satr saar stars stter ba baa baby bana
star is correct
satr should be one of star (0) stir (2) stars (4) steer (4) tar (6)
saar should be one of star (1) stir (3) stars (5) steer (5) tar (7)
stars is correct
stter should be one of steer (0) star (4) stars (4) stir (4) tar (10)
ba should be one of a (6) at (7) banana (9) art (10) tar (10)
baa should be one of banana (7) a (8) art (8) tar (8) at (9)
baby should be one of banana (8) star (10) art (11) tar (11) at (12)
bana should be one of banana (4) star (10) a (11) art (11) tar (11)

a words star satr saar stars stter ba baa baby bana
star is correct
satr should be one of star (0) scar (2) sear (2) soar (2) spar (2)
saar should be one of scar (1) sear (1) soar (1) spar (1) star (1)
stars should be one of start (2) satyr (3) smart (3) stair (3) stare (3)
stter should be one of steer (0) seder (2) sever (2) sheer (2) sneer (2)
ba should be one of boa (3) be (4) by (4) b (5) bad (5)
baa should be one of boa (1) bad (3) bag (3) bah (3) bam (3)
baby is correct
bana should be one of bona (1) band (3) bane (3) bang (3) bank (3)

a foo test
File not found: foo

To spellcheck: a file words...

This specification is incomplete. Your program should include a complete specification. For example, does case matter? What about words with characters other than letters? What if the dictionary file does not exist. What format does the dictionary need to be in? (sorted?, one word per line?, no duplicates?, etc). What happens if several words have the same score? What happens if the user doesn't enter any command line arguments, or in the wrong order? Give an example of running the program and what the output will look like. The specification is 20% of your grade.


Homework 4

Due Apr. 21, 2008 by midnight (30 points). Your program should read a text file and determine the most common word for each length 1, 2, 3,... up to the longest word. For each different length, report how many times the most common word occurs, followed by an alphabetical list of all words with that frequency. The file name should be given as a command line argument (not input). For example if the file test.txt contains

  This is a TEST...
  And this is another test, it is.
and your compiled program is a.exe then the command shown in bold will produce output as shown:
  a test.txt
  1 a
  3 is
  1 and
  2 test this
  1 another

The output shows that among 2-letter words, the word "is" occurs 3 times, more than any other (like "it", which occurs once). Among 4 letter words, "test" and "this" each occur twice (which is more than any other 4 letter word), so they are listed alphabetically. There are no words of length 5 or 6, so the output is skipped for these lines. The longest word has length 7 so that is the last line of output.

For this program, a "word" is any sequence of 1 or more letters (A-Z, a-z) with nothing else in between. Thus, "don't!" is 2 words, "don" and "t". Upper and lower case are considered equivalent, so "TEST" and "test" count as 2 instances of the same word. Output should be all lower case.

If the input file does not exist or none is given, your program should print an error message (and not crash).

Output for alice.txt should be as follows:

a alice.txt
632 a
729 to
1642 the
462 said
398 alice
128 little
83 herself
40 dormouse
18 something
14 everything
28 caterpillar
10 conversation
4 uncomfortable
2 contemptuously

Output for book1.txt should be:

a book1.txt
3921 a
3786 of
7757 the
1629 that
619 which
180 little
368 gabriel
335 boldwood
556 bathsheba
30 apparently
86 weatherbury
55 casterbridge
21 circumstances
9 disappointment
3 thoughtlessness
2 responsibilities
1 comprehensiveness contradictoriness undistinguishable

Hint: read the input file into a map<string, int> that maps each word to its count.


Extra Credit

Due Fri. Apr. 25, midnight (up to 20 points). Write a program to print pi to 1000 decimal places using Machin's formula, using strings to represent high precision numbers.

Note: your total homework grade cannot exceed 100 points. This assignment is intended for those who need to make up for a poor homework grade.