Homework 4: Linear Interpolation
This graphical assignment is designed to exercise your ability to declare an expression given an arithmetic formula.
Concepts
Linear Interpolation
Have you ever seen a cool graphical program that allows the user to explore and learn certain things about data? One cool feature in many of those programs is the ability to move the mouse around between known datapoints and to display an interpolated value. Rather than describe linear interpolation here, we will emphasize that you should have read section 2.5 pages 65 - 67 to understand a little about what linear interpolation is and how you can calculate a function value given an input value and two additional points of data.
We'd like to take this opportunity to show you bad style vs. good style. You will hear your instructor whine and whine about bad programming style all semester. To get them to keep quiet, you should exercise good style. Besides, no one wants to be that person at the programming party on Saturday night.
While the "good" example could be further improved with meaningful variable names and a descriptive comment, it is definitely easier to read than the "bad" example. Whenever you see code like the "bad" example, you should wonder if the person who wrote that code was raised by wolves or not. Chances are, they were.
Instructions
Open the solution file in apps\homework\04_linearInterpolation
.
Hit Ctrl-F5
to "build and run" the provided program. It should compile and run without error. (If it doesn't, ask for assistance.) Move the mouse around and click on the screen. Notice how the interpolated value is always 0. That's not quite right. This program needs improved, such that it actually displays the correct interpolated value.
Add your name in the comment header of main.cpp
.
Now, open the file testApp.cpp
. Read the comment you see, and focus on line 21. That is the only line you must change. Although we haven't talked about functions yet, that's ok. Just pretend that we're "giving" you variables a
, fA
, c
, fC
, and b
. Now, look at the formula for linear interpolation on page 65 of your textbook. Implement the algebraic formula for linear interpolation as a valid C++ expression.
Save testApp.cpp
and re-run your program. If you correctly implement the expression, a blue reticle will appear at the intersection of the two lines, and the application will display the correct interpolated value.
Although this assignment isn't hard, we want you to keep this in your back pocket because you can extend what you will learn here and apply it in a variety of engineering software contexts.
Requirements and Rubric
This work is worth 22 points.
Requirement | Points | Notes |
---|---|---|
Place your name in the comment header in main.cpp | 1 | |
Correct implementation of expression | 16 | |
Proper style / legibility | 4 | |
Correct submission of src directory as a .zip file. | 1 |
Concepts Exercised: talking to the machine, declaring facts, expressions and operators, animation and graphics, application, fun
© 2011 Yong Joseph Bakos.