I need help with my programming homework I been having problems
with for loops with arrays can someone give me examples the details
are located in the class tester.
/*
Overloaded constructor
Parameters used to populate class private variables via set functions
*/
SnowData::SnowData(string _date, double _inches)
{
setDate(_date);
depth = 0;
setDepth(_inches);
}
/*
print functions
prints out class private variables
*/
void SnowData::print()
{
cout << setw(15) << left << date
<< setw(5) << fixed << showpoint << setprecision(2) << right
<< depth << endl;
}
/*
accessor function for snow_date
*/
string SnowData::getDate()
{
return date;
}
/*
accessor function for base_depth
*/
double SnowData::getDepth()
{
return depth;
}
/*
mutator function for base_depth.
ensures that base_depth is not set to a negative value
*/
void SnowData::setDepth(double _inches)
{
if (_inches >= 0)
depth = _inches;
}
/*
mutator function for snow_date
*/
void SnowData::setDate(string _date)
{
date = _date;
}
SnowData snow_days[7];
int i = 0;
for (auto &one_snow_day : snow_days)
{
one_snow_day.setDate(dates[i]);
one_snow_day.setDepth(base_depth[i]);
i++;
}
cout << setprecision(2) << fixed << showpoint;
cout << " --- array after set functions invoked to populate array --\n";
print_array_elements(snow_days, 7);
cout << "Average base depth for the period "
<< snow_days[0].getDate() << " - "
<< snow_days[6].getDate() << " : "
<< get_average_base_depth(snow_days, 7) << endl;
sort_by_base_depth(snow_days, 7);
cout << " --- array after sort by base_depth --\n";
print_array_elements(snow_days, 7);
sort_by_date(snow_days, 7);
cout << " --- array after sort by date --\n";
print_array_elements(snow_days, 7);
return 0;
}
double get_average_base_depth(SnowData _array[], int size)
{
double total_depth = 0;
/*
write code to iterate the array and add up base depth
from each individual array element
RANGE-BASED FOR LOOP CANNOT BE USED!
*/
return total_depth / 7;
}
void print_array_elements(SnowData _array[], int size)
{
/*
Write down the for loop to print out elements from array
RANGE-BASED FOR LOOP CANNOT BE USED!
*/
}
void sort_by_base_depth(SnowData _array[], int size)
{
/*
Write down sort code to sort by base depth of each element in the
array. Use the getBase_depth() function of each array element
*/
}
void sort_by_date(SnowData _array[], int size)
{
/*
Write down sort code to sort by date of each element in the
array. Use the getSnow_date() function of each array element
*/