Author Archives: Salvador García

Creating your own and using C++ libraries

As a programmer you’re going to find out that the libraries in C++ are limited, so sometimes you’re going to need to create your own libraries, this is actually very tricky.

Had to look up for some videos, I’m going to leave the links of a couple of them.

https://www.youtube.com/watch?v=DdNfbcsL-28

https://www.youtube.com/watch?v=t4t26x8IAyA

Once you’ve created your own library, you need to add it to your program file, just as you did in the WSQ of YoSoy196.

In order to call your library you need to type in this “whatevernameyouhave.h” so the program can us the library.

I hope these links and my explanation can be useful.

 

Basic types and their use in C++

First let my show you a screenshot of the basic types in C++, you are going to be using these a lot while programming, there are many others, but these are the basic.

I found this webpage very useful to learn about all the basic types and how you can use them, check it out.

http://www.tutorialspoint.com/cplusplus/cpp_data_types.htm

Nesting of conditional statements


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.

Creating and calling functions in C++

In order to creat a function we need to give it a name first and we need to do that before main, like this:

You need to be clear about whay type of function you are creating, in this case is a boolean, and then followed by the instructions that the function will perform in case you call it.

Now, to call a function you need to type in the name of it, followed by the data that the function will use to work, in this case is “input”, but it can be any data you want, as long as it’s the correct type of data that the function is ready to process.

As you can see here I typed in bool and the name of the function is palindrome, that’s how you call it, I hope this comes useful.

 

Importing and using C++ libraries


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++

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

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++

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

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.

Scilab

It seems like a ver useful tool, for arithmetic functions, if you follow the manual, you can find a few features that might become helpful in the future, such as: graphics, solving equations and many others.

I personally didn’t find it that friendly, because you do have to go trough the manual very carefully, but I guess once you get the hang of it it’s pretty easy.