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.

22 comments:

  1. God i hate C++. After C# I hope to never go back. I probably will, though. There are some things that C++ simply does better and faster. I just wish it had a prettier syntax.

    ReplyDelete
  2. I hear in some IDE's you can color code text so different kinds of syntax have different colors similar to how eclipse works with Java

    ReplyDelete
  3. haha i love c++, man

    :)

    we have the same major! and we live in the same state! let's follow each other! <3

    ReplyDelete
  4. interesting stuff. hope to read more.

    ReplyDelete
  5. nice man, interesting wish i could understand more :)

    ReplyDelete
  6. and this is why im not a computer major haha

    ReplyDelete
  7. Might need to C++ to my repertoire. You should check out my blog too man. I just got it started.

    ReplyDelete
  8. I had a teacher I couldn't understand, he was portugese. Horrid class :/

    ReplyDelete
  9. Looking forward to more posts. I know how you feel on the whole teacher thing. I took java programming in college and they could barely speak English at all.

    ReplyDelete
  10. Holy moly the most code I know is AutoLisp and that confuses the shit out of me! GL with school!

    ReplyDelete
  11. There's nothing like looking at C++ to make Python look even more majestic.

    ReplyDelete
  12. well that reminds me on school when we had c++ and c#

    ReplyDelete
  13. i had a russian teacher for c++ . i learned nothing , read a good book and thats all you need.

    ReplyDelete
  14. I would like to go to school and learn about internet marketing, specifically SEO work. Do you have any suggestions on courses to take to get into that field?

    ReplyDelete
  15. Pretty sure it's using namespace std;

    don't need a . character. It's not like C#, (in C# you do stuff like using System.Linq)

    ReplyDelete
  16. I like the way you designed your blog :)

    ReplyDelete
  17. Neat stuff, C++ is a great language, but it'll get trickier later. I still don't fully grasp the concept of pointers.

    ReplyDelete
  18. This is really neat stuff you're doing

    ReplyDelete