Skip to main content
 

Sudoku

1 min read

We are almost done with the final project, but we had a little set back with the board printing, so we talked to Ken today, so that we could get some questions answered on regards to our code. He will check out our code and tell us what we are missing so that we can get a good grade on this .

I'll include our Github link so that you can check what Alan and I have been doing.

https://github.com/kenwbauer/SalvadorAlan

 

Use of "switch" as a conditional

1 min read

This switch thingy is a very useful tool, because instead of nesting many conditionals, you can be very specific, on the response of the program in which case.

As you can see you can add as many cases as you want, but you need to add "break" at the end, if not the default answer will also show up, that why when I typed in 3 goals, it shows the two answers.

If you get the hang of this tool, you will have many posible solutions for coding issues you may find.

 

Creating your own and using C++ libraries

1 min read

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

1 min read

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

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

1 min read

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

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.