I remember doing very simple classes in c++ before but I'm having a lot of trouble understanding this use of class. One that reads from file into an array. I would ask my teacher but he just makes it sound ever more confusing and the book that I'm using doesn't even cover how to use a class this way.
Its suppose to read a city and the average temperature for each city.
Here's a piece of the code he wants us to use:
PHP Code:
#ifndef _ASSIGNMENT_8_CPP_
#define _ASSIGNMENT_8_CPP_
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
class DATA {
private:
char city[20][25];
int temps[20];
int HIGH;
int LOW;
float AVE;
char HIGH_city[25];
char LOW_city[25];
public:
DATA();
void FileRead(char fname[25]);
/* I was taught to do it like "void FileRead(char);". Why is it that way?*/
void FindMax();
void FindMin();
void FindAve();
void ShowData();
void Print();
};
DATA::DATA()
{
//Isn't there suppose to be some code in here?
}
void DATA::FileRead(char fname[25])//Don't understand why "fname" is an array of char
{
ifstream infile(fname);
int i = 0, size = 0;
char temp[32];
while(!infile.eof())
{
infile.getline(temp, 30, ' ');
strcpy(city[i],temp);//Gives me error: " deprecated conversion from string constant to ‘char*’ "
infile.getline(temp, 30);
temps[i] = atoi(temp);
i++;
size++;
}
/*How am I suppose to use this outside of this function?*/
infile.close();
}