Homework help needed please

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.



snow data.h



#pragma once
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
/*
SnowData specification file
*/
class SnowData
{
private:
string date;
double depth;
public:
SnowData(string _date = "2000/01/01", double _inches = 0);
void print();
string getDate();
double getDepth();
void setDepth(double);
void setDate(string);
};

SnowData.cpp


#include "SnowData.h"

/*
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;
}



->_class tester_<-

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#include "SnowData.h"

void print_array_elements(SnowData[], int);
void sort_by_base_depth(SnowData[], int);
void sort_by_date(SnowData[], int);
double get_average_base_depth(SnowData[], int);
int main()
{
string dates[7] = { "2016/01/15","2016/01/16","2016/01/17","2016/01/18",
"2016/01/19" , "2016/01/20" , "2016/01/21" };
double base_depth[7] = { 34.5, 23.6, 25.5, 31.5, 40.6, 30.9, 38.4 };

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
*/

}
Topic archived. No new replies allowed.