"How to program" is bigger than "C++" or any other language. Programming is a creative process, in which you construct a model world inside the computer that interacts with the real world via keyboards, mice, monitors, speakers network connections, and so forth. It's very rewarding and exciting; you will never be bored!
This course focuses on solid understanding of foundational concepts, so please be patient with the fact that your programs will usually be reading and writing text and not interacting with all the fancy peripherals mentioned above.
In summary, frustration will always be with you, so welcome it with your open arms. Remember that you are learning something new, whenever you get frustrated. However, if you think you're too frustrated, you must seek help. It's your responsibility to seek help. It's our responsibility to help you with all our might when you seek help.
|
← This "includes" code needed to use the "standard library" iostream.
Libraries are repositories of compiled C++ code that we can use in
our own programs. iostream provides input/output functionality.
← This allows us to use shorter names for standard library objects.
For example, without this line we have to write "std::cout" rather
than simply "cout". The line is saying "just assume the 'std::'
part".
← The "main" function. For now, all our C++ code goes in between
these { }'s.
← "cout << x" is how we write output. The right-hand side can be
almost any expression. "std::cout" is the full name of the output
stream associated with the terminal. "cout << endl" sends a
newline to the output stream.
← A program actually returns a number to the command shell that
launched it. Returning 0 is like saying "this program exited
normally".
|
Some more comments follow:
;".
cout << x
The object x can be either a number or a string (a string is a sequence of
characters).
For short, you can print several things out in a single "cout" statement
by separating them with "<<", like this:
cout << "I am " << 44*12 + 3 << " months old!" << endl
![]() |
Step 1: Planning.
Think about what your program should do and plan how you are going to write it. For many simple programs this part will be pretty obvious, but when you start to write bigger programs, it might be the most important step! |
![]() |
Step 2: Source code writing.
Use an editor to create the file |
![]() |
Step 3: Compilation.
Use a compiler (g++ in this case) to translate the human-readable
C++ source code into machine-readable object code
|
![]() |
Step 4: Linking.
Use a linker (g++ does this as well) to combine our object file
|
![]() |
Step 5: Execution.
Use the OS to initiate execution of (i.e. start the fetch-decode-execute
cycle on) the program |
All these steps are kind of a pain in the neck, but remember: we're writing a program that is executing on "bare metal", i.e. directly on the CPU.