다음은 내 코드 목록입니다. 친절하게보세요. 옵션 1은 값을 입력합니다. 반면 옵션 5는 값을 표시합니다. 내 프로그램에 문제가 있습니다.값 입력 및 표시
값을 입력하고 표시하는 데 문제가 없지만 정상적으로 표시됩니다. 때 등, 예를 들면 값이 2 세트 I 입력 ..
(1, 1, 타입 O, 1, 1, 1, 1) < - 제 1 세트. (2, 2, 타입 K, 2, 2, 2, 2) < - 두 번째 세트.
그것을 표시
등FIRST DISPLAY (2, 2, 타입 K, 2, 2, 2, 2) & 2ND 디스플레이 (2,2, 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";
}
}