Difference between revisions of "RPi Education/Manual"
(C++ hello world example) |
m (Hierarchy corrected.) |
||
Line 51: | Line 51: | ||
==Python== | ==Python== | ||
+ | |||
==C/C++== | ==C/C++== | ||
C and C++ are often put together, but are indeed two similar but different languages. | C and C++ are often put together, but are indeed two similar but different languages. | ||
− | =C= | + | ===C=== |
+ | ---- | ||
− | =C++= | + | ===C++=== |
+ | ---- | ||
For starters the famous "Hello world!" example. Save the following code in a file called <tt>helloworld.cpp</tt> in a directory of your choice (e.g. <tt>~/cpp</tt>). The filename can be chosen arbitrarily, but should describe the content. | For starters the famous "Hello world!" example. Save the following code in a file called <tt>helloworld.cpp</tt> in a directory of your choice (e.g. <tt>~/cpp</tt>). The filename can be chosen arbitrarily, but should describe the content. | ||
Line 77: | Line 80: | ||
<tt>cd ~/cpp</tt> | <tt>cd ~/cpp</tt> | ||
− | Make sure with <tt>ls</tt> that you are in the correct directory. It should output <tt>helloworld.cpp</tt> and all other files in this directory. | + | Make sure with <tt>ls</tt> that you are in the correct directory. It should output <tt>helloworld.cpp</tt> and all other files in this directory (if any). |
Now it is time to translate your code so your computer can understand it. This is called compiling. | Now it is time to translate your code so your computer can understand it. This is called compiling. |
Revision as of 05:36, 24 April 2012
Please add any contributions to the educational user manual here. These should take the form of step-by-step guides or listings with descriptions. Alternatively, email your contribution by taking a look at this Raspberry Pi forum posting.
Contents
intro
general
The objective is to educate people in computer science.
hardware
cheap hardware with 1/2 open specifications allow the masses to learn modern computer science.
- plug in your rpi to your monitor with the hdmi and usb cable
- plug in your mouse and keyboard to your monitor
- plug in your monitor power and turn it on.
software
Linux is used, it is open source, user friendly, and technically capable.
language selection
beginners should select a high level language. Advanced users may select different languages combinations depending on the available libraries, programming paradigm, and optimizations.
All code is executed in binary assembled from assembly code compiled from a language sometimes in-turn compiled from other higher level languages.
There are 2 main interfaces for most all applications in linux CLI, and GUI, while GUIs are user friendly CLIs are more simple to build and can be used as building blocks for more complicated tools/toys.
it is considered good programming to use an iterative approach, using existing tools and patterns as much as possible, as such it is customary to start with a hello world:
bash
bash is the language of the terminal.
- open the termonal application
- type: echo Hello world!
That was a computer program,
if you want to learn more about the echo command you can type man echo (press q to quit)
now let's make it a runnable file:
- nano hi.sh
- echo Hello $1!
- [Ctrl]+[x],[y],[enter]
- bash hi.sh Tux
(vim, and gedit are other editors you may with to use.)
python
make a file called hi.py, put print("Hello, world!") in it and run it with python hi.py
now a GUI version:
...//TODO format code in wiki...
beginning
features libraries and limitations
Python
C/C++
C and C++ are often put together, but are indeed two similar but different languages.
C
C++
For starters the famous "Hello world!" example. Save the following code in a file called helloworld.cpp in a directory of your choice (e.g. ~/cpp). The filename can be chosen arbitrarily, but should describe the content.
//Compile with: g++ helloworld.cpp -o helloworld
#include <iostream>
using namespace std;
int main () {
cout << "Hello world!" << endl;
return 0;
}
Open a terminal and switch to the directory, which contains the saved file.
cd ~/cpp
Make sure with ls that you are in the correct directory. It should output helloworld.cpp and all other files in this directory (if any).
Now it is time to translate your code so your computer can understand it. This is called compiling.
g++ helloworld.cpp -o helloworld
If everything went ok, nothing is printed. Now run your program.
./helloworld
This outputs Hello world! on the command line.
Java
intermediate
useful tools and fun toys.
bash
Python
C/C++
perl
Java
Scratch
Greenfoot
Geogebra
advanced
algorithms, heuristics, design patterns, and optimization