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:
Aaaand finally the good and final GitHub code link.
]]>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.
]]>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.
]]>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.
]]>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.
]]>
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.
]]>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.
]]>Well, first of all strings are a one-dimensional array of characters which is terminated by a null character ‘