Thread: New to Programming

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    New to Programming

    Hi all!

    I'm currently trying to get some experience and understanding of programming in C++ for a University course. I'm a Science student at the moment but i'm hating it and changing over to something along the lines of game design. I suppose that sounds slightly childish or something, but hey it's what i'm interested in.

    I know the course uses C++, but it doesn't start until next year so i've been looking for tutorials such as the ones on this site.

    I'm currently reading this page http://www.cprogramming.com/tutorial/lesson1.html and although i totally understand how to change what the program says (duh), i really don't understand much else.

    For example, what is <iostream>? There's a brief explanation but that's it, and i really don't understand it.

    Is this one of those things where you learn via repetition and experience, or do you use your own intuition? To me it appears as if somebody has pulled the <iostream>, namespace and especially "cout" of of thin air.

    How do i find out about this stuff? How do i know what to use and where? Am i stupid?

    Help would be greatly appreciated!


    Edit: Lovely site and forums you have here too by the way! Thanks!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I'm going to say, don't worry about it.

    Just go with the flow. Follow the tutorials, follow the book... learn what they teach you and don't ask about what they haven't taught you, yet. They will when they know you can learn it. At the point you are in your studying, you're nowhere near ready to be told how cout works. If we told you, we'd just be giving you a couple dozen new words to ask about.

    Just keep doing what you're doing and you'll be fine.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    2
    Thanks for your help! =D I'll do that then. I was feeling a bit like i'd missed 3 pages worth of "pre-course" stuff, but if that is the structure of the tutorials i'll press on.

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Yeah you can't learn whole the things at once. Just
    Follow the tutorials, follow the book... learn what they teach you and don't ask about what they haven't taught you
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Very basic terms, cout is a function declared in the iostream library header file and mainly deals with outputiing results to the screen ( console window ). Via text strings and other things. Cout is also known as an object.
    It is prenounced "CEE-OUT"

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Very basic terms, cout is a function declared in the iostream library header file
    Wrong x 2.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    903
    You just need to know that cout (which really stands for character output) is declared inside the std namespace and is found in the iostream file.

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    The tutorials are a good start, but they are very abbreviated. Get yourself a good beginning book. A beginning book will cover essentially the same material as the tutorial, but in much more depth, detail, and explanation. For example, Accelerated C++ is about 350 pages, and Teach Yourself C++ In 21 Days is over 700 pages.

    Here are a couple of references where you can look-up what's included in <iostream> and the other standard headers.
    Dinkumware.com
    cppreference.com

    At some point, you might get your hands on the ANSI/ISO C++ Language Standard. Of course, it's a very 'technical' document. So, it doesn't make a 'handy' reference. ...It's just something you might want to have before you graduate.

    I was feeling a bit like i'd missed 3 pages worth of "pre-course" stuff, but if that is the structure of the tutorials i'll press on.
    One thing that's missing from most beginning C++ books (and tutorials) is an overview or introduction to programming and how it works in general. They mostly just jump into the particular language syntax. But, you should get plenty of that in school. This isn't really what I was looking for, but I found this once: Introduction To Programming. I was looking for something that talks about variables, loops, and branching, etc. Looping (doing stuff over & over) and branching (decision making... if-statements in C++) are the things that make programming worthwhile!

    I'm a Science student at the moment but i'm hating it and changing over to something along the lines of game design. I suppose that sounds slightly childish or something, but hey it's what i'm interested in.
    Nobody here thinks that's childish! Switching to Computer Science is the wisest decision you could possibly make! There's nothing wrong with doing something you enjoy, especially if you can make a living at it. Besides, people enjoy things that they are good at, and people are good at things they enjoy!
    Last edited by DougDbug; 09-08-2006 at 01:24 PM.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    28
    I know i'll probably get sneered at for suggesting this, but try learning something easier first. I started to learn programming from scratch only a few months back, and my first choice was python.

    Python is a very powerful scripted language with an extremely clear syntax and very easy to pick up. Within a day or so you will be coding simple but useful apps, expanding to more complex projects as your knowledge of the language grows.

    At some point, for various reasons, you may decide to switch to c++ to solve a certain problem. C++ is far more powerful and dynamic than scripted languages like python will ever be. Its ability to combine high-level concepts like object-oriented programming, with the low level abilities of C makes it a great choice for almost any project.

    After learning to program in python a few things didnt make sense to me when making the switch to c++. But I can honestly say that having the previous experience in another (albeit simpler) language has allowed me to pick up c++ much faster than I would have done if learning from scratch. Introducing myself to the very basics like functions, variables, classes, iterators, control structures and data types, allowed me to skip most of this when learning c++.

    Of course this is just my opinion. I am pretty sure many people here would completely disagree.

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I completely disagree.

    Each language has its ups and downs. C++ has a slightly steep learning curve, but once you're over it you're very much home free. Which means only the real Stroustrup fanboys will make it to the advanced level and not some half-jacked script kiddies.

    Python is for scripting, C++ is for programming. They are apples and bananas. Comparing them won't help solve world hunger. In fact, if you're after an interpreted language, I'd suggest Lisp or Scheme.


    Anyway, because your name starts with an N, here's a half-jacked explanation:

    <iostream> is a C++ code file. It is part of the C++ Standard Library, which is basically a collection of commonly used code to make your life easier. In this case, <iostream> provides cout and cin so you don't need to write your own code for input and output. By adding #include <iostream> into your program you will be able to use the I/O code provided.

    But what if your program already used the names "cout" or "cin" for other purposes? So the C++ folks are very nice and place everything in a "capsule" (called a namespace) called std so both the standard names and your own names can coexist in peace and harmony.

    This is a very thoroughly simplified explanation and is technically incorrect in a few places but you will be able to understand the finer details when you learn C++ a bit further in.
    Last edited by jafet; 09-09-2006 at 12:12 AM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  11. #11
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    You should know the "Where should I use it?" before "What is it?". After some time, if you were intrested you can find out "What is it?".
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  12. #12
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Off topic:
    siavoshkc: The yellow text in your sig is impossible to read unless you highlight it or try really hard...

    On topic: Look up Thinking in C++ by Bruce Eckel (http://www.bruceeckel.com I think) it is a 2 part book on C++ from a C programers perspective... but even if you are new to programming I think it is a awesome book, it teaches a lot of stuff I have never seen or is just briefly glossed over in most C++ programming books.

    I have been using C++ for a while now and I still go back and read from that book when I get stuck or need more indepth explinations of things.

  13. #13
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    On topic: Look up Thinking in C++ by Bruce Eckel (http://www.bruceeckel.com I think) it is a 2 part book on C++ from a C programers perspective... but even if you are new to programming I think it is a awesome book, it teaches a lot of stuff I have never seen or is just briefly glossed over in most C++ programming books.
    Really? It makes me happy, because I decided to read it after my current book.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  14. #14
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by Nuro
    I know the course uses C++, but it doesn't start until next year so i've been looking for tutorials such as the ones on this site.
    Realize that the intro tutorials on this site are not that great (so ask for a refund if you want :-)), and a significant difficulty with learning programming is just that so many people/books are bad at teaching it.

    Your discomfort with the way it's covered iostream and how it doesn't say what is /really/ going on should be seen as evidence that you have the right kind of mind for writing programs.

    I think the Python suggestion is a relatively good one. It is much simpler and doesn't contain unnecessary layers of abstraction. (That is, 'unnecessary' from the perspective of teaching a beginner how to think about problem solving.) For example, in C++, cout is an object that sort of abstractly represents an output stream, and the << operator tells the cout object that some particular string of text should be sent to that output stream. In C++, objects are just functions with their own personal internal state, which can be modified. (C++ people use 'function' for a different meaning, though.) An operator is just a function that uses special syntax. Then there's the question of how we know which '<<' operator we are using (and this depends on its arguments' types, its arguments' namespaces, and such), and whether there could be any exceptions we'll want to catch. And let's not even start about memory management.

    In Python, the print command takes a value and prints it out. And that's all you need to worry about. When learning programming, languages like Python or Ruby are like Esperanto -- you'll speak better French if you take a year of Esperanto and 2 years of French than you would with 3 years of French. You'll also be better at C++ programming if you learn Python or Ruby first, and then move to C++.
    Last edited by Rashakil Fol; 09-09-2006 at 02:57 PM.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  15. #15
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    There is really no need to begin with another language I think. It has benefits, but it has downfalls too. When you start learning C++ for the first language, you learn both language and how to solve problems with it. C++ is simple enough to start with.

    Look:
    cout is a stream and you can put some known objects to it and it will put them where it is directed that is usually monitor screen. How? Using << operator: Place cout at left and your object at right and don't forget the semicolon at the end..
    Like:

    cout << "Hi" ; or cout << 23;

    This is so simple. What is cout? It is early for you to know the details. It is just a stream. Take it as simple as it is.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed