Quiz 2 – The smallest number

--Originally published at Programming in C++

This was the second quiz of the partial. For this we had to use functions, arrays, and vector.

quiz2We had 2 vectors with 4 numbers with decimals, and a vector of size 8 and also with decimals. The first functions is for the vectors, and it is simply dine with several ifs. The second one is for the arrays and for this i used a for.

Note: in both cases I assumed the first number given was the smallest one and then compare that one with the rest of the numbers in the vectors or array.

quiz2m


Lists – WSQ07

--Originally published at Programming in C++

For this program we had to ask the user for 10 numbers and saved the in a list. In this case I used arrays, but it can also be done with vectors. And then show to the user the total, average and standard deviation of those numbers.

wsq07f

Here are the 3 functions of the program (one for total, one for average, and one for standard deviation). The only new thing is putting arrays on them. Which is actually simple. You put the name of the array and then the size of it .

 

Now we have the main part:

wsq07m Here we have our array and its size. The size of the array is put between “[ ]”. Then there is a for for inserting the values. When talking about arrays we have to remember that it does not start counting in 1, it starts with 0, so that’s why our i starts there.

wsq07b


Mastery Topics (TC2017)

--Originally published at Programming in C++

First Parcial, Second Parcial, Final

  1. Use of comments

#WSQ03 – Random number

  1. C++ Good Style coding conventions
  2. Basic types and their use
  3. Basic output (print)
  4. Basic user input (text based)
  5. Calling functions
  6. Creating functions
  7. Importing and using libraries
  8. Creating and using your own libraries (program with multiple files)
  9. Use of the conditional “if”
  10. Use of “else” with a conditional if
  11. Nesting of conditional statements (ifs inside ifs)
  12. Use of loops with “while” and “do while”
  13. Use of loops with “for”
  14. Nested loops
  15. Use of recursion for repetitive algorithms
  16. When to use what type of repetition in a program
  17. Creation and use of Arrays/Vectors in C++
  18. Creation and use of strings
  19. Validated user input (ensure correct/expected data entry)
  20. Reading and writing of text files
  21. Matrices and Vectors
  22. Data analysis with tools (to be determined which tool, most likely SciLab)
  23. Visualization of data with tools

Factorial Calculator

--Originally published at Programming in C++

I strugled with this for a while. The first thin I did was the do while, so the program would run several times when indicated with a yes or a no. For this we save the answer with a string (that uses another library called “string”) and then we compare the answer given with yes.

Then comes the tricky part (at least for me), the factorial number. First I tried to usea a for, but it never worked. Then I asked for the help of my friend Ana , you can also go to her blog.

 

 


On To Functions

--Originally published at Programming in C++

1
Operations 

Program:

This program is similar to the first one we did, except we use functions.

How does functions work? For functions we write a part of the code outside our main, and the we call for it in the main.

Basically we did each operation in different pieces, and then we call them when needed.

In this specific program there are more code lines in the function version than in the original, but in bigger program it can be useful.

 

 

2
Our main code calling the operations

Sum of Numbers

--Originally published at Programming in C++

Program:

For this program we have to ask for two range of numbers and the we are going to add the numbers that are in the range.

Imagen2

For this we use a “for”. With the loop “for” we have to put the integer, then the condition, and lastly we sum 1. What this is going is add a number to the variable until it satisfy the condition we put, so it will run for a certain amount of times.

Bash:

Imagen3


Pick a number

--Originally published at Programming in C++

The Program:

 

Imagen1

For this program we use 2 more libraries besides iostream. First we use srand. This is going to give us a random number.

The problem is that it will give us the same random number every time we run it.

To change that we are going to add the library time, this is going to set the random number to the current time, so it won’t give the same number unless you run it at the same second.

We are also going to need a several loops. First we want the program to run every time we insert an incorrect number, for this we use a “while”. Then we use “if” to condition when the given number is too high or too low, and for when the number is actually correct.

I consult K Hong blog. Which explains in a better way the random part. I also found this image about it:

Dilbert_random


Temperature

--Originally published at Programming in C++

 

Tqw02he program uses the formula c=5*(F-32)/ that is just to convert farenheit to celsius

The user insert the temperature in F.

Then the program has to say if the water will boil. For this we use a if. So, if the temperature is bigger than 100 c (celsius>100) the water will boil, and if the temperature is smaller than 100 c (celsius<100) the water will not boil.

The bash should look something like this: qw021

 


Hello world

--Originally published at Programming in C++

This is the basic program (sometimes you don´t even have to do it because it is already done as an example)

hw

 

The program uses one library call “<iostream>”, this library is where you find “cout”, which is the function that shows something.

Note: The program is going to show everytihng between “…” exactly as you put it.

 

Then, to run your program, you need to put g++ then the name of you program.pp. In this case it was helo.cpp. Then you put ./a.out. The bash should show something like this:

hw1