本文整理汇总了C++中SpreadsheetCell类的典型用法代码示例。如果您正苦于以下问题:C++ SpreadsheetCell类的具体用法?C++ SpreadsheetCell怎么用?C++ SpreadsheetCell使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpreadsheetCell类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
SpreadsheetCell myCell;
myCell.setValue(6);
return 0;
}
示例2: invalid_argument
SpreadsheetCell operator/(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
if (rhs.getValue() == 0) {
throw invalid_argument("Divide by zero.");
}
return SpreadsheetCell(lhs.getValue() / rhs.getValue());
}
示例3: invalid_argument
SpreadsheetCell operator/(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
if (rhs.mValue == 0)
throw invalid_argument("Divide by zero.");
SpreadsheetCell newCell;
newCell.set(lhs.mValue / rhs.mValue); // call set to update mValue and mString
return newCell;
}
示例4: main
int main()
{
SpreadsheetCell myCell(4), anotherCell(5);
SpreadsheetCell aThirdCell = myCell.add(anotherCell);
cout << aThirdCell.getValue() << endl;
return 0;
}
示例5: main
int main()
{
SpreadsheetCell* myCellp = new SpreadsheetCell();
myCellp->setValue(3.7);
cout << "cell 1: " << myCellp->getValue() <<
" " << myCellp->getString() << endl;
delete myCellp;
myCellp = nullptr;
return 0;
}
示例6: main
int main()
{
// Using the default constructor
SpreadsheetCell myCell;
myCell.setValue(6);
cout << "cell 1: " << myCell.getValue() << endl;
// The next line will crash when compiled with SpreadsheetCellInitListBackward.cpp
SpreadsheetCell myCell2("6");
auto smartCellp = make_unique<SpreadsheetCell>();
// Or with a naked pointer (not recommended)
SpreadsheetCell* myCellp = new SpreadsheetCell();
// ... use myCellp
delete myCellp;
myCellp = nullptr;
return 0;
}
示例7:
bool operator>(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
return (lhs.getValue() > rhs.getValue());
}
示例8: SpreadsheetCell
SpreadsheetCell operator*(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
return SpreadsheetCell(lhs.getValue() * rhs.getValue());
}
示例9: printCell
void printCell(const SpreadsheetCell& inCell)
{
cout << inCell.getString() << endl;
}
示例10:
SpreadsheetCell operator*(const SpreadsheetCell& lhs, const SpreadsheetCell& rhs)
{
SpreadsheetCell newCell;
newCell.set(lhs.mValue * rhs.mValue); // call set to update mValue and mString
return newCell;
}
示例11: main
int main()
{
// On the stack (destroyed when out of scope)
SpreadsheetCell stackCell, stackCell2; // Omit parentheses for the default constructor
stackCell.set(6);
stackCell2.set("3.2");
cout << "stack cell 1: " << stackCell.getValue() << endl;
cout << "stack cell 2: " << stackCell2.getValue() << endl;
// Constructor on the stack
SpreadsheetCell stackCell3(4.2), stackCell4(9.2);
cout << "stack cell 3: " << stackCell3.getValue() << endl;
cout << "stack cell 4: " << stackCell4.getValue() << endl;
// On the heap
SpreadsheetCell* heapCell = new SpreadsheetCell();
heapCell->set(3.7);
cout << "heap cell 1: " << heapCell->getValue() << endl;
delete heapCell;
heapCell = nullptr;
// Constructor on the heap
auto heapCell2 = new SpreadsheetCell(44);
cout << "heap cell 2: " << heapCell2->getValue() << endl;
delete heapCell2;
heapCell2 = nullptr;
// Smart pointers for the heap
auto smartCell = make_unique<SpreadsheetCell>();
smartCell->set(3.14159);
cout << "smart cell 1: " << smartCell->getValue() << endl;
// Constructor with for pointer to the heap
auto smartCell2 = make_unique<SpreadsheetCell>(42);
cout << "smart cell 2: " << smartCell2->getValue() << endl;
// Manual heap delayed instantiation
SpreadsheetCell* heapCell3 = nullptr;
heapCell3 = new SpreadsheetCell(55);
cout << "heap cell 3: " << heapCell3->getValue() << endl;
delete heapCell3;
heapCell3 = nullptr;
// Array instantiation requires a default constructor (as to STL collections)
const int size = 3;
SpreadsheetCell cells[3];
SpreadsheetCell* moreCells = new SpreadsheetCell[10]; // HEAP!
// Stack arrays can use an initializer for non-default constructors
SpreadsheetCell stackCells[3] = {
SpreadsheetCell(3),
SpreadsheetCell(4),
SpreadsheetCell(5)
};
for (int i = 0; i < size; i++) {
cout << "arr cell " << i << ": " << cells[i].getValue() << endl;
cout << "heap arr cell " << i << ": " << moreCells[i].getValue() << endl;
cout << "stack arr cell " << i << ": " << stackCells[i].getValue() << endl;
}
delete[] moreCells; // CLEAN THE HEAP!
moreCells = nullptr;
// Copy
auto copyCell = SpreadsheetCell(stackCell);
cout << "copy cell: " << copyCell.getValue() << endl;
// Initializer-List Constructor
// EvenSequence p1 = {1.0, 2.0, 3.0, 4.0, 5.5, 7.7}; // or
EvenSequence p1 {1.0, 2.0, 3.0, 4.0, 5.5, 7.7};
p1.dump();
try {
EvenSequence p2 = {1.0, 2.0, 3.0};
} catch (const invalid_argument& err) {
cout << err.what() << endl;
}
// std initializer list
vector<string> myVec {"Hello", "World"};
for (auto value : myVec) {
cout << value << endl;
}
// Done
return 0;
}
示例12: SpreadsheetCell
SpreadsheetCell SpreadsheetCell::operator+(const SpreadsheetCell& cell) const
{
return SpreadsheetCell(getValue() + cell.getValue());
}