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
‘#Batman’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 05:19:35 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Nesting of conditional IF statements. https://kenscourses.com/tc101fall2015/2015/nesting-of-conditional-if-statements/ Thu, 26 Nov 2015 05:19:35 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=418 Continue Reading →]]> In C++ the braces of and if or an else clause can contain another if statement. There are known as nested if statements.

In simple terms a nested if is when you write an IF inside another IF braces.

This is the basic structure of a nested if.

if( boolean_expression 1)
{
   // Executes when the boolean expression 1 is true
   if(boolean_expression 2)
   {
      // Executes when the boolean expression 2 is true
   }
}

 

And of course we can nest else if in the similar way as you nest the if statement.

This is an example of a program with nested if-else.

#include <iostream>
using namespace std;
 
int main ()
{
   int marks = 55;
   if( marks >= 80) {
      cout << "U are 1st class !!";
   } 
   else {
      if( marks >= 60) {
          cout << "U are 2nd class !!";
      }  
      else {
	if( marks >= 40) {
  	  cout << "U are 3rd class !!";
	}
	else {  
	  cout << "U are fail !!";
        }		  
      }
   }
   return 0;
}

 

And this will be the output:

U are 3rd class !!

 

-The Admin.

]]>
https://creativecommons.org/licenses/by/4.0/
BONUS POINTS! https://kenscourses.com/tc101fall2015/2015/bonus-points-6/ Thu, 26 Nov 2015 04:53:46 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=404 Continue Reading →]]> Well this is a video of myself talking about my experience in Flip learning and how to be succesful in the subject.

I really had a great time with Ken as my teacher and his way of teaching is incredible! I had never been on a class where I feel like the teacher was actually my friend and he helped us a lot through our way in the course.

I highly recommend a flipped class room and even more if you have the opportunity to be with Ken Bauer, he is one of the best teachers that I ever had.

Thanks Ken!

-The admin, Esaú.

PS: Here is the video.

]]>
https://creativecommons.org/licenses/by/4.0/
Final Project! https://kenscourses.com/tc101fall2015/2015/final-project-10/ Thu, 26 Nov 2015 04:39:20 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=386 Continue Reading →]]> We did it!

My buddy and I finally acomplish our project for our TC101 class.

Well, basically, our program had to do the following:

“You will create a command-line program that uses two-dimensional arrays or matrices to process images. You cannot simply call graphics libraries to manipulate the images directly but must implement the functions with your own algorithms. The input to each operation is an image (you choose to support any of JPEG, PNG) and the output is the modified image. The idea is to have a final project which shows your mastery of the topics in this course”.

I was really hard to acomplish but Eduardo and I worked together and we made it!

The user is able to type in the name of the file (a picture) and the program will process the image outputting a different file than the first one.

There is a huge code!

It looks like this:

#include <Magick++.h>
#include <iostream>
#include <cmath>
using namespace std;
using namespace Magick;

void grayscale (string in, string out){
  Image image;
  image.read( in );
  int x = image.rows();
  int y = image.columns();
  Color image_array [x] [y];
  Color original;
  Color graysc;
  int col;


  for (int i=0; i < x; i++){                    
    for (int u = 0; u < y; u++){               
      original = image.pixelColor(u,i); 
      image_array [i][u] = original;
      col = (original.redQuantum() + original.greenQuantum() + original.blueQuantum()) / 3;
      graysc.redQuantum(col);
      graysc.greenQuantum(col);
      graysc.blueQuantum(col);
      image_array [i] [u] = graysc;
      image.pixelColor(u, i, graysc);
    }
  }
  image.write( out );
}

void scale(string in, string out){
  Image image;
  image.read( in );

  int x = image.rows();
  int y = image.columns();
  int xf = x/2;
  int yf = y/2;
  Image image2( Geometry(yf, xf), Color(MaxRGB, MaxRGB, MaxRGB, 0));
  Color image_array [x] [y];
  Color image_array2 [xf] [yf];
  Color pixel1, pixel2, pixel3, pixel4, pixel5;
  int red,blue,green;
  Color newRGB, newRGB2;

  for (int i=0; i < x; i++){
        for (int u = 0; u < y; u++){
              pixel1 = image.pixelColor(u,i);
              image_array [i][u] = pixel1;
        }
  }

  for (int i=0; i < x; i = i+2){
       for (int u = 0; u < y; u = u+2){
       	     int x2 = i/2;
       	     int y2 = u/2;
             pixel2 = image_array [i] [u];
             pixel3 = image_array [i+1] [u];
             pixel4 = image_array [i] [u+1];
             pixel5 = image_array [i+1] [u+1];
             red = (pixel2.redQuantum() + pixel3.redQuantum() + pixel4.redQuantum() + pixel5.redQuantum())/4;
             blue = (pixel2.blueQuantum() + pixel3.blueQuantum() + pixel4.blueQuantum() + pixel5.blueQuantum())/4;
             green = (pixel2.greenQuantum() + pixel3.greenQuantum() + pixel4.greenQuantum() + pixel5.greenQuantum())/4;
             newRGB.redQuantum(red);
             newRGB.greenQuantum(green);
             newRGB.blueQuantum(blue);
             image_array2 [x2] [y2] = newRGB;
       }
  }

  for (int i=0; i < xf; i++){
       for (int u = 0; u < yf; u++){
             newRGB2 =image_array2 [i] [u];
             image2.pixelColor(u, i, newRGB2);
       }
  }

 image2.write( out );
}

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

  try {
 string im;
 string out;
 int ans;
 cout << "Write your file name: ";
 cin >> im;
 cout<< "Write the name of your output file: ";
 cin>>out;
 cout<<"What do you wanna do?"<<endl<<"1. Grayscale."<<endl<<"2. Scale (1/2)."<<endl;
 cin>>ans;

while (ans != 1 && ans != 2){
  cout<<"Try again please: ";
  cin>>ans;}
if(ans == 1){
 grayscale(im, out);}
 if (ans == 2){
 scale(im, out);
}
}
  catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }
  return 0;
//// c++ -O2 -o prog prog.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs`
}

 

There is also a Repository made it in Github and that’s were our teacher is going to check it out.

Any question feel completely free to ask.

Thank you guys for everything.

-The Admin.

 

 

]]>
https://creativecommons.org/licenses/by/4.0/
Creation and use of Strings in C++ https://kenscourses.com/tc101fall2015/2015/creation-and-use-of-strings-in-c-2/ Wed, 25 Nov 2015 23:43:28 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=352 Continue Reading →]]> In this mastery I will talk to you about a really simple topic, “Strings”.

Well, first of all strings are a one-dimensional array of characters which is terminated by a null character ‘’. Thus a null-terminated string contains the characters that comprise the string followed by a null.

The following declaration and initialization create a string consisting of the word “Hello”. To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word “Hello.”

char greeting[6] = {'H', 'e', 'l', 'l', 'o', ''};

 

If you follow the rule of array initialization, then you can write the above statement as follows:

char greeting[] = "Hello";

 

Following is the memory presentation of above defined string in C/C++:

string_representation

Actually, you do not place the null character at the end of a string constant. The C++ compiler automatically places the ‘’ at the end of the string when it initializes the array. Let us try to print above-mentioned string:

#include <iostream>

using namespace std;

int main ()
{
   char greeting[6] = {'H', 'e', 'l', 'l', 'o', ''};

   cout << "Greeting message: ";
   cout << greeting << endl;

   return 0;
}

 

When the above code is compiled and executed, it produces result something as follows:

Greeting message: Hello

 

For any other doubt please feel free to write it in the comments.

Sources:

http://stackoverflow.com/questions/10219225/c-create-string-of-text-and-variables

http://www.cs.fsu.edu/~myers/c++/notes/stringobj.html

-The Admin

]]>
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/
Visualization of Data with Tools https://kenscourses.com/tc101fall2015/2015/visualization-of-data-with-tools/ Wed, 25 Nov 2015 06:55:40 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=313 Continue Reading →]]> A simple and really cool tool and the one that we are going to learn to use is Scilab.

What is Scilab ?

Scilab is free and open source software for numerical computation providing a powerful computing environment for engineering and scientific applications.

What does Scilab do ?

Scilab includes hundreds of mathematical functions. It has a high level programming language allowing access to advanced data structures, 2-D and 3-D graphical functions.

A large number of functionalities is included in Scilab:

  • Maths & Simulation
    For usual engineering and science applications including mathematical operations and data analysis. 
  • 2-D & 3-D Visualization
    Graphics functions to visualize, annotate and export data and many ways to create and customize various types of plots and charts.
  • Optimization
    Algorithms to solve constrained and unconstrained continuous and discrete optimization problems.
  • Statistics
    Tools to perform data analysis and modeling
  • Control System Design & Analysis
    Standard algorithms and tools for control system study
  • Signal Processing
    Visualize, analyze and filter signals in time and frequency domains.
  • Application Development
    Increase Scilab native functionalities and manage data exchanges with external tools.
  • Xcos – Hybrid dynamic systems modeler and simulator
    Modeling mechanical systems, hydraulic circuits, control systems…

 

Where can I get this Software?

As always, just clic on BATMAN.

And also, very important! You will need a beginers guide that will help you out in your familiarization with the program. To download the guide just clic on ROBIN.

Here is a video with basic operations made in Scilab.

-The Admin.

 

]]>
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/
Use of “Switch” as a Conditional. https://kenscourses.com/tc101fall2015/2015/use-of-switch-as-a-conditional-3/ Wed, 25 Nov 2015 04:53:44 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=268 Continue Reading →]]> The syntax of the switch statement is a bit peculiar. Its purpose is to check for a value among a number of possible constant expressions. It is something similar to concatenating if-else statements, but limited to constant expressions. Its most typical syntax is:

switch (expression)
{
  case constant1:
     group-of-statements-1;
     break;
  case constant2:
     group-of-statements-2;
     break;
  .
  .
  .
  default:
     default-group-of-statements
}

 

Basically, what “Switch” actually does is to evaluate expression and checks if it is equivalent to constant1; if it is, it executes group-of-statements-1 until it finds the break statement. When it finds this break statement, the program jumps to the end of the entire switch statement (the closing brace).

If expression was not equal to constant1, it is then checked against constant2. If it is equal to this, it executes group-of-statements-2 until a break is found, when it jumps to the end of the switch. Finally, if the value of expression did not match any of the previously specified constants (there may be any number of these), the program executes the statements included after the default: label, if it exists (since it is optional). Both of the following code fragments have the same behavior, demonstrating the if-else equivalent of a switch statement:

switch example if-else equivalent

switch (x) {

  case 1:

    cout << "x is 1";

    break;

  case 2:

    cout << "x is 2";

    break;

  default:

    cout << "value of x unknown";

  }

if (x == 1) {

cout &lt;&lt; "x is 1";

}

else if (x == 2) {

cout &lt;&lt; "x is 2";

}

else {

cout &lt;&lt; "value of x unknown";

}

 

Here is a simple example of a code with a “Switch” Statement in it.

switch (x) {
  case 1:
  case 2:
  case 3:
    cout << "x is 1, 2 or 3";
    break;
  default:
    cout << "x is not 1, 2 nor 3";
  }

 

Sources:

http://en.cppreference.com/w/cpp/language/switch

http://www.cplusplus.com/doc/tutorial/control/#switch

-The Admin.

]]>
https://creativecommons.org/licenses/by/4.0/
Scilab! The last one. https://kenscourses.com/tc101fall2015/2015/scilab-the-last-one/ Tue, 24 Nov 2015 08:10:15 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=258 Continue Reading →]]> In this WSQ we had to download, install and use a new program called Scilab which is an IDE really usefull because it let you do mathematical operations really easy and also calculate graphics and write lines of code.

I checked out the introduction for beginners and I learned how to use it, it’s actually pretty simple to do the basic things and for the advanced stuff well, I will need more practise.

It is really a usefull tool that I thing will help a lot during my class of math and physics not only because it works as a calculator, but also it can print graphics and you can create your own programs writing the code lines inside the program! That’s awesome.

No doubt Scilab is an excellent tool and I can’t wait to keep practising and descovering new stuff in it.

 

-The Admin.

 

]]>
https://creativecommons.org/licenses/by/4.0/
Final Dash! (FINAL FINAL DASH) https://kenscourses.com/tc101fall2015/2015/final-dash-final-final-dash/ Tue, 24 Nov 2015 07:18:15 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=250 Continue Reading →]]> So! In this post I will schedule all my remaining WSQ’S and Masteries and of course, the project. But, as you can notice, there is not much time left so I took the challenge of doing my remaining 3 WSQ’s including this one and 8 masteries, which I will do In november 24th and 25th and also working in the project at the same time.

I probably won’t get no sleep in a couple of days but hey, sleeping is for the weaks and the procrastinators, I guess.

Anyways, I’m commited to achieve all my assignments, so don’t worry, They will be posted on time!

 

Keep Sleeping and I will be around here doing all my homework!

-The admin.

 

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