Recitation 1
Recitation 1
Recitation 1
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
2. Create and run a simple C++ code as a
part of a project
If you did everything right, a window will pop up and display something
like this.
● If after submission we cannot run your code on the server, you are
likely to lose a good portion of your grade even if your code works
perfectly on your computer.
3. Running your code on a remote server
● Luckily, uploading your code to the server and running it there is
very simple
Download FileZilla and let’s move to the next step. Command prompt is
already available on your pc.
3. Running your code on a remote server
● The server we are going to use is located at Bilkent and is called
Dijkstra. Think of it as a computer somewhere in one of our
buildings which is connected to the bilkent network.
● Again, you don’t need VPN if you are connected to Bilkent network.
3. Running your code on a remote server
● Before this recitation or shortly after, each student taking this
course will receive a unique server ID and password which they will
use to connect to the server.
● With that being said. Lets go and upload our code to the server
using FileZilla, our ID and password.
3. Running your code on a remote server
Open FileZilla. It has 3 sections. The one marked with blue is for establishing connection, the red section is the
contents of your computer and green section is the contents of the server. Because we are not connected yet, the
blue and green sections are empty
3. Running your code on a remote server
Establish a connection. On the upper corner you will see four slots.
Host: dijkstra.ug.bcc.bilkent.edu.tr
Username: yourusername
Password: yourpassword
Port: 22
Here host (dijkstra.ug.bcc.bilkent.edu.tr) is the address of our server on the Bilkent network. And
username and password are the ID details that each individual student received.
Naturally, you need to replace ‘yourusername’ part with the username that you have
been provided for the server. Type the command and press ‘Enter’.
3. Running your code on a remote server
You will be asked to enter a password. As you enter your password you will not see it
being typed on the prompt, it is normal, just type the password and press enter.
If you entered it correctly then you will see something like below. Now you command
prompt is connected to the server.
3. Running your code on a remote server
For example if you now type ‘ls’ you will see same files listed in the command prompt.
Here you can also see the main.cpp file that we just uploaded using FileZilla is visible from prompt.
Let’s compile and run it.
To compile the file, you will use command ‘g++ main.cpp -o my_program’
This command will generate a compiled binary named ‘my_program’ that we will use to run the code.
3. Running your code on a remote server
After you execute the compile command you can actually see my_program binary that
we just created by listing the folder using ‘ls’
Hello World! Is printed. Congrats! You ran your code on the server!
3. Running your code on a remote server
● Okay, now we know how to run a single .cpp file on the server. But
how do we run large projects?
Now run: g++ main.cpp GradeBook.cpp -o my_second_program to generate the binary of this
program. As you might have guessed, when we are compiling a project with multiple cpp files, we
simply type the names of all cpp files instead of a single one. You might have also noticed that
we don’t type the name of .h file. This is because .h files are internally linked with .cpp files and
don’t need to be included in the command. But they need to be present in the same folder.
4. Running a project with multiple header
and cpp files.
Now you simply run you new binary.
4. Running a project with multiple header
and cpp files.
● That’s it. If you reached this point. You are ready to test your code on
the server before submitting it.
● Always make sure that you test your code on the server before you
submit it
● Always make sure that you are ONLY using ‘g++’ compiler.
● Uploading you code to the server is not same as submitting it. Your
code on the server is seen by you and only you. You still need to upload
your code to the Moodle. And that is what we will use for grading.
● Next I will discuss an extra trick that might make your life a bit easier. It
is called Makefile.
5. Briefly about Makefile
● Makefile is often used for making compiling large projects a bit easier.
● You now know that we need to type the names of all of our cpp files
when we compile a project on the server.
● You can imagine how on a project with 10-15 cpp files compile command
might get messy: g++ main.cpp car.cpp house.cpp person.cpp ...
● Green section on the right contains the names of the files you will use to
generate the output
● And the yellow section at the bottom is the really long command that
you don’t want to type over and over again on the command prompt
5. Briefly about Makefile
Save and close the file. After you closed it rename it such that it no longer
has the .txt extension.
You will get a warning. Just press yes. Now upload this file to the server just
as you uploaded your code. After you upload the makefile go to the
command prompt and type ‘ls’ to observe the makefile in the directory.
5. Briefly about Makefile
Now, to execute the same ‘g++ main.cpp Gradebook.cpp -o my_second_output’
command you simply need to type ’make’.
And now your long command has been executed by just typing ‘make’
5. Briefly about Makefile
● But that is outside the scope of this course. But we do encourage you to
read up on the Makefile.
● Instead of running the entire code at once you can watch step-by-step
as each command is being executed