Comments


Comments

It is possible to write notes inside a program to provide additional information to the person who is reading the program. These lines are called comments and are ignored by the computer. Do not use comments to explain something obvious in the program.
Es posible escribir notar dentro del programa para proporcionar información adicional a la persona que está leyendo el programa. Estas líneas se llaman comentarios y son ignoradas por la computadora. No se comentarios para explicar algo obvio en el programa.

Comment Types

There are two types of comments: single line and multiline. Single line comments begin with // and end where the line ends. Multiline comments begin with /* and end with */
Hay dos tipos de comentarios: de una línea y de varias líneas. Los comentarios de una sola línea empiezan con // y terminan cuando termina la línea. Los comentarios de varias líneas comienzan con /* y terminan con */

CommentTypes

Debug Comments

When a program has many errors, it is possible to divide the program in small segments. To do this, all program lines are converted to comments by adding // at the beginning of each line. Then, the programmer can gradually remove the comments (uncomment) from the lines until each error is found. Because it is easier to find an error when the program has few lines, this method is extremely useful. As a matter of fact, most IDE (such Microsoft Visual Studio and others) have a pair of buttons to comment and uncomment a group of lines. Even though when the compiler provides the line number and error description, commenting and un-commenting lines is very useful for correcting code.
Cuando un programa tiene muchos errores, es posible dividir el programa es pequeños segmentos. Para hacer esto, todas las líneas de código se convierte a comentarios agregando // al principio de cada línea. Entonces, el programador puede gradualmente remover los comentarios (descomentar) de las líneas hasta que cada uno de los errores es encontrado. Porque es más fácil encontrar un error cuando el programa tiene pocas líneas, este método es extremadamente útil. De hecho, la mayoría de las IDE (tales como Microsoft Visual Studio y otras) tiene un par de botones para comentar y descomentar un grupo de líneas. A pesar de que el compilador proporciona el número de la línea y una descripción del error, comentar y descomentar líneas es muy útil para la corrección de código.

Problem 1
Use Debug Comments to correct the code shown below.
Use los comentarios de depuración para corregir el error en el código.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int x = 50
     douvle y = 100,0;
     bool isBig + true;
}

Step 1
First, we convert to comments the second and third lines by adding // at the beginning of these lines. When the program is compiled, it tells that a semicolon is missing. The, we add a semicolon at the end of the first line.
Primero, se convierten a comentarios la segunda y tercera líneas agregando // al principio de estas líneas. Cuando se compila el programa, este indica un punto y coma faltante. Se agrega, entonces un punto y coma al final de la primera línea.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int x = 50
     //douvle y = 100,0;
     //bool isBig + true;
}

Step 2
We remove the comments from the second line. Then, we fixed this line: double y = 100.0;
Se remueven los comentarios de la segunda línea. Entonces, se corrigen esta línea: double y = 100.0;

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int x = 50;
     douvle y = 100,0;
     //bool isBig + true;
}

Step 3
We remove the comments from the third line. Then, we fixed this line: bool isBig = true;
Se remueven los comentarios de la tercera línea. Entonces, se corrigen esta línea: bool isBig = true;

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int x = 50;
     douvle y = 100,0;
     bool isBig + true;
}

Dividing Comments

When writing several lines of code one after the other, it is difficult to read and understand the code. In these cases, a separator comment with some text at the right can greatly alleviate the reading of the code. The figure below shows how to use dividing comments.
Cuando se escriben muchas líneas de código uno después de la otra, es difícil de leer y entender el código. En estos casos, un comentario separador con algo de texto a la derecha puede facilitar grandemente la lectura del código. La figura de abajo muestra cómo usar los comentarios para dividir el código.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     //___________________________ Input Data
     double a = 5.0;
     double b = 15.0;
     double c = 10.0;
     //__________________________ Computation
     double discr = b*b - 4*a*c;
     double x1 = (-b + sqrt(discr)) / 2 * a;
     double x2= (-b - sqrt(discr)) / 2 * a;
}

Problem 2.
Indicate whether or not comments are properly used.
Indique si los comentarios son usados apropiadamente.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int temperature = 25; //Here we set the temperature to 25
     double weight = 50.0; //Here we set the weight to 50
}

Problem 3.
Indicate whether or not comments are properly used.
Indique si los comentarios son usados apropiadamente.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int temperature = 25; //A semicolon goes at the end of each line
     double weight = 50.0;
}

Problem 4.
Indicate whether or not comments are properly used.
Indique si los comentarios son usados apropiadamente.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int temperature = 25; // Celsius
     double weight = 50.0; // Kg
}

Problem 5.
Indicate whether or not comments are properly used.
Indique si los comentarios son usados apropiadamente.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     int x = 25; // x represents the temperature in Celsius
     double y = 50.0; // y represents the weight in Kg
}

Problem 6.
Indicate whether or not comments are properly used.
Indique si los comentarios son usados apropiadamente.

Program.cpp
void Program::Window_Open(Win::Event& e)
{     
     //___________________________________________
     int x = 25;
     //___________________________________________
     double y = 50.0;
     //___________________________________________
}

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home