← ppnm

Exercise "Hello, World!"

Tasks

  1. Install the programming language of your choice on your system.
  2. Create a directory for the exercise inside your repository, let's say "~/repos/ppnm/exercises/hello",

    mkdir -p ~/repos/ppnm/exercises/hello
  3. Go to your directory (remember to use the completion feature of your shell !):

    cd ~/repos/ppnm/exercises/hello
  4. Create a Makefile with the following content (mind the tabulators!) (and you can omit the comments).
    • Makefile for Csharp:
    Out.txt : hello.exe              # Out.txt depends on hello.exe
    	mono hello.exe > Out.txt # run hello.exe, send output to Out.txt
    
    hello.exe : hello.cs             # hello.exe depends on hello.cs
    	mcs hello.cs             # compile hello.cs, save bytecode in hello.exe
    
    clean:                           # a phoney target, no dependencies
    	rm -f Out.txt hello.exe  # remove secondary files
    
    • Makefile for C++:
    Out.txt : hello.exe             # Out.txt depends on hello.exe
    	./hello.exe > Out.txt        # run hello.exe, send output to Out.txt
    hello.exe: hello.cc                 # hello depends on hello.cc
    	clang++ -o hello.exe hello.cc  # compile-and-link hello.cc, save executable in hello.exe
    clean:
    	rm -f Out.txt hello.exe
    
  5. Create a file hello.cs (hello.cc) with the following content,
    • hello.cs:
    class hello{
    static int Main(){
    	System.Console.Write("hello\n");
    	return 0;
    	}
    }
    
    • hello.cc:
    #include<iostream> /* std::cout */
    #include<stdio.h>  /* printf */
    int main(){
    	std::cout << "Hello, ";
    	printf("World!\n");
    	return 0;
    }
    
  6. Run "make" and debug.
  7. Make the progam output "Hello, your-user-name!" where "your-user-name" is your user name.

Hints