Implementing classes in python
<p>Hey this is one of the classes that I had for homework in my cs class and now i'm playing around with python. I want to learn how to design classes in python and would like to implement this one. It's a relatively straight forward class. Help would be appreciated. Here's the code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;

using namespace std;

int num_flights=0 ;
const int Columns_Total = 14; /*the total columns are 14 for each flight*/


class Flight
{
public:
Flight();
void major_calc(string&amp; filename,ifstream&amp; is,string&amp; line, ofstream&amp; os);
    void print (ofstream&amp; os);

private:
vector&lt;vector &lt;double&gt; &gt; store;
int num_lines;
double avg_wind_speed;
double avg_height;
double avg_tempr;
double std_dev_speed;
double std_dev_height;
double std_dev_tempr;

  };

 Flight::Flight()
 {

 }

  void Flight::major_calc(string&amp; filename,ifstream&amp; is, string&amp; line, ofstream&amp; os)
   {    num_lines=0;

vector &lt;double&gt; single_line;  /* Vector to one test line of a flight*/
vector &lt;double&gt; flight_height; /* Vector stores the heights associated with all the test lines for a particular flight*/
vector &lt;double&gt; flight_wind_speed; /* Vector stores the wind speeds  associated with all the test lines for a particular flight*/
vector &lt;double&gt; flight_tempr; /*  Vector stores the temperatures  associated with all the test lines for a particular flight*/

while(getline(is,line))
{   
if (line.substr(0,3) == "ACM") /* Checks a new flight */
{
    num_flights++;
    os &lt;&lt; line &lt;&lt; endl;
    return ;

}
else 
{
    istringstream iss(line,istringstream::in);  /* Reading the string*/
    double FieldInfo;
    num_lines++;  /* updating the counter*/
    for (int n=0; n&lt;14; n++)
    {
        iss &gt;&gt; FieldInfo;
        single_line.push_back(FieldInfo);
    }

    store.push_back(single_line);

    flight_height.push_back(single_line[4]); /* Updates the height vector with the value from a particular test line*/
    flight_wind_speed.push_back(single_line[3]); /* Updates the wind speed vector with the value from a particular test line*/
    flight_tempr.push_back(single_line[8]);/* Updates the temperature vector with the value from a particular test line*/

}

    single_line.clear(); /* Empties the single line vector so it can be used again*/

}


double temp1=0; /* temporary variables used to calculate the average height, average speed and average temperature*/
double temp2=0;
double temp3=0;

for (int i=0; i&lt; flight_height.size();i++)
{
    temp1+= flight_height[i];
    temp2+= flight_wind_speed[i];
    temp3+= flight_tempr[i];
}

avg_height= temp1/(flight_height.size());
avg_wind_speed= temp2/(flight_wind_speed.size());
    avg_tempr= temp3/(flight_tempr.size());   


double sqr=2.0; /* Temporary variables used to calculate std deviation associate with the speed, height and the temperature*/
double temp4=0;
double temp5=0;
double temp6=0;

for (int i=0; i&lt; flight_height.size();i++)
{
    temp4+= pow((flight_height[i]-avg_height),sqr);
            temp5+= pow((flight_wind_speed[i]-avg_wind_speed),sqr);
            temp6+= pow((flight_tempr[i]-avg_tempr),sqr);
}

std_dev_height= sqrt(temp4/flight_height.size());
std_dev_speed= sqrt(temp5/flight_wind_speed.size());
    std_dev_tempr= sqrt(temp6/flight_tempr.size());
    }

  void Flight::print (ofstream&amp; os)
  {
os&lt;&lt;"printing the results out"&lt;&lt;endl;           /* Printing out all the values*/
os&lt;&lt;"avg speed: "&lt;&lt;avg_wind_speed&lt;&lt;"knots"&lt;&lt;endl;
os&lt;&lt;"avg height: "&lt;&lt;avg_height&lt;&lt;"feet"&lt;&lt;endl;
os&lt;&lt;"avg tempr: "&lt;&lt;avg_tempr&lt;&lt;"celcius"&lt;&lt;endl;
os&lt;&lt;"std dev in height: "&lt;&lt;std_dev_height&lt;&lt;"knots"&lt;&lt;endl;
os&lt;&lt;"std dev in speed: "&lt;&lt;std_dev_speed&lt;&lt;"feet"&lt;&lt;endl;
os&lt;&lt;"std dev in temperature: "&lt;&lt; std_dev_tempr&lt;&lt;"celcius"&lt;&lt;endl;
os&lt;&lt;"The number of lines "&lt;&lt; num_lines&lt;&lt;endl;

 }


   int main()
   {        
string filename;
    string line;
cout&lt;&lt;"Enter the filename"&lt;&lt;endl;
cin&gt;&gt;filename;
ifstream is;
    is.open(filename.c_str()); /*open the file*/
bool FileDoesntExist = is.fail();

if(FileDoesntExist) /*checks if the file exists*/
{
cout &lt;&lt; "File doesn't exist" &lt;&lt; endl; 
exit(1);
}

string fileout = filename.substr(filename.rfind(".")+1,filename.length()) + ".log"; /*making the ouput file */
ofstream os (fileout.c_str());

vector &lt;Flight&gt; complete;
while(!is.eof())
{
    Flight test;
    while(getline(is,line))
    {
        test.major_calc(filename,is,line,os);
        test.print(os);
    }
    complete.push_back(test);
}


return 0;
</code></pre>

<p>}</p>
