Assignment 05

HOMEWORK #5

CS 53

Due: Thursday, Oct. 4, 2012, at noon, 100 points

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Of course, you will submit in the usual (correct) way. cssubmit shall be your guide to enlightenment and redemption.

Background: Oh, that Krusty! Krusty wants to turn as much of a profit as possible. So, he hired an emminent scientist, Nathan Eloe1, to determine a mathematical model that will generate numbers that somehow relate to his profits from Krusty Burger based on two variables. These variables are the number of different animal parts used in a burger, and the number of different types of animals (from which these parts are extracted) used in the burgers. In the foregoing formula, these are denoted as x and y, respectively.2

f(X,Y) = X * e-Y2/X

Specifications: Your program is to use several functions to implement this program. You will have functions to:

    1. Greet the user.

    2. Prompt the user and read in values to be used in the calculations of Krusty's Profit Maximizer. This can be done in several ways; we leave it up to you to decide the method. But however you do it, you will need to input integers from the user for a lower and upper bound for both functional values (x and y in the formula below).

    3. A function that will output in table format (no horizontal or vertical lines necessary in this table) the values of the Maximizer function. It will call the (next) function that computes these profit values.

    4. A function that calculates the values of Krusty's profit function. This function will have two parameters representing the inputs to the program by the user, and it will return a single value computed in accordance with the above Krusty function.

    5. Sign off the running of the program.

Have your program loop, requesting new inputs by the user. You can devise a way for the program to terminate (specific inputs, "wanna quit (y/n)", or some other way; it's up to you.)

Details: The devil is the in details....except in this case. You are now allowed to use the cmath library. You get access to this with a

#include <cmath>

pre-processor command. Here are two good references for looking up information about system library functions:

    • http://en.cppreference.com/w/

    • http://www.cplusplus.com/

Also, for you output, you will produce a table of values but this table doesn't have to have verticle or horizontal line separators. Please use the "magic code" we gave you in assignment #3 that formats numerical output with exactly 2 dec points. That will make your output look pretty. You don't need to know any other special output formatting code to make the table.

To make it clear what we're looking for in output, suppose the user inputs for x the lower bound of 1 and upper bound of 3, and lower for y or 4 and upper bound of 7, your output should have values for f(x,y) for integer values of x incremented from 1 to 3 and y from 4 to 7.

f(1,4) f(1,5) f(1,6) f(1,7) f(2,4) f(2,5) f(2,6) f(2,7) f(3,4) f(3,5) f(3,6) f(3,7)

Remember: When writing your code, be sure to:

    • Use meaningful variable names.

    • Use proper spacing for indentations.

    • Use constant variable declarations where appropriate.

    • Include the comment block at the head of your file.

    • Comment code that needs it.

    • Be literate in your welcoming/signing-off messages and prompts and output.

    • Make the output pretty and user-friendly.

Note: Don't underestimate the time that it will take to write this program!

When you submit the submit script will compile and execute your program in the process. This means that you will be the "user" of the program for that few minutes. Now, in order that the grader isn't driven crazy by a multitude of inputs/outputs, you will ALL input the same values so that he has uniform output to grade. They are:

    • enter lower bound of 2 and upper bound of 7 for the number of animal parts

    • enter lower bound of 1 and upper bound of 4 for the number of animals

    • do again

    • enter lower bound of 3 and upper bound of 8 for the number of animal parts

    • enter lower bound of 4 and upper bound of 5 for the number of animals

    • quit

ALSO, you are to include in your submission a .txt file in which you will compose in Kings English an interpretation of the output of your program. You will receive extra points3 for doing this in rhyme. In any case, you will receive more credit for more thorough and humorous prose.

As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutors.

1I don't know who this joker is.....some math mercenary sorta guy.

2 These are NOT good variable names in any computer program.

3"extra points" is a loose term and can be interpreted any way WE like.