Today we will be working with multiple files. The fun thing is that Blackboard only accepts one file as an attachment, so we need to learn how to use the UNIX tar command. The tar command is a command that bundles many files into one compressed file, much like the WinZip program in Windows. We will use tar to bundle our assignments from here on out. Read these instructions carefully! Failure to do so will result in an ungradeable assignment, which will result in a 0!
| General Step | Lab 06 Specific Step |
| Make a directory to hold all the files. | mkdir lab06 |
| Create the files in question. | Edit your lab06.h, lab06.cpp, and lab06-main.cpp from within the lab06 directory. |
| Use the tar command to tar up the files. | tar zcvf lab06.tar.gz *.cpp *.h |
You should now be able to see a lab06.tar.gz file in your directory. This is the file you need to turn in.
Now that we are using multiple files, we now need to use a slightly modified compiler command:
g++ -Wall -W -s -pedantic-errors *.cpp -o executable
Notice the command has not fundamentally changed except for the *.cpp part of it. This is pretty much telling the compiler, "gather up all the .cpp files in this directory, compile them, and save the output in the file executable."
So, for this lab, you want to use this compiler command:
g++ -Wall -W -s -pedantic-errors *.cpp -o lab06
Tautological Industries (TI) has hired you as part of a team for its latest and greatest graphing calculator, the TI 42. After much discussion and division of work, TI wants you to create the absolute value and cosine functions for the new calculator. Since you're working on a team, TI requires you to keep all your code in separate functions and separate files so all the team members' functions can come together easily at the end.
I have made some files to get you started on this lab. If you have not already, create a directory named lab06 and save the files to that directory. The files are:
| File | Purpose |
| lab06.h | Lab 06 Header File |
| lab06-main.cpp | Lab 06 main() Function |
| lab06.cpp | Lab 06 Main Implementation File |
Use the files I gave you to implement and test the absolute() function. Make the functions in your lab06.cpp file and test your functions in your lab06-main.cpp file.
Physicists from the Institute for Stochastic Research on Particle Physics (ISROPP) bribed TI for a freefall function in the TI 42 to raise AP Physics scores. The equation for an object falling at freefall (neglecting air drag) is:
df = ½at2 + vot + do
where a = 9.80665 is the acceleration due to gravity, vo is the starting velocity, do is the starting position, and df is the final position. Write a function that will find the final position given the time elapsed, starting velocity, and starting position. By default, the starting velocity and starting positions will be assumed to be 0. However, if the user wants, they should be able to specify a different starting velocity and/or position.
Use the files I gave you to implement and test the cosine() function. Make the functions in your lab06.cpp file and test your functions in your lab06-main.cpp file. Do NOT use the cosine function from cmath. Instead, write it on your own. After all, we know from calculus that:

You can use the expansion as above. There is no need to expand the series further. One unique feature TI wanted was the ability for the user to have two options for the cosine function: either enter in the argument directly or enter in the argument in terms of π (i.e., if they enter x when this option is active, then the function should calculate cos(π x). Make sure to test both modes in your main() function. So, for example, you could have a program that works something like this:
What number do you want to take the cosine of? 0.25
Is that number in terms of pi (y/n)? n
OK, the cosine of 0.25 is 0.968912.
Or, if the user said yes to the previous question:
What number do you want to take the cosine of? 0.25
Is that number in terms of pi (y/n)? y
OK, the cosine of 0.25 * pi is 0.707106.
Part I is worth 8 points. Part II is worth 10 points (Part I + 2 more points). Part III is worth 12 points (Part II + 2 points extra credit). The lab is out of 10 points. When you're done, submit your lab06.tar.gz file on Blackboard. I will be grading your program on the following criteria:
![[Dilbert]](dilbert.gif)