According to a news article on the USA Today web site, the U.S. National Weather Service and Canadian weather authorities modified the formula for calculating the wind chill factor in the Fall of 2001, based on "greater scientific knowledge".
(Link to the article: http://www.usatoday.com/weather/resources/basics/windchill/wind-chill-formulas.htm)
In this exercise, you will modify your previous wind chill program so that it can produce a table of the old wind chill factor, a table of the new wind chill factor, and a table that shows the difference between the two.
Copy your ~/cisc181/lab04/lab04a.cc file to ~/cisc181/lab05/lab05a.cc.
Then
modify
the lab05a file in the following manner:
enum WindChillOption {WCO_NEW = 0,
WCO_OLD = 1,
WCO_DIFF = 2};
This enumeration will be use to control what type of table is printed.
void printTableHeader(WindChillOption opt)
{
switch(opt)
{
case WCO_NEW:
cout << " ****** NEW WIND CHILL FORMULA ******" << endl;
break;
case WCO_OLD:
cout << " ****** OLD WIND CHILL FORMULA ******" << endl;
break;
case WCO_DIFF:
cout << " ****** DIFFERENCE (NEW - OLD) ******" << endl;
break;
default:
cerr << "Unexpected case! Line number "
<< __LINE__ << " in file " << __FILE__ << endl;
exit(-1);
}
}
This function prints a different header for each kind of table that you might
want to print. You pass in one of the values WCO_NEW, WCO_OLD, or WCO_DIFF
to get the kind of header you want.void printTable(WindChillOption opt, int windMin, int windMax, int windStep)
{ ... }
int main(int argc, char *argv[])
{
// initialize from command line arguments; default to 10, 50 and 10
int windMin, windMax, windStep;
windMin = (argc <= 1)? 10 : atoi(argv[1]);
windMax = (argc <= 2)? 50 : atoi(argv[2]);
windStep = (argc <= 3)? 10 : atoi(argv[3]);
// print three tables:
// one for new wind chill
// one for old wind chill
// one showing difference between them
printTable(WCO_NEW, windMin, windMax, windStep);
cout << "\n\n"; // skip a couple of lines
printTable(WCO_OLD, windMin, windMax, windStep);
cout << "\n\n"; // skip a couple of lines
printTable(WCO_DIFF, windMin, windMax, windStep);
return 0;
}
Note that most of the work is done by the functions that you call; the main
is short and sweet; it is like an "outline" of what happens in the program.
double tableEntry(int windMph, int tempF, WindChillOption opt) { switch(opt) { case WCO_NEW: return windChillNew(windMph, tempF); break; ...
> CC lab05a.cpp -o windChill
> ./windChill
****** NEW WIND CHILL FORMULA ******
Temperature (degrees F)
------------+-------+-------+-------+-------+-------+-------+
wind (mph) | 40 | 30 | 20 | 10 | 0 | -10 |
------------+-------+-------+-------+-------+-------+-------+
10 | 34 | 21 | 9 | -4 | -16 | -28 |
20 | 30 | 17 | 4 | -9 | -22 | -35 |
30 | 28 | 15 | 1 | -12 | -26 | -39 |
40 | 27 | 13 | -1 | -15 | -29 | -43 |
50 | 26 | 12 | -3 | -17 | -31 | -45 |
****** OLD WIND CHILL FORMULA ******
Temperature (degrees F)
------------+-------+-------+-------+-------+-------+-------+
wind (mph) | 40 | 30 | 20 | 10 | 0 | -10 |
------------+-------+-------+-------+-------+-------+-------+
10 | 28 | 16 | 4 | -9 | -21 | -33 |
20 | 18 | 4 | -10 | -24 | -39 | -53 |
30 | 13 | -2 | -17 | -32 | -48 | -63 |
40 | 10 | -5 | -21 | -37 | -53 | -68 |
50 | 9 | -7 | -23 | -39 | -55 | -71 |
****** DIFFERENCE (NEW - OLD) ******
Temperature (degrees F)
------------+-------+-------+-------+-------+-------+-------+
wind (mph) | 40 | 30 | 20 | 10 | 0 | -10 |
------------+-------+-------+-------+-------+-------+-------+
10 | 5 | 5 | 5 | 5 | 5 | 5 |
20 | 12 | 13 | 14 | 15 | 17 | 18 |
30 | 15 | 17 | 19 | 20 | 22 | 23 |
40 | 16 | 18 | 20 | 22 | 24 | 26 |
50 | 16 | 18 | 20 | 22 | 23 | 25 |
>
|
In a previous lab, you have seen how to use gnuplot to plot points that you entered by hand using emacs or vi to create a data file (e.g. initials.dat).
Now, you will write a program, lab05b.cpp, to produce a data file containing a five pointed star. Eventually, we want the program to be able to also produce a 6 pointed star, or 7 pointed star, etc.
The star will be contained within a circle centered at the origin, and with a radius of 10 units.
The "top" point of the start will be at the point (0,10), ten units above the origin, right on the y axis. The other four points will be at angles of 360/5 degrees around the circle. You can use trig to determine the x,y coordinates of these points (sin(), cos(), etc.... .remember SOHCAHTOA?) Consult your Deitel/Deitel text on details of using #include <cmath> to access these functions (remembering to use radians rather than degrees).
You'll open an external file inside the C++ program (with ofstream). Call it "star.dat". Then write out the points to this file. Two nested "for loops" should do the trick. The pseudocode is as follows:
for each of five points of the circle (call this point p)
{
for each of the two points other than p and the two points adjacent to p
( call each of these points q)
{
write out a line connecting p to q
write a blank line in the gnuplot file
(so gnuplot lifts the pen)
}
}
When you have finished writing the points, close the output file. You can generate the gnuplot script (star.gnuplot) either by hand editing it in vi or emacs. Even better would be to open it also as an output file, and write it out. Set the xrange and yrange appropriately, e.g. [-10,+10] or [-11,+11] so that the entire star appears in the output. Use star.png as the output file. (Writing it from the program allows you to make the number "10" a constant or a variable that can be modified later to make different size stars. The number of points, 5, is also a number that should be a constant or a #define so that it can be modified later.
What to turn in:
lab05a.cc:
lab05b.cpp:
Total: 100 points.