Skip to main content
 
 
 

Nesting of conditional statements

Nesting of conditional statements

At this point we already know how to use conditionals, but we can have one conditional inside the other. This is in order to have several options of answers of the program in use, or many other options.
This is very useful because with only con conditional there's no much place to work, but you can add as many conditions as you want to your code, and the posibilities are huge.
In my example there are two conditions, one to let you know that you passed, and the other, in case your grade is above 9 points, it congratulates you.
It's very easy to do and it will be coming handy.

 

Importing and using C++ libraries

Importing and using C++ libraries

Libraries are very important in the use of C++ language, they let you use the functions you need for each program.
You need to call the library at the beggining of the code, I added this example because I needed several libraries on this program.
You can call the library that you need by typing "#include" and then the name of the library between "". The example is very clear.

 

Reading and writing of files in C++

Reading and writing of files in C++

To open o create a file in C++, first you must be sure to add the proper library which is , as you can see, in my example the first command in main is "ofstream file", that's to create a file inside your program. Later I name it as Hello.txt, and in there you can put in whatever you want, I just typed in a line that said "Hello dudes", and that text file will remain with that line unless I erase it. After that you just close your file.

 

Use of recursion for repetitive algorithms

Use of recursion for repetitive algorithms

Recursion means that a function is calling itself to acomplish the condition given before, this is very useful when we need a number or sum to have a limit, that way we can give the program an instruction on when to stop adding.
In my example I just put in a countdown.
As you can see there is a "recur(n-1)" thing there, that means that the number given, is going to be reduced by one until zero is reached.

 

Validated user input in C++

Validated user input in C++

As a programer sometimes it is necessary, to validate a user entry into a program, there is a ver easy way to do that using if and else, you can also do it with do and while, but my example consists of the first, so I'm going to explain that one.
As you can see I used a string as the correct user name, if the username is not the same as the one I the I gave to the string, it will show "Usuario incorrecto", that's how validation works, I hope this was helpful.

 

Vectores

Vectores

Un vector es muy similar a un array, pero tiene muchas más posibilidades, como cambiar de tamaño, y cambiar los datos dentro de la lista, si comienzas a usarlo, te darás cuenta de que es una herramienta muy usada en C++.
Incluyo un ejemplo para que sepan como usarlo.
Se inicia con el código vector, para después declarar que tipo de vector será, en este ejemplo es un "double", y los valores que nos está dando para llenar el vector son calificaciones de estudiantes.

 

Bonus quiz

Bonus quiz

Do your it helps the teachers to improve.

 

Estimating e

Estimating e

Here's my code