本文整理汇总了C++中Star::SetRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ Star::SetRadius方法的具体用法?C++ Star::SetRadius怎么用?C++ Star::SetRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Star
的用法示例。
在下文中一共展示了Star::SetRadius方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addStar
void addStar()
{
char name[NAME_SZ] = "";
long temp = 0;
double lumin = 0, mass = 0, radius = 0;
Star *newStar;
if(strcmp(Star::filePath_, "") == 0) //if no file is open, do nothing.
{
cout << "No file to write to, please load a file.\n";
return;
}
cout << "Please enter the following information: \nName: ";
cin >> name;
newStar = new Star(name); //instantiate star with name
if(newStar == 0) //Abort if memory allocation fails.
{
cout << "Memory allocation failed.\n";
return;
}
cout << "Temperature: ";
cin >> temp;
newStar->SetTemperature(temp);
cout << "Luminosity: ";
cin >> lumin;
newStar->SetLuminosity(lumin);
cout << "Mass: ";
cin >> mass;
newStar->SetMass(mass);
cout << "Radius: ";
cin >> radius;
newStar->SetRadius(radius);
linkList.AddLinkToBack(newStar); //add star to linked list
newStar->AppendToFile();
}
示例2: readFromFile
void readFromFile()
{
ifstream inFile;
char name[NAME_SZ] = "";
long temp = 0, starCount = 0;
double lumin = 0, mass = 0, radius = 0;
Star *newStar;
clearStars(); //clear any residual data
cout << "Please enter the file path.\n";
cin >> Star::filePath_;
inFile.open(Star::filePath_);
while(inFile >> name)
{
name[strlen(name)-1] = '\0'; //strips comma from name.
newStar = new Star(name);
if(newStar == 0) //Abort if memory allocation fails.
{
cout << "Memory allocation failed.\n";
break;
}
inFile.ignore(); //ignore coma, name entry actually grabs first comma, all others are caught by ignore()
inFile >> temp; //read temperature
newStar->SetTemperature(temp);
inFile.ignore();
inFile >> lumin; //read luminosity
newStar->SetLuminosity(lumin);
inFile.ignore();
inFile >> mass; //read mass
newStar->SetMass(mass);
inFile.ignore();
inFile >> radius; //read radius
newStar->SetRadius(radius);
inFile.ignore();
starCount++;
linkList.AddLinkToBack(newStar);
}
inFile.close();
inFile.clear(std::ios_base::goodbit); //reset flags to prevent errors on certain compilers
cout << "Successfully loaded " << starCount << " star entries.\n";
}