Weatherreport by ear7

  1. weatherreport.C, weatherreport.txt.
    The program is supposed to output the weather reports for 8 consecutive days. But it has a bug: it never outputs the report for the last day (74, 68, “Mostly Cloudy”). Instead it outputs the reports for the first 7 days, and then repeats the first day.
  2. weatherreport1.C, weatherreport1.txt.
    I corrected the bug. More importantly, I replaced the three parallel arrays (temp_High, temp_Low, forecast) with a single array of structures, named a. We saw an array of structures here. I made the output more legible by printing each weather report in a single line, with the columns lined up.
  3. weatherreport2.C, weatherreport2.txt.
    Now that the data structure is under control, let’s simplify the executable code. Instead of outputting the first weather report in the main function of weatherreport1.C, and the seven remaining weather reports in the weather::nextDay function of weatherreport1.C, I output all eight weather reports in one place (in the main function of weatherreport2.C).
  4. weatherreport3.C, weatherreport3.txt.
    [We haven’t done this in class yet.] I created a five-argument constructor for class weather. Instead of creating one weather object and then updating it seven times, the main function in weatherreport3.C creates a series of seven short-lived weather objects, each one a const. Constants are safer than variables.

A time class by ssood2

Excerpts from time_example.C:

class Time {
public:
	//Declarations for the data members:
	int hour;   //in the range 0 to 23 inclusive
	int minute; //in the range 0 to 59 inclusive
	int second; //in the range 0 to 59 inclusive

	//Declarations for the member functions:
	void print() const; //const member function
	void next(int n);   //non-const member function
	void next();
};
void Time::print() const  //This member function can't change the Time object.
{
	cout << (hour < 10 ? "0" : "") << hour << ":"
	     << (minute < 10 ? "0" : "") << minute << ":"
	     << (second < 10 ? "0" : "") << second;
}

Easier to do it with the i/o manipulators setfill and setw. 'Single quotes' around a value of type char.

#include <iomanip>   //for the i/o manipulators setw and setfill

void Time::print() const  //This member function can't change the Time object.
{
	cout << setfill('0')
                << setw(2) << hour   << ":"
                << setw(2) << minute << ":"
                << setw(2) << second;
}

Class date with a default constructor, and two prev member functions

exercise.C, exercise.txt
The above program is a modification of obj2.C.

obj2.C

//Return a random int in the range small to big, inclusive.

int inrange(int small, int big)
{
	const int n {big - small + 1};  //number of values in the range
	return small + rand() % n;
}

obj2a.C
We saw the keyword static inside of a function in static.C.

Three logical bugs

In ear7’s objRev.C, the day before June 1, 2025 should be May 31, 2025.
objRev2.C, objRev2.txt