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


C++ item::getWeight方法代码示例

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


在下文中一共展示了item::getWeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addWeightAndCount

void inventory::addWeightAndCount(itemNode* node, const item& newItem) {
    if(newItem.getWeight() == node->getWeight()) {
        node->incrementCount();
        _weight += newItem.getWeight();
        _count++;
        newItem.printSuccess();
    }

    else {
        std::cout << "ERROR: tried to add a duplicate item "
                  << "with wrong weight!\n";
    }
    return;
}
开发者ID:mbottini,项目名称:CS260lab1,代码行数:14,代码来源:inventory.cpp

示例2: AddItem

void inventory::AddItem(const item& newItem) {
    // We start by checking the weight to see if it will overload us.
    // If so, we don't do anything and can immediately return.

    if(newItem.getWeight() + _weight > _maxWeight) {
        newItem.printFailure();
        return;
    }

    itemNode *newNode = new itemNode;
    
    if(newNode) {
        newNode->setItem(newItem);
        itemNode *currentNode = _head;
        itemNode *previousNode = NULL;

        // Go to the first node that is greater than newItem.
        // previousNode will either be NULL, (in which case it's
        // at the head of the list) equal to newItem,
        // (in which case it will be incremented)
        // or less than newItem (in which case newNode will be
        // put between previousNode and currentNode).

        while(currentNode && newItem >= currentNode->getItem()) {
            previousNode = currentNode;
            currentNode = currentNode->getNext();
        }

        if(previousNode == NULL) {
            newNode->setNext(_head);
            _head = newNode;
            addWeightAndCount(newNode, newItem);
        }

        else if(newItem == previousNode->getItem()) {
            addWeightAndCount(previousNode, newItem);
            delete newNode;
        }

        else {
            previousNode->setNext(newNode);
            newNode->setNext(currentNode);
            addWeightAndCount(newNode, newItem);
        }
    }

    return;
}
开发者ID:mbottini,项目名称:CS260lab1,代码行数:48,代码来源:inventory.cpp

示例3: incWeight

//Adds the weight of aItem to the inventory's total weight
//Returns whether or not it succeeded.
bool inventory::incWeight(const item& aItem)
{
    //If the new items weight added to the inventory total weight exceeds the
    //MAX_WEIGHT value, return a failure.
    double item_weight = aItem.getWeight();
    if((item_weight + weight) > MAX_WEIGHT)
    {
        cout << "You're not strong enough to pick up the " << aItem << " with everything else you're carrying." << endl;
        return false;
    }
    else
    {
        cout << "You picked up a " << aItem << "." << endl;
        weight+=item_weight;
        return true;
    }

}
开发者ID:chancez,项目名称:CS261,代码行数:20,代码来源:inventory.cpp

示例4: subtractWeightAndCount

void inventory::subtractWeightAndCount(const item& newItem) {
    _weight -= newItem.getWeight();
    _count--;
}
开发者ID:mbottini,项目名称:CS260lab1,代码行数:4,代码来源:inventory.cpp


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