当前位置: 首页>>代码示例>>C++>>正文


C++ Star::SetMass方法代码示例

本文整理汇总了C++中Star::SetMass方法的典型用法代码示例。如果您正苦于以下问题:C++ Star::SetMass方法的具体用法?C++ Star::SetMass怎么用?C++ Star::SetMass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Star的用法示例。


在下文中一共展示了Star::SetMass方法的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();
}
开发者ID:cognar,项目名称:CS162A03,代码行数:35,代码来源:main.cpp

示例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";
}
开发者ID:cognar,项目名称:CS162A03,代码行数:41,代码来源:main.cpp


注:本文中的Star::SetMass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。