Tuesday, October 5, 2010

this gif is awesome


Friday, October 1, 2010

Week Two Part Two:

We spent today discussing control flow and conditional statements.  This is a huge part of programming, it allows your program to choose which code to execute based on a given expression.  The instructor reviewed if , if-else, if-else-if, and while statements.

To begin, an if statement looks like this:

if (boolean value)

Let's look at the first line; the function of the keyword "if" is obvious.  Inside the parentheses is any expression that evaluates to a boolean value; if the expression is true the code below in the brackets will execute, if not the code within the brackets is ignored by the computer.

Some examples of expressions that could be used in if statements:
(x > 4)
(age >=  22)
(a == b)  <== a equals b
(c != d)  <== c doesn't equal d
(booleanvalue == true)

If-else statements work the same way except if the conditions of the if statement are not met the code in brackets below the keyword else is executed.

If-else-if statements are very similar to if-else statements except the else has its own condition.  This can be repeated any number of times and can be ended with an else or if-else.  This is very useful when you require multiple conditions leading to multiple outcomes.

The while loop is very useful when you want a block of code to execute more than once if a condition is met.  They normally use a counter to control the number of iterations in the loop.  A counter is just a variable that starts at a given number and is increased by one every time the code in the loop is executed until it reaches a value designated to stop the loop.

Here is a sample program using a while loop:

#include <iostream>
using namespace std;

int main ()
     int count;

     cout << "How many iterations would you like?" << endl;
     cin >> count;

     while ( count > 0)
          cout << "Hello Blogger Community" << endl;
          count = count - 1; //this can also be written count--

     cout << "That is all." << endl;

     return 0;

Notice that there is no semi-colon placed after the declaration of the while loop.  This is also the case for all variants of the if statement.

I hope I'm doing OK with this blog.  Any constructive criticism is more than welcome!

Tuesday, September 28, 2010

Week Two:

Well week two's here and my instructor is just as hard to understand as last week.  I don't even know if I have an American teacher or not this quarter.  It makes me mad that the university hires these people knowing the students won't be able to understand them.

Setting up your program can be a little boring sometimes.  There are a few lines of code that must go at the beginning and end of every program you write.  We haven't learned what it means yet but with my experience I understand what it's doing.

This goes at the beginning of every program: 

#include <iostream>
using namespace std

int main()

This goes at the end of every program:

return 0;

Anyway, one of the main functions of C++ is the console.  Represented by cin or cout, the commands are used to control a program's input and output.  The correct way to pronounce these words is "see-in" and "see-out".

In a typical program, you may see these console commands in code similar to the following:

cout << "Enter your age.\n";
cin >> user_age

Think of cout as your monitor; when you tell the console to output something it will usually be on your monitor.  The arrows represent the flow of data, i.e. taking the string "Enter your age.\n" and sending it to the monitor to be displayed.  The next line takes the user input from the keyboard and stores that value in the variable "user_age".  Notice the arrows are pointing the other way; think of cin as your keyboard, the arrows then point from the keyboard to the variable.

Well there's plenty more to talk about but I have other classes to work on too so I'll be posting more from this lecture very soon.

P.S. I'll make a program out of the examples I used.

#include <iostream>
using namespace std

int main ()
     int user_age, user_bday;
     cout << "Enter your age. \n";
     cin >> user_age;
     cout << "you are " << user_age << " years old." << endl;

     return 0;

If, for example, the user inputs 20 for user_age, the output will be "you are 20 years old."

Note: "\n" (newline) will cause a line break and the next output will be on a new line.  It can also be replaced with the "<< endl" shown above.

Country-Steak: Sauce

I've been playing a lot of Counter-Strike: Source lately and I'm so addicted it's not even funny.  I suck at it too i just can't stop.  What other games do you guys have for Steam that you would recommend? (bonus points for Valve games cause I have all of them)

May the Best Tablet Win

I thought this article might be worth sharing on here.  Even though I think tablets are stupid, I like to read about them so I can tell other people how stupid they are.


Monday, September 27, 2010

Week One:

Well I had two lectures last week and they were pretty boring.  We've just been going over the basics that I've heard a million times: how data is stored, how the CPU and RAM communicate, what the compiler does.  None of it is too important and really won't affect your programs at this point.

Basically, the only important thing that I learned is how to log on to the network allowing me to work in a UNIX Command Line environment through SSH Secure Shell.  Since you're reading this you probably aren't taking this class so you will need to find your own IDE.  Eclipse CDT isn't a bad option http://www.eclipse.org/cdt/.

Now that you have your IDE, you're finished with class.  Party hard this weekend :D