connchri
Daemon Poster
- Messages
- 1,025
- Location
- Scotland, UK
Hello all, long time no, erm, type?
Anyway,
I'm having to do a c++ project for university and it's to simulate the power output of a windfarm.
Long story short, I have created a header file that contains my object template and class functions for my windturbines.
I then want to use this windturbine template/object (sorry, I'm not too hot on the terminology) to create a vector. This vector will be used to represent the windfarm made of a number of turbines.
ie. here's the header file for the turbine:
The function for calculatePower is held in turbine.cpp, but as it's irrelavent for the question I've not included it here.
Here is the line of code form my windfarm class for creating a vector of turbine objects to represent the windfarm (this is held in a test.cpp, as I use that for testing code as I go along):
My question is, is there anyway to access the functions of the turbine class (primerally the setters, getters and calculatepower functions) for a vector element in the vector turb?
I realise I could rewrite my code so that the functions are part of the windfarm class, but I would like to reuse the windturbine code elsewhere in the program and hence avoid this.
Any help would be greatly appreciated.
Cheers,
CW.
Anyway,
I'm having to do a c++ project for university and it's to simulate the power output of a windfarm.
Long story short, I have created a header file that contains my object template and class functions for my windturbines.
I then want to use this windturbine template/object (sorry, I'm not too hot on the terminology) to create a vector. This vector will be used to represent the windfarm made of a number of turbines.
ie. here's the header file for the turbine:
#include <iostream>
#include <string>
#include <math.h>
#define PI 3.14159265
#define AirDensity 1.225
using namespace std;
class turbine
{
private:
string name;
int BladeLength;
int GeneratingCapacity;
float minSpeed;
float maxSpeed;
public:
turbine();
~turbine();
string getName(){return name;}
void setName (string n){name = n;}
int getBladeLength(){return BladeLength;}
void setBladeLength(int a){BladeLength = a;}
int getGeneratingCapacity(){return GeneratingCapacity;}
void setGeneratingCapacity(int b){GeneratingCapacity = b;}
float getminSpeed (){return minSpeed;}
void setminSpeed (float a){minSpeed = a;}
void setmaxSpeed (float a){maxSpeed = a;}
int calculatePower (float Windspeed);
};
#include <string>
#include <math.h>
#define PI 3.14159265
#define AirDensity 1.225
using namespace std;
class turbine
{
private:
string name;
int BladeLength;
int GeneratingCapacity;
float minSpeed;
float maxSpeed;
public:
turbine();
~turbine();
string getName(){return name;}
void setName (string n){name = n;}
int getBladeLength(){return BladeLength;}
void setBladeLength(int a){BladeLength = a;}
int getGeneratingCapacity(){return GeneratingCapacity;}
void setGeneratingCapacity(int b){GeneratingCapacity = b;}
float getminSpeed (){return minSpeed;}
void setminSpeed (float a){minSpeed = a;}
void setmaxSpeed (float a){maxSpeed = a;}
int calculatePower (float Windspeed);
};
The function for calculatePower is held in turbine.cpp, but as it's irrelavent for the question I've not included it here.
Here is the line of code form my windfarm class for creating a vector of turbine objects to represent the windfarm (this is held in a test.cpp, as I use that for testing code as I go along):
vector <turbine> turb(1);
My question is, is there anyway to access the functions of the turbine class (primerally the setters, getters and calculatepower functions) for a vector element in the vector turb?
I realise I could rewrite my code so that the functions are part of the windfarm class, but I would like to reuse the windturbine code elsewhere in the program and hence avoid this.
Any help would be greatly appreciated.
Cheers,
CW.