My class is having us make a class in a separate header file, use the prototypes in a separate cpp file from where main is. The data has to be read from another file that the teacher will create and store those values into the class. I am having troubles getting my code to understand what is going on.
Here is my header file, I think everything here is alright because I am not getting errors connected straight to this file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin;
class Month_Info
{
private:
float rainfall,
hi_temp,
lo_temp,
average_temp;
public:
void set_values (Month_Info, ifstream &fin);
}
|
Here is the file that I am trying to use the function from the prototype in the header file. I am getting errors and I will post those after the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include "cMonthlyRainfall.h"
using namespace std;
void set_values (Month_Info month[], ifstream &fin)
{
int count = 0,
i = 12;
for (count = 0, i = 12; count <= month[i]; count++)
{
fin >> month[i].rainfall;
fin >> month[i].hi_temp;
fin >> month[i].lo_temp;
}
}
|
The errors that I am getting are as follows:
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|11|error: expected unqualified-id before 'using'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp||In function 'void set_values(Month_Info*, std::ifstream&)':|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|18|error: no match for 'operator<=' in 'count <= *(month + ((unsigned int)(((unsigned int)i) * 16u)))'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.h|19|error: 'float Month_Info::rainfall' is private|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|20|error: within this context|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.h|20|error: 'float Month_Info::hi_temp' is private|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|21|error: within this context|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.h|21|error: 'float Month_Info::lo_temp' is private|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|22|error: within this context|
||=== Build finished: 8 errors, 0 warnings ===|
Here is my main cpp, it is not pretty yet but I haven't finished it. I know it breaks so many rules of coding but here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include "cMonthlyRainfall.h"
using namespace std;
int main()
{
ifstream fin;
fin.open ("weather.dat");
if (!fin)
{
cout << "ERROR: Unable to find weather.dat";
return 1;
}
Month_Info month[12]; //Creates an object for each month
Month_Info::set_values (month, fin);
return 0;
}
|