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
‘Programming’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 06:15:08 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Final Project: FINAL https://kenscourses.com/tc101fall2015/2015/final-project-final/ Thu, 26 Nov 2015 06:15:08 +0000 http://alansprogramming.wordpress.com/?p=358 Continue reading Final Project: FINAL ]]> FINAL

It’s over. It’s all over!! “Stress Free Bar” by Jason St. Peter. Link: https://www.flickr.com/photos/fiftypercentchanceofrain/3769770467/

Redundant title is redundant. After much work, tears, sweat and a couple of sleep-deprivation sessions at the Biblioteca, we did it. Messily, and with two codes worth of work, but we did it. Montse had a lot of trouble simply getting the Magick++ library to cooperate with us and it just did not work in my computer. I really have to check it sometime… Anyway, the “good” code is the one titled Final Project.cpp, while the others are alternates with discrepancies (see Week #3). All we have left to do is wait for the reckoning to come.

Here’s the alternate (code for “sucky”) code:

Final1

Final2

Aaaand finally the good and final GitHub code link.

]]>
https://creativecommons.org/licenses/by/4.0/
Masteries 23. and 26. https://kenscourses.com/tc101fall2015/2015/masteries-23-and-26/ Thu, 26 Nov 2015 05:55:05 +0000 http://alansprogramming.wordpress.com/?p=348 Continue reading Masteries 23. and 26. ]]> Mastery 26

Entering the matrix in this moment… and never leaving it. “Matrix Code” by David Asch. Link: https://www.flickr.com/photos/trinity-of-one/20562069/

Description: Creation and use of vectors and matrixes in C++.

The very last one. We are going into the matrix of codes (or the code of matrixes, rather). It’s a bit odd that these masteries find themselves separated by a gap between two other masteries, but that’s just nitpicking. Let’s go ahead and finish this trip.

Video link.

]]>
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/
Masteries 24. and 25. https://kenscourses.com/tc101fall2015/2015/masteries-24-and-25-3/ Thu, 26 Nov 2015 05:02:49 +0000 http://alansprogramming.wordpress.com/?p=337 Continue reading Masteries 24. and 25. ]]> Mastery 25

Pianos are also arrays… kind of. “Piano strings” by Kevin Dooley. Link: https://www.flickr.com/photos/pagedooley/6399773133/

Description: Creation and use of arrays and strings in C++.

Wait, I didn’t know strings were arrays! Just kidding, we have to know all about arrays and strings if we want to make more complicated code, and it’s always useful to know that you can do one thing in more than one way.

That said, I leave you with the video explanation.

]]>
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/
Mastery 10. https://kenscourses.com/tc101fall2015/2015/mastery-10-10/ Thu, 26 Nov 2015 02:14:01 +0000 http://alansprogramming.wordpress.com/?p=292 ]]> Mastery10

Those post-its are amazing aren’t they? “Got Feedback?” by Alan Levine. Link: https://www.flickr.com/photos/cogdog/14279306964/

Description: Basic output (printing) and input (text based) in C++.

Learning to print text in a code and let the user input some more of their own. We understand the andvantages of output and input in this mastery.

Link to video here.

]]>
https://creativecommons.org/licenses/by/4.0/
WSQ14 https://kenscourses.com/tc101fall2015/2015/wsq14-18/ Thu, 26 Nov 2015 00:20:49 +0000 http://alansprogramming.wordpress.com/?p=265 ]]> 14WSQ

2.7176… almost there… almost there. Photo in Creative Commons. Link: https://www.flickr.com/photos/ilike/4920776953/

After having done the #Quiz11, this WSQ was one of the easier ones, even if it took a lot of digging in StackOverflow and cplusplus.com, looking at details of semi-finished code from beginners (like me, obviously) with the same problems as myself.

e’s an awesome number, check the GitHub code link for the WSQ.

]]>
https://creativecommons.org/licenses/by/4.0/
WSQ13 https://kenscourses.com/tc101fall2015/2015/wsq13-25/ Wed, 25 Nov 2015 23:45:44 +0000 http://alansprogramming.wordpress.com/?p=262 GitHub code link

]]>
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/
WSQ12 https://kenscourses.com/tc101fall2015/2015/wsq12-26/ Wed, 25 Nov 2015 23:42:12 +0000 http://alansprogramming.wordpress.com/?p=252 ]]> 12WSQ

I thought fun with numbers was over? “Numbers 7/52” by Janet Ramsden. Link: https://www.flickr.com/photos/ramsd/5445918407/

GitHub code link

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