Ниже приведен список моих кодов. Пожалуйста, посмотрите.
Вариант 1 - ввод значений. Принимая во внимание, что вариант 5 отображает значения.
Проблема с моей программой.
У меня нет проблем с вводом и отображением 1 набора значений, он отображается нормально.
Когда я ввожу 2 набора значений, например, как ..
(1, 1, Тип O, 1, 1, 1, 1) <- 1-й сет. (2, 2, Тип К, 2, 2, 2, 2) <-
2-й сет. </p>
отображается как
ПЕРВЫЙ ДИСПЛЕЙ (2, 2, Тип K, 2, 2, 2, 2) и 2-й ДИСПЛЕЙ (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";
}
}