Introductions
Course Logistics
Who is your instructor. Who is your section leader. Role of the website.
Course Policy and CS Department Honor Policy. Computing resources and
course VM.
What is this course about?
This course is an introduction to programming. C++ is the language
we use, but this course is not about learning C++.
It is about learning to program!
"How to program" is bigger than "C++" or any other language.
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. You'll apply your programming skills
to fun graphic stuff next semester: this semester we focus on programming
itself.
Compiled vs interpreted, and why C++ is different than Javascript
You really should review the computer architecture section of SY110.
Here's a link to
the SY110
site.
In SY110, all of you were exposed to Javascript programs. You'll
notice that what we do here feels a lot more low-level, and requires a
lot more discipline. The main reason is that Javascript programs are
executed by the browser, whereas C and C++ programs are actually executed by the
physical machine. This fundamental fact leads to a lot of the differences
you'll observe.
Javascript is an interpreted language. This means that the
code you write is read and processed by the browser, which then executes
the steps demanded by that code.
C and C++ are compiled languages. As shown in the figure below, this
means that the code you write is read and processed by a special-purpose
program called a compiler, which translates it into the zeros and
ones that the CPU speaks, and stores it in an executable file. At some
later point, the OS is told to start the program stored in the executable
file running, and the CPU initiates its fetch-decode-execute cycle on the
code contained in that file.
 |
Step 1: Source code writing.
Use an editor to create the file hello.cpp containing
the source code for the program.
|
 |
Step 2: Compilation.
Use a compiler (g++ in this case) to translate the human-readable
C++ source code into machine-readable object code
hello.o.
|
 |
Step 3: Linking.
Use a linker (g++ does this as well) to combine our object file
hello.o with other object files (like those that take care of
input/output) to create the executable program hello.
|
 |
Step 4: Execution.
Use the OS to initiate execution of (i.e. start the fetch-decode-execute
cycle on) the program hello.
|
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.
Problems
At the end of the notes for almost every lecture will be a couple of
example problems with solutions. Everyone likes to see examples of code,
so that's what we give you!
Do you know ...
- How are Javascript and C++ different?
- What are four steps you need to go through, when you write a program
with the C++ programming language?