Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#Mastery24’ Articles at TC101 Fall 2015, Page 2
Introduction to Programming Python and C++

Tag Archives: #Mastery24

Masteries 23 & 24

Creation and use of vectors in C++
Creation and use of arrays in C++

Tuples


      A tuple is a sequence of values that are nested into one function. These elements can be strings, number, and even tuples. You can have many types of elements within the same tuple, for example:


Colors = (‘red’, ‘blue’, ’yellow’ )

Numbers = ( 1, 2, 3 )

List = ( 4, (5, 6))

Other = ( ‘red’, 2, (5, 6) )


      As you can see, tuples are pretty much like a list; what differentiates them is that tuples cannot be mutable. For creating a tuple you need to establish the name of the tuple followed by an equal sign (which means ‘assignment’). After the equal sign you start naming the elements included in the list. These elements are nested inside parenthesis () and separated by commas. If the element being established is a string, it needs to be between quotation marks.


     For printing the whole tuple you type the command print() and between the parenthesis you type the name of the tuple. For printing just one element of the tuple you type the command print() and between the parenthesis you type the name of the tuple followed by the number of the element between square brackets.


NOTE: The elements on a tuple are numbered starting from 0


     For knowing how many elements a tuple contains, you can use the command len(), between the parenthesis you type the name of the tuple.


     Also, you can add one tuple to another and create a new tuple. For that, you need to type the name of the tuple you are creating followed by an equal sign, followed by the name of the first tuple and the addition sign followed by the second tuple you will adding.

Masteries 24 and 27 – Creation and use of tuples and diccionaries

 A tuple is like a list and is used in the same way, the only difference is that a tuple cannot be modified or changed.A diccionarie is a colleccion of anything that can be labeled with any other thing. It is used as a list too but to use a slot i…

An array is used when we need to handle similar types of data….

An array is used when we need to handle similar types of data. It is defined as a sequence of variable that can store value of one particular data type. To define an array, we use this guide:
type   array_name[size];
For example, if we want to make an array to enter the age of 5 people, we write it like this:
int   age[5];
The resulting array can be represented the first image of the top. 

This array has 5 elements in it, but notice that the first element in the array is age[0]. This is true for any array we create. Also, we can initialize an array at the time of declaration. This means, we can enter the data that goes in each element since we declare the array, for example:
int   age[5]  =  {12,  16,  7,  14,  10};
Example: Program to store 5 numbers entered by the user in an array and display first and last number only. (Second image on the top)

Mastery 24

On this mastery I will show you what are arrays in C++ and how to use them.

Arrays are some sort of lists that can be input by the user, stored in the program, and then used in the program in order to do something with them later. This may sound pretty similar to how variables work, but the difference with arrays is that you just have to state the values that will be used inside the array instead of making tons of variables. For example, if you want the user to input 5 variables, you just need an array of size 5, instead of declaring variable1, variable2, variable3,

variable4, and

variable5.

An array needs a type (chech out mastery 9 where I talk about types) a name and the number of elements that will be inside of it. Arrays are written: type name [elements].

Now, let’s create a program that allows the user to input 5 elements inside the array and then make a sum and an average of the elements inside the array. So, do as follows:

  1. Create our “basic program”
  2. Declare two variables of type float (this will allow us to have non-integer numbers as the result) with initial value= 0
  3. Create an array of type float with 5 elements (or as many you want). Remember, float NAME[# of elements].
  4. Let the user input the values by calling your array beginning the count of the elements in 0. (cin >> NAME[0]; cin >> NAME[1]; … cin >> NAME[4];) 
  5. Create a for loop (like we learned on mastery 20) that will add the values of the array and will display the total.
  6. Calculate the average (average = total/5)
  7. Print the variables, they will now display a value.

Your program should look something like this:

image

Now let’s run the program:

image

Great! Now you know what are arrays and how to use them, congrats!

#Masteries23,24,25

Creation and use of vectors in C++
Creation and use of arrays in C++
Creation and use of strings in C++

#Mastery24 -Creation and use of arrays in C++

Hey there! This is that is about the creation and the usage of arrays in c++. Arrays are different numbers with the same type placed in separate spaces. It is like to fill drawers with information to use them after. This is used instead of declaring individual variables.

 

Let´s say you want the program to ask for 10 various numbers separately and then get the total of them, in this case you can use arrays. The only “disadvantage” of using an array is that you have to define the number of values to introduce.

Using arrays is easier than it sounds.

 

To understand its use, it is better to imagine them as boxes you are saving info into:

 

0

1

2

3

4

5

6

7

8

 

 

 

 

 

 

 

 

 

 

An array starts it´s count from the box number 0. Declaring an array is as easy as declaring some other thing. The structure of an array is like this:

 

type  nameofarray [number of spaces];

 

       An array can be any type just as a normal variable, but it is a arrangement of variables.

       You can choose whichever name you want for your array.

       The number in between the squared braces [ ] is to set the number of values introduced in the array.

       The number of spaces in the array has to be an integer because it is a whole unit space.

 

The elements of an array can be used to be introduced by the user of the program, or you can type them after declaring in between braces= { }.

 

Then when you want to use the values already stored inside an array, you have to simply type the nameofarray[ number of space of the value]. Be aware that the space number 0 counts as a space.

 

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}
table.MsoTableGrid
{mso-style-name:”Tabla con cuadrícula”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:39;
mso-style-unhide:no;
border:solid windowtext 1.0pt;
mso-border-alt:solid windowtext .5pt;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-border-insideh:.5pt solid windowtext;
mso-border-insidev:.5pt solid windowtext;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

WATCH MY VIDEO https://youtu.be/XekmFL6VBwI

Masteries 23 y 24: creation and use of vectors and arrays

Hey there! Here is my video for #Mastery23 and #Mastery24:

Mastery 24: Creation and use of arrays in C++

Hi there… here is the video: https://youtu.be/UXQVmYoCK8Y Thanks for watching!!! n_n

MASTERY 24: Creation and use of arrays in C++

I like arrays better than vectors and here’s a ppt exaplaining them! So if you don’t know how to use vectors, try with arrays instead. MASTERY 24 I hope you enjoy it!!

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).