Write a simple C++ program that prints "Hello, World!" (or some other
greeting of your choice) on the command-line.
No write-up is needed for this orientation lab; the main point is to make
sure you are setup with a C++ development environment (editing, compiling,
running).
If you are using Microsoft Visual Studio 2008, note that it is a very complex
and powerful development environment; invest time to learn it, and it will
help you in the long term. Visual Studio is available on the senior lab
computers. When it starts up for the first time, select "Visual C++" as
the working profile.
You may find helpful Microsoft's
"Visual C++ Guided Tour" (also available from online help within
Visual Studio).
The first section,
"Introducing the Visual Studio IDE (C++)",
and parts of the second section,
"Creating Command-Line Applications (C++)",
will be most pertinent to your Win32 command-line application.
Package up your whole project directory, including all source and header files,
into one ZIP file, and upload it to myCourses.
Write a C++ program that uses the if or
switch structures to print the song,
"The Twelve Days of Christmas".
The user must be asked to enter a day from 1
to 12, and the program must display the corresponding message for that day.
The strings for each day should only appear in your code once each (e.g., the
string "five golden rings" should only appear in your code once).
Google for the lyrics, or make up your own (keep it clean, please).
Choose one of the following options:
- Write a program that produces a histogram of the letters in a file.
A histogram is a bar-chart with the length of the bars representing the
frequency with which the corresponding letter appears in the file.
- Write a ROT13 encryption program that reads in a plaintext file and
outputs encrypted text to another file.
- Write a program that gives and takes advice on programming. The
program starts by displaying a piece of advice on the screen, then asks
the user to type in another piece of advice (can be multiple lines),
ending with a blank line (press Return twice). The program then ends.
The next person to run the program sees the piece of advice given by
the last user to run the program.
Write a class defining some new kind of mathematical entity not built-in to C++.
Possible options are mentioned below.
Your class must include at least the following functionality:
- Constructors that can take a variable number of arguments, and provide
reasonable default values.
- A reasonable copy constructor.
- Overload the operators +, -, *, /
to work the way they should.
- Overload the operators ==, !=, <, ≤, >, ≥ to work
in a reasonable way.
- Also write a separate testbed program that shows off the functionality
of your class.
Possible mathematical entities you may consider:
- Rational numbers (fraction of two integers). Include a method to
reduce the fraction to lowest terms. Be sure to protect against zero
denominator.
- Complex numbers (a + bi, a real and an imaginary part).
Make sure that multiplication works the proper way for complex numbers.
- 2x2 matrices. Include a method to compute the determinant. Come up
with a reasonable semantics for the operators.
- Come up with your own idea! Just check with me first.
Write a "reasonably useful" interactive program using FLTK for the GUI.
Your application should be designed to make use of a GUI (i.e., not something
that could easily be done in a command-line text interface). You may find
the FLTK docs and
Erco's FLTK Page helpful.
You do not have to use Fluid if you don't want to.
Be creative and have fun!
Both of these options require a nice user-friendly FLTK GUI: your program
should be reasonably easy-to-use and not unbearably ugly. An average
computer user (non-programmer) should be able to figure out the controls,
even without the help text (which you should also provide). You are not
required to use Fluid, but you are asked to use FLTK.
- Option 1:
Write an FLTK GUI program to render a fractal
L-system or
Iterated Function System (IFS) using a recursive algorithm.
The shape need not be a Sierpinski gasket.
Most fractals have some parameters that can be tweaked (e.g., length of
each branch compared to its parent); provide some kind of interactive
graphical interface to adjust those parameters.
The fractal can be 2D.
Extra credit (up to 5pts): make it 3D using OpenGL.
- Option 2:
Write an FLTK GUI program to read in an image
(need not be colour), display it, and manipulate it
(i.e., a rudimentary Photoshop).
Provide an interactive graphical
interface to adjust the brightness and contrast of the image.
Hint: if the original shade (o) and final shade (f) are floats between
0 and 1, and the brightness (b) is a float between -1 and +1, and the contrast
is a float between 0 and infinity, then one simple way to define
brightness and contrast is by: f = (o+b)*c. The final shade f will need to
be clamped to [0,1]. This method has some bad limitations; you may want to
research better ways to define contrast and brightness.
Extra credit (up to 5pts): add another Photoshop image operation/filter
of your choosing.
Design a networked client/server application and
implement it in C++ using TCP sockets.
- You will need to write two programs, one for the client and one
for the server. They may share some code; put all the shared code in
separate .cpp files and have both client and server link in those files.
- Sample code:
command-line client/server.
You may use this code as a starting point -- but no guarantees about the
quality of my code; it's pretty rudimentary and might not work right!
- The sample code works with the BSD sockets libraries in Cygwin
and Linux. Windows' own socket library, Winsock2, is slightly
different; see
MSDN article on Winsock, including
the chapter on differences between Winsock and standard BSD sockets.
- This lab need not have an FLTK GUI; command-line is fine.
(But see the extra credit option!)
- For testing purposes, both client and server may be run on the same
machine. The hostname 'localhost' (IP 127.0.0.1) always refers to
the same host the program is running on.
- If you want to try running client and server on two different machines,
the host running the server needs to have an exception in its firewall
for the port number the server uses. The senior lab machines have had
exceptions added for TCP ports 4410 and 4411, so you can use either
of those for your server port.
- You may use 'ipconfig' (Windows) or 'ifconfig' (Linux) to find the
IP address of the current machine. The senior lab machines are named,
e.g., SENIORLAB08; you may use this as input to gethostbyname().
- This lab is more complex and worth more than the other labs.
5 of the points will be from a demo presentation you will give of
your lab project, in class on Mon 6Apr in the senior lab. This is a big lab,
and you want to have something nice to show, so make sure you allocate
enough time to work on it!
- Extra credit (up to 5pts):
Give it an FLTK GUI! You'll need to use multithreading; see
my FlChat sample program and
the fl_threads.h wrapper for
PThreads.
Again, you may use my code as a starting point -- but no guarantees, and
your project obviously must be significantly different from mine!