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 07 Specific Step |
| Make a directory to hold all the files. | mkdir lab07 |
| Create the files in question. | Edit your lab07.h, lab07.cpp, and lab07-main.cpp from within the lab07 directory. |
| Use the tar command to tar up the files. | tar zcvf lab07.tar.gz *.cpp *.h |
You should now be able to see a lab07.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 lab07
The Kate Holdener Organization for Nutrition (KHON) has recently been concerned with the latest cookies developed on the 42nd floor of the Stimsonian Institute. KHON modeled the toxic cookies by breaking down the ingredients:
struct cookie
{
double m_flour; /* in kg */
double m_sugar; /* in kg */
double m_butter; /* in kg */
int m_eggs;
};
I have made some files to get you started on this lab. If you have not already, create a directory named lab07 and save the files to that directory. The files are:
| File | Purpose |
| lab07.h | Lab 07 Header File |
| lab07-main.cpp | Lab 07 main() Function |
| lab07.cpp | Lab 07 Main Implementation File |
KHON's Team of Mathematicians modeled the harmfulness, H of the cookies using the following equation:
![]()
where b is the kilograms of butter, e is the number of eggs, f is the kilograms of flour, and s is the kilograms of sugar. Write a function that will calculate the harmfulness of the cookie based on the recipe:
double cookieHarm(cookie recipe);
KHON also modeled the number of days, D, eating such cookies will take off of your life using the following equation:
![]()
Write a function that will calculate the number of days you are taking off your life:
double cookieDays(cookie &recipe, double harmScore);
Chefs at the Stimsonian Institute noticed that this equation divides by zero if there's no sugar in the cookies. They called KHON and advised to add a pinch of sugar (0.01 kg) in case s = 0.
Now write a function that, given the user's age and the number of batches of cookies they consumed over their lifetime, will calculate how many days they have to live. If the number of days is negative, print a creative epitaph for the user because they SHOULD be dead! Assume that there are 365.2425 days in a year and everyone lives to be 75 years old.
![[Dilbert]](dilbert.gif)