Im creating a panel bank class,Banks, derived from SolarPanel class.
SolarPanel class is supposed to take a vector of doubles for its parameters.
i had no problem with all these but it seems that the bank.getBankPowerOutput(Years) function crashes every time.
can anyone tell me how to solve this problem?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
double* Banks::getBankPowerOutput(unsigned int Years)
{
unsigned int banksize = m_P.size();
double* bankpower;
double** panelpower;
for(unsigned int i = 0; i < banksize; i++)
{
panelpower[i] = m_P[i].getPowerOutput(Years);
}
for(unsigned int i = 0; i < Years; i++)
{
for(unsigned int j = 0; j < banksize; j++)
{
bankpower[i] += panelpower[i][j];
}
}
return bankpower;
}
|
#include "solar.h"
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
/*SolarArray class*/
//constructor with default values
SolarPanel::SolarPanel()
{
_PowerOutput = 0;
_RatedOutput = 0;
_Efficiency = 1;
_SunTime = 10;
_YearlyReduction = 0;
}
//destructor
SolarPanel::~SolarPanel(){}
//set values for SolarArray
void SolarPanel::setSolarPanel(vector<double> v)
{
_RatedOutput = v[0];
double orientationloss = (100 - v[1])/100;
double tiltangleloss = (100 - v[2])/100;
double wiringloss = (100 -v[3])/100;
double invertereffi = v[4]/100;
_YearlyReduction = v[5]/100;
_SunTime = v[6];
_Efficiency = 1 * orientationloss * tiltangleloss * wiringloss * invertereffi;
}
//get power output over years
double* SolarPanel::getPowerOutput(unsigned int Years)
{
double* power_ptr;
power_ptr[0] = _RatedOutput * _Efficiency * _SunTime * 365;
for(int i = 1; i < Years; i++)
{
power_ptr[i] = power_ptr[i-1] * (1 - _YearlyReduction);
}
return power_ptr;
}
Banks::Banks(){}
//Constructor that takes a vector of variable type of SolarArray
Banks::Banks(vector<SolarPanel> P)
{
m_P = P;
}
//get power out put of panel banks
double* Banks::getBankPowerOutput(unsigned int Years)
{
unsigned int banksize = m_P.size();
double* bankpower;
double** panelpower;
for(unsigned int i = 0; i < banksize; i++)
{
panelpower[i] = m_P[i].getPowerOutput(Years);
}
for(unsigned int i = 0; i < Years; i++)
{
for(unsigned int j = 0; j < banksize; j++)
{
bankpower[i] += panelpower[i][j];
}
}
return bankpower;
}
Banks::~Banks(){}
//This main function asks user to enter basic input in the exact order
//described in the given .txt file
//then generate the power output of a solar array for 25 years of life-span according
//to the data entered by user. It also calculates the average daily power output.
#include <iostream>
#include "solar.h"
#include <cstring>
using namespace std;
int main(int argc, char** argv)
{
double* pwr_ptr;
vector<double> v;
if(argc < 2)
{
SolarPanel a;
cout<<"Please enter the parameters in the order shown"<<endl;
cout<<"Rated output, orientation loss, tilt angle loss, wiring loss, inverters efficiency, declined inefficiency, average sunlight effective"<<endl;
double x;//inputs
for(int i = 0; i < 7; i++)
{
cin >> x;
v.push_back(x);
}
a.setSolarPanel(v);
pwr_ptr = a.getPowerOutput(25);
//print out 1st line
cout<<"Year Total kwh for the Year Average kwh/Day"<<endl<<endl;
for(int i = 0; i < 25; i++)
{
cout<<i+1<<" "<<pwr_ptr[i]/1000<<" kwh "<<pwr_ptr[i]/1000/365<<" kwh/day"<<endl;
}
}else if( argc >= 2 || argv[1] == "-t")
{
//cout<<"Entering the Advanced mode"<<endl;
//cout<<"How many panel banks do you have?"<<endl;
//int NumOfBanks = 1;
//cin>>NumOfBanks;
//4850,5,10,2,97,1.5,5.5
double d[7] = {4850,5,10,2,97,1.5,5.5};
vector<double> v;
unsigned int i = 0;
while(i<7)
{
v.push_back(d[i]);
i++;
}
SolarPanel p;
p.setSolarPanel(v);
vector<SolarPanel> vp;
vp.push_back(p);
vp.push_back(p);
unsigned int size = vp.size();
cout<<size<<endl;
Banks b(vp);
//b.getBankPowerOutput(25);
}
return 0;
}