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

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/feed-rss2.php on line 8
‘MASTERY #24’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 01:59:02 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Creation and use of Tuples and Lists in Python https://kenscourses.com/tc101fall2015/2015/creation-and-use-of-tuples-and-lists-in-python/ Thu, 26 Nov 2015 01:59:02 +0000 http://juansalvadorfernandez.wordpress.com/?p=178 Continue reading Creation and use of Tuples and Lists in Python]]> Both tuples and lists are bundles of data bound together under a single index. The difference radiates in both the syntax and the fact that the tuple is immutable, and the list can be altered.

The difference in syntax between a list and a tuple is that to create a list you use “[ ]” and to create a tuple you use “( )”. Plus tuples are defined as “Heterogeneous data structures” and lists are defined as “Homogeneous sequences that have an order”

The use you most probably will use the tuple as reference data, since the values inside it cannot be modified; the list in the other hand can have the values inside it changed, move around, add new values and eliminate existing ones.

If you remember the mastery about “For” loops, in the example we used a list named “L” containing the values [1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 5]. For that program we could use a tuple as well since the “for” only checks for the value within the list, but it doesn’t modify it.

There are a whole bunch of things you can do with lists and tuples, like splitting and indexing them, for a whole list of the things you can do and how to do them please visit this link: http://www.tutorialspoint.com/python/python_lists.htm

You should be very careful not to use lists instead tuples or the other way around since even if you ARE able to do some things with both without negative results, not all of their functions are the same, tuples are more oriented towards indexing and lists are fore managing data.

Lists and tuples have positions, or spaces, and they store the values they are given in those. Those positions start with 0, then 1, next 2 and so on till they cover the length they are needed. So if you need the value stored in the tenth position of a list, you would need to call for the ninth value, since the counter starts from zero instead of one.

Another important thing is that they can contain any amount of data, and they don’t care about dta types, you can just throw integers, floats and strings inside a list and it will be just fine, just be careful when trying to mess around with the information itself, the list doesn’t have a problem with it but other parts of your code may.

]]>
https://creativecommons.org/licenses/by/4.0/
Creation and use of Arrays https://kenscourses.com/tc101fall2015/2015/creation-and-use-of-arrays/ Wed, 25 Nov 2015 21:47:17 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=332 Continue Reading →]]> C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Instead of declaring individual variables, such as number0, number1, …, and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and …, numbers[99] to represent individual variables. A specific element in an array is accessed by an index.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Declaring Arrays:

To declare an array in C++, the programmer specifies the type of the elements and the number of elements required by an array as follows:

type arrayName [ arraySize];

This is called a single-dimension array. The arraySize must be an integer constant greater than zero and type can be any valid C++ data type. For example, to declare a 10-element array called balance of type double, use this statement:

double balance[10];

Initializing Arrays:

You can initialize C++ array elements either one by one or using a single statement as follows:

double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};

The number of values between braces { } cannot be larger than the number of elements that we declare for the array between square brackets [ ]. Following is an example to assign a single element of the array:

If you omit the size of the array, an array just big enough to hold the initialization is created. Therefore, if you write:

double balance[] = {1000.0, 2.0, 3.4, 17.0, 50.0};

You will create exactly the same array as you did in the previous example.

Concept Description
Multi-dimensional arrays C++ supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.
Pointer to an array You can generate a pointer to the first element of an array by simply specifying the array name, without any index.
Passing arrays to functions You can pass to the function a pointer to an array by specifying the array’s name without an index.
Return array from functions C++ allows a function to return an array.

-The Admin.

 

]]>
https://creativecommons.org/licenses/by/4.0/