Programming Assignment 1
Programming Assignment 1
Spring 2012
Instructions
● It is important that you work on this assignment independently as it will serve as a
building block for the rest of the course.
● Ask the teaching staff first if you have any problems. It is OK to discuss the assignment
with your friends and classmates as long as you only discuss programming concepts.
Do not copy code from them!
● Section I can be done in C++ or Python. Section II can only be done in C++.
● The standard late policy as detailed in the syllabus will be followed.
● Remember to follow the submission instructions with each section
● There are 3 pages in this assignment
The first few numbers of the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,... More
information is available on the wikipedia page:
http://en.wikipedia.org/wiki/Fibonacci_number
Below are a number of references you might have to use to complete this section. These might
be especially useful if you are unfamiliar with C++
http://cplusplus.com/doc/tutorial/basic_io/
http://cplusplus.com/doc/tutorial/functions/
http://cplusplus.com/doc/tutorial/functions2/ (Check out the section on recursive functions)
A) (3 points) In this section you will need to implement 2 classes, HeatingUnit and
BangBangControl. Remember to implement the classes in separate files as discussed in class.
A Bang-bang control is one of the simplest controllers out there, and you will probably have one
in your home. You can read up on Bang-bang control here:
http://en.wikipedia.org/wiki/Bang%E2%80%93bang_control
The BangBangControl should have an object of the HeatingUnit class and should expose the
following 4 functions:
constructor - takes 3 initial parameters: the temperature to maintain, whether the heating unit is
on or off, and the initial temperature. The last 2 parameters are passed to the constructor of the
HeatingUnit class
setTemp() - set the temperature to maintain
getTemp() - get the temperature that is currently being maintained
update() - update first calls the tick() function of the HeatingUnit object. It then uses the following
check to figure out whether the heating unit needs to be turned on or off.
if (current_temp > temp_to_maintain + 2) heating_unit.turnOff()
if (current_temp < temp_to_maintain - 2) heating_unit.turnOn()
B) (2 points) Write 3 different Makefiles as discussed in class and using the help of examples
provided. The 3 Makefiles should implement each of the following:
1. Compile both classes and your main code directly into 1 binary (executable).
2. Compile the 2 classes into separate static libraries and then link it to the binary.
3. Compile the 2 classes into separate dynamic libraries and then link it to the binary.
To know more about tar and turnin, look up the manual for these commands. Type in man tar or
man turnin for further documentation.