DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
| Code Block |
|---|
#include <iostream>
using namespace std;
namespace ts
{
/**
* @brief Demonstrates how to format code
* This class demonstrates to developers how we should structure code
*/
class Counter
{
public:
Counter():_count(0), _totalCount(0) { }
/**
* @brief Increments the count by one or an optional value
* @param delta The amount to increment the count, default is 1
*/
void increment(int delta = 1) {
_count += delta;
}
/**
* @brief Returns the count value
* @return Count value
*/
int getCount() const { // try to use const as much as possible
return _count;
}
private: // try to hide data
int _count; /// if there is something special to say
int _totalCount;
};
}
/**
* @brief This is the main function for the program
*/
int main()
{
ts::Counter x;
if (x.getCount() == 0) {
x.increment();
} else {
// make sure to always use braces for conditionals
}
// increment the counter 10 times
for (int i = 0; i < 10; ++i) {
x.increment();
}
cout << x.getCount() << endl;
}
|
...