//convert sunType to sunTypePercentage
float LocationData::computeCivIndex(string st, int earth, int moons, float particle, float plasma)
{
float sunTypePercent;
if(st == "Type 0")
{
sunTypePercent = 80.0;
}
else if(st == "Type B")
{
sunTypePercent = 45.0;
}
else if(st == "Type A")
{
sunTypePercent = 60.0;
}
else if(st == "Type F")
{
sunTypePercent = 75.0;
}
else if(st == "Type G")
{
sunTypePercent = 90.0;
}
else if(st == "Type K")
{
sunTypePercent = 80.0;
}
else if(st == "Type M")
{
sunTypePercent = 70.0;
}
// calculate CIV Value
float civNum,civNum1,civNum2,civNum3,civNum4,civNum5;
civNum1 = sunTypePercent / 100;
civNum2 = plasma + particle;
civNum3 = civNum2 / 200;
civNum4 = civNum1 - civNum3;
civNum5 = earth + moons;
civNum = civNum4 * civNum5;
return civNum;
}
//display data
void LocationData::displaydata()
{
cout << "suntype: " << sunType << endl;
cout << "earth: " << noOfEarthLikePlanets << endl;
cout << "moons: " << noOfEarthLikeMoons << endl;
cout << "particle: " << aveParticulateDensity << endl;
cout <<"density: " << avePlasmaDensity << endl;
cout << "CIV value: " << computeCivIndex()<< endl;
}
这是我遇到问题的实际代码。对于 computeCivIndex() 函数,它实际上是我的 LocationData.h 文件中公共 LocationData 类下的静态变量,看起来像这样。
静态浮点计算 CivIndex(字符串 st,int earth,int moons,floatparticle,float plasma);
所以为了从函数中检索值我应该这样做吗?
cout << "CIV 值:" << LocationData.computeCivIndex() << endl;