以下は私のコードのリストです。どうぞよろしくお願いします。 オプション1は値の入力です。オプション5は値を表示します。 私のプログラムに問題があります。値の入力と表示
1組の値を入力して表示するのに問題はありませんが、通常は表示されます。 場合のような、例えば、値の入力I 2セット..
(1、1、タイプO、1、1、1、1)< - 第1セット。 (2,2、タイプK、2,2,2,2)< - 2番目のセット。それは
第一の表示(2、2、タイプK、2、2、2、2)& 2NDディスプレイ(2,2、BLANK 、0,0,0、のように表示さ
0)。
なぜそうですか? お手数をおかけしていただきありがとうございます。
//DECLARATIONS
MissionPlan m;
int i;
PointTwoD pArray[2];
vector<PointTwoD> point2DVector = vector<PointTwoD>(); // instantiate an empty vector
vector<PointTwoD>::iterator point2DVectorIterator;
PointTwoD point2D;
LocationData locData;
int travdistance = 0;
int OptionChosen;
//OPTION CHOSEN
if (OptionChosen == 1)
{
//declarations
int i=0;
int x, y, earth, moon;
float Particulate, Plasma, civIndex;
string sType;
string mystr;
cout<<"[Input Statistical data] \n";
cin.ignore();
cout<<"Please enter x-ordinate: ";
getline (cin,mystr);
stringstream(mystr) >> x;
cout<<"Please enter y-ordinate: ";
getline (cin,mystr);
stringstream(mystr) >> y;
//cin.ignore();
cout<<"Please enter sun type: ";
getline (cin,sType);
cout<<"Please enter no. of earth-like planets: ";
getline (cin,mystr);
stringstream(mystr) >> earth;
cout<<"Please enter no. of earth-like moons: ";
getline (cin,mystr);
stringstream(mystr) >> moon;
cout<<"Please enter ave. particulate density (%-tage): ";
getline (cin,mystr);
stringstream(mystr) >> Particulate;
cout<<"Please enter ave. plasma density (%-tage): ";
getline (cin,mystr);
stringstream(mystr) >> Plasma;
PointTwoD point2D = PointTwoD(x,y,locData, civIndex=0);
point2DVector.push_back(point2D); // Insert newly formed point2D object to insert into the vector of PointTwoD objects
point2DVector[i].setxCOORD(x);
point2DVector[i].setyCOORD(y);
point2DVector[i].locData.setSunType(sType);
point2DVector[i].locData.setNoOfEarth(earth);
point2DVector[i].locData.setNoOfMoon(moon);
point2DVector[i].locData.setPartDensity(Particulate);
point2DVector[i].locData.setPlasDensity(Plasma);
cout<<"\n";
cout<<"Record successfully stored. Going back to the main menu ... \n";
i++;
}
if (OptionChosen == 5)
{
for(int i=0; i< point2DVector.size();i++)
{
cout << "************************************************ \n";
cout << " DISPLAY INPUT RECORDS \n";
cout << "************************************************ \n";
cout << "x-ordinate: " << point2DVector[i].getxCOORD() << "\n";
cout << "y-ordinate: " << point2DVector[i].getyCOORD() << "\n";
cout << "sun type: " << point2DVector[i].locData.getSunType() << "\n";
cout << "no. of earth-like planets: " << point2DVector[i].locData.getNoOfEarth() << "\n";
cout << "no. of earth-like moons: " << point2DVector[i].locData.getNoOfMoon() << "\n";
cout << "ave. particulate density: " << point2DVector[i].locData.getPartDensity() << "%" "\n";
cout << "ave. plasma density: " << point2DVector[i].locData.getPlasDensity() << "%" "\n";
}
}