Last active
December 12, 2015 00:18
-
-
Save opavlyshak/4682448 to your computer and use it in GitHub Desktop.
Sample of C++ code convention
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code convention summary: | |
- don't use underscores '_' (except in constants) | |
- lines should not be longer than 100 symbols | |
- indent using EITHER ALWAYS 4 spaces OR ALWAYS Tabs. Don't mix tabs and spaces. | |
*/ | |
#include <string> | |
// Declaration and implementation should be split into "CompanyWorkers.h" and "CompanyWorkers.cpp" files. | |
class CompanyWorkers | |
{ | |
private: | |
static const int INITIAL_WORKERS_COUNT = 0; | |
int workersCount; | |
std::string companyName; | |
bool workerExists(std::string workerName); | |
void registerNewWorker(std::string workerName, int workerId); | |
public: | |
CompanyWorkers(std::string companyName); | |
void addWorker(std::string workerName); | |
void removeWorker(std::string workerName); | |
}; | |
CompanyWorkers::CompanyWorkers(std::string companyName) | |
:companyName(companyName), | |
workersCount(INITIAL_WORKERS_COUNT) | |
{} | |
void CompanyWorkers::addWorker(std::string workerName) | |
{ | |
if (workerExists(workerName)) | |
{ | |
return; | |
} | |
int* pointerToWorkersCount = &workersCount; | |
workersCount++; | |
registerNewWorker(workerName, workersCount); | |
} | |
void CompanyWorkers::removeWorker(std::string workerName) | |
{ | |
bool canRemove = true; | |
for (int i = 0; i < workerName.length(); i++) | |
{ | |
if (workerName[i] == 'x') | |
{ | |
canRemove = false; | |
break; | |
} | |
} | |
} | |
bool CompanyWorkers::workerExists(std::string workerName) | |
{ | |
// implementation here | |
return false; | |
} | |
void CompanyWorkers::registerNewWorker(std::string workerName, int workerId) | |
{ | |
// implementation here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment