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 23’ 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 Vectors in C++ https://kenscourses.com/tc101fall2015/2015/creation-and-use-of-vectors-in-c-2/ Wed, 25 Nov 2015 06:25:49 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=292 Continue Reading →]]> A vector is a container in the C++ Standard Library (a bunch of stuff which sort of comes “bundled” with C++) which is essentially just an array that can grow and shrink in size. These things have been highly optimized and tried and tested for several years, and as such are generally considered a standard when creating C++ applications.

Vector Constructors.

The available constructors for a vector are given by:

1	vector<int> testVector;
2	vector<long> testVector(10);
3	vector<float> testVector(5,1.0);

 

The first syntax declares an empty vector capable of storing the integer datatype. The second declares a vector with storage space for 10 long integers, each of which is initialized to the default value for the type. The final line declares a vector with storage for 5 floats, and initializes each of their values to 1.0. Any valid type can be used for any of the constructors.

There is also a copy constructor for the std::vector class. The following code creates a vectors of integers with 10 copies of the number 5, and duplicates the vector into a new one using the copy constructor:

01	#include <iostream>
02	#include <vector>
03	 
04	using namespace std;
05	 
06	int main(int argc, char** argv) {
07	     
08	    vector<int> vectorOne(10,5);
09	     
10	    vector<int> vectorTwo(vectorOne);
11	     
12	    return EXIT_SUCCESS;
13	}

 

Accessing Elements of a Vector.

There are a number of ways to access the elements of a vector. For the moment, I will focus on two of them, one safe and one unsafe. And as a reminder, C++ vectors (and other STL containers), like raw C/C++ arrays, are accessed with indices starting at zero. This means that the first element is at position 0 in the vector, and the last element is at position (number of elements)-1.

The vector class contains a member function at() for accessing individual elements of a vector. This is the safe way of accessing elements, since attempting to access an element beyond the valid range will cause an exception to be thrown. However, the raw data stored in the vector can still be accessed using the usual [] operator, just like in a raw array. Unfortunately, just like with a raw array of data, overrunning the end of the vector using the [] operator can cause weird and unexpected things to occur, such as program crashes or unexpected results. It may also return garbage data that follows the meaningful data of the vector, which has the potential to be disastrous if it is used in subsequent operations. The following two code snippets demonstrate each of these access methods:

Safe access version:

#include <iostream>
#include <vector>
using namespace std;
 

int main(int argc, char** argv) {
     
    /*  Initialize vector of 10 copies of the integer 5 */

    vector<int> vectorOne(10,5);
     
    /*  Display size of vector */

    cout << "Size of vector is " << vectorOne.size() << " elements." << endl;
     
    /*  run through the vector and display each element, using size() to determine index boundary */

    for (long index=0; index<(long)vectorOne.size(); ++index) {

        cout << "Element " << index << ": " << vectorOne.at(index) << endl;
    }

    return EXIT_SUCCESS;
}

 

Unsafe access version

#include <iostream>
#include <vector>
 
using namespace std;

 
int main(int argc, char** argv) {
     

    /*  Initialize vector of 10 copies of the integer 5 */
    vector<int> vectorOne(10,5);
     

    /*  run through the vector and display each element, if possible */

    for (int index=0; index<20; ++index) {

        cout << vectorOne[index] << endl;

    }
    return EXIT_SUCCESS;
}

 

Sources:

http://www.cplusplus.com/reference/vector/vector/vector/

http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm

-The Admin.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery 23 y 13 https://kenscourses.com/tc101fall2015/2015/mastery-23-y-13/ Sat, 31 Oct 2015 00:00:12 +0000 http://fernyalanis.wordpress.com/?p=71

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