From the translator. I was searching the Internet for a simple and easily applicable guideline on writing programs in C ++. I liked one of the options, and I decided to translate and publish it. If habra users well meet this topic, I can translate other related documents, as well as guidelines on writing code from other companies.
// ( ), .Line, SavingsAccountline, savingsAccountMAX_ITERATIONS, COLOR_RED, PI int getMaxIterations() // : MAX_ITERATIONS = 25
{
return 25;
}getName(), computeTotalWidth()model::analyzer, io::iomanager, common::math::geometrytemplate<class T> ...
template<class C, class D> ...exportHtmlSource(); // : exportHTMLSource();
openDvdPlayer(); // : openDVDPlayer();::mainWindow.open(), ::applicationContext.getName()class SomeClass {
private:
int length_;
} void setDepth (int depth)
{
depth_ = depth;
}void setTopic(Topic* topic) // : void setTopic(Topic* value)
// : void setTopic(Topic* aTopic)
// : void setTopic(Topic* t)
void connect(Database* database) // : void connect(Database* db)
// : void connect (Database* oracleDB) Point startingPoint, centerPoint;
Name loginName;fileName; // : imyaFaylaline.getLength(); // : line.getLineLength();employee.getName();
employee.setName(name);
matrix.getElement(2, 4);
matrix.setElement(2, 4, value);valueSet->computeAverage();
matrix->computeInverse()vertex.findNearestVertex();
matrix.findMinElement();printer.initializeFontSet();mainWindow, propertiesDialog, widthScale, loginText,
leftScrollbar, mainForm, fileMenu, minLabel, exitButton, yesToggle . .vector<Point> points;
int values[];nPoints, nLinestableNo, employeeNofor (int i = 0; i < nTables); i++) {
:
}
for (vector<MyClass>::iterator i = list.begin(); i != list.end(); i++) {
Element element = *i;
...
}isSet, isVisible, isFinished, isFound, isOpen bool hasLicense();
bool canEvaluate();
bool shouldSort();get/set, add/remove, create/destroy, start/stop, insert/delete,
increment/decrement, old/new, begin/end, first/last, up/down, min/max,
next/previous, old/new, open/close, show/hide, suspend/resume, . .computeAverage(); // : compAvg();cmd command
cp copy
pt point
comp compute
init initialize
. . HypertextMarkupLanguage html
CentralProcessingUnit cpu
PriceEarningRatio pe
. .Line* line; // : Line* pLine;
// : Line* linePtr;bool isError; // : isNoError
bool isFound; // : isNotFoundenum Color {
COLOR_RED,
COLOR_GREEN,
COLOR_BLUE
};class AccessException
{
:
}MyClass.c++, MyClass.hMyClass.h, MyClass.c++class MyClass
{
public:
int getValue () {return value_;} // !
...
private:
int value_;
}totalSum = a + b + c +
d + e;
function (param1, param2,
param3);
setText ("Long line split"
"into two parts.");
for (int tableNo = 0; tableNo < nTables;
tableNo += tableStep) {
...
}#ifndef COM_COMPANY_MODULE_CLASSNAME_H
#define COM_COMPANY_MODULE_CLASSNAME_H
:
#endif // COM_COMPANY_MODULE_CLASSNAME_H#include <fstream>
#include <iomanip>
#include <qt/qbutton.h>
#include <qt/qtextfield.h>
#include "com/company/ui/PropertiesDialog.h"
#include "com/company/ui/MainWindow.h"floatValue = static_cast<float>(intValue); // : floatValue = intValue; int x, y, z;
getCenter(&x, &y, &z);float* x; // : float *x;
int& y; // : int &y;if (nLines != 0) // : if (nLines)
if (value != 0.0) // : if (value)sum = 0; // : for (i = 0, sum = 0; i < 100; i++)
for (i = 0; i < 100; i++) sum += value[i];
sum += value[i];isDone = false; // : bool isDone = false;
while (!isDone) { // :
: // while (!isDone) {
} // :
// }while (true) {
:
}
for (;;) { // !
:
}
while (1) { // !
:
}bool isFinished = (elementNo < 0) || (elementNo > maxElement);
bool isRepeatedEntry = elementNo == lastElement;
if (isFinished || isRepeatedEntry) {
:
}
// NOT:
if ((elementNo < 0) || (elementNo > maxElement)||
elementNo == lastElement) {
:
}bool isOk = readFile (fileName);
if (isOk) {
:
}
else {
:
}if (isDone) // : if (isDone) doCleanup();
doCleanup();File* fileHandle = open(fileName, "w");
if (!fileHandle) {
:
}
// :
if (!(fileHandle = open(fileName, "w"))) {
:
}double total = 0.0; // : double total = 0;
double speed = 3.0e8; // : double speed = 3e8;
double sum;
:
sum = (a + b) * 10.0;double total = 0.5; // : double total = .5;int getValue() // : getValue()
{
:
}for (i = 0; i < nElements; i++)
a[i] = 0;while (!done) {
doSomething();
done = moreToDo();
}while (!done)
{
doSomething();
done = moreToDo();
}while (!done)
{
doSomething();
done = moreToDo();
}class SomeClass : public BaseClass
{
public:
...
protected:
...
private:
...
}void someMethod()
{
...
}if (condition) {
statements;
}
if (condition) {
statements;
}
else {
statements;
}
if (condition) {
statements;
}
else if (condition) {
statements;
}
else {
statements;
} if (condition) {
statements;
} else {
statements;
}for (initialization; condition; update) {
statements;
}for (initialization; condition; update)
;while (condition) {
statements;
}do {
statements;
} while (condition);switch (condition) {
case ABC :
statements;
// "break"
case DEF :
statements;
break;
case XYZ :
statements;
break;
default :
statements;
break;
}try {
statements;
}
catch (Exception& exception) {
statements;
}if (condition)
statement;
while (condition)
statement;
for (initialization; condition; update)
statement;void
MyClass::myMethod(void)
{
:
}a = (b + c) * d; // : a=(b+c)*d
while (true) // : while(true)
{
...
doSomething(a, b, c, d); // : doSomething(a,b,c,d);
case 100 : // : case 100:
for (i = 0; i < 10; i++) { // : for(i=0;i<10;i++){
...doSomething (currentFile);Matrix4x4 matrix = new Matrix4x4();
double cosAngle = Math.cos(angle);
double sinAngle = Math.sin(angle);
matrix.setElement(1, 1, cosAngle);
matrix.setElement(1, 2, sinAngle);
matrix.setElement(2, 1, -sinAngle);
matrix.setElement(2, 2, cosAngle);
multiply(matrix);AsciiFile* file;
int nPoints;
float x, y;if (a == lowValue) compueSomething();
else if (a == mediumValue) computeSomethingElse();
else if (a == highValue) computeSomethingElseYet();
value = (potential * oilDensity) / constant1 +
(depth * waterDensity) / constant2 +
(zCoordinateValue * gasDensity) / constant3;
minPosition = computeDistance(min, x, y, z);
averagePosition = computeDistance(average, x, y, z);
switch (value) {
case PHASE_OIL : strcpy(phase, "Oil"); break;
case PHASE_WATER : strcpy(phase, "Water"); break;
case PHASE_GAS : strcpy(phase, "Gas"); break;
}// ,
// .while (true) { // : while (true) {
// Do something // Do something
something(); something();
} }Source: https://habr.com/ru/post/172091/
All Articles