This is a quick tutorial on how to start a new c++ assignment on the department's Linux server. This is not meant to replace any directions given by your instructor or teaching assistant, but to give a general example of what is suggested to be done.
Back to the Top.
This may be confusing for new users, but it is important to be clear on this. There are more than one system that you can do your programming on. It is important to know where you are so that you do not cause any problems for yourself or other users.
There is a server and there are clients in the labs. All of the clients have all the same access to your accounts and files as the server. So programmaticly it should not matter whether you are logged directly into the server or into a client. But whe you do your work on a client your processes are more seperated from other users doing work at the same time, so it is harder for one person to do something wrong and affect all users.
You can tell where your current shell is by looking at your command prompt, usually. By default, the name of the system is part of your command prompt. For example, if your prompt said 'lucas:~ >' then you are currently logged into lucas and if your prompt said 'ewok:~ >' you would be on a client named ewok. If the command prompt is just a '>', you could type echo $HOSTNAME to find what your current system name is.
So, we require users to follow these rules when determining where you need to be when programming:
Back to the Top.
When you start a new program you should create a new directory to keep your files in. This will help as the semester goes on so that you do not start confusing the files in your home directory, trying to figure out what files belong to which project. To do this you want to use the mkdir command. So, for example, we use mkdir lab1 for our first lab assignment.
Once you create the new directory you need to change your current working directory to this new directory. You do this by using the cd command. So from our example you would do cd lab1 and from then on all new files will be in this lab1 directory and not your home directory.
If you are returning to do more work on your assignment, you do not need to re-create your lab1 directory. You can just do your cd lab1 to change to the lab1 directory and start doing your work.
Back to the Top.
Before you start editing your project you should pick a good filename. This is important for the facts that:
So, from our previous example of lab1, you would want to make your main program file lab1.cpp. So if you are using pico as your text editor you would do pico lab1.cpp and type your program in. By naming your main program as lab1 we make it easier when you copy your code from one assignment to another to keep your original code from your modified code. By giving the .cpp extention we tell the C++ compiler that this code is C++. If this was a C program we would name it lab1.c
Back to the Top.
The following file extensions are used on most systems to mean the same thing. Files with no extention are legal in all operating systems, but may not be regonized as the right type of file by the applications that try to run them.
| Extention | Quick Description |
| .c | ANSI C ( or GCC or Visual C ) program |
| .cpp | C++ program |
| .h | Function Header file, defines the functions contained in the program files so that code in other files can find functions in other files. |
| .o | Compiler Object file ( intermediary step in the compile process ) |
| .in | Redirected input into a program. |
| .out | Redirected output from a program. |
| .log | Logged output from a program program exits abnormally |
| .exe | Executable program file ( not needed on *NIX since the --x permission already denotes this ) |
| .dat | Data file |
| a.out | *Special Name* Default exectuable output from a C Compiler. |
| core | *Special Name* Memory dump created for debugging programs when your |
Back to the Top.
The beginning comment blocks are used to identify the file ( because it is not displayed when you print it ), who wrote the file ( because when you submit it many will look similar or the same ), your account name ( so that yor TA or instructor can find you on thier class list either way ) when the project was written ( for your own information, you will not always remember, later )
It is good to get into the habit of doing this now to avoid problems when you do hand in assignments, but also many companies you may work for REQUIRE this on each and every document/code file submitted. If you forget in a work setting, you can get a bad reputation for sloppyness, not get credit for your own work or even face disiplin for failing to follow the rules. So learn now while it just cost you a little off your grade in some classes if you forget.
Back to the Top.
One thing you should do before resume working on a project is to backup your work on this project, before you make any new changes. Do a ls -l to make sure of what you have already. Now do a mkdir bup1 or bup2 or whatever the next available number is. Now you can do a cp * bup1 to copy your projects files into the new directory. You will probably geta message Cannot copy bup1 to itself or something like that. You can ignore this message.
Once you have a backup like this you can go ahead and do your work and if you accidentally ruin your file or feel that you are making negative progress you can copy the same file from the bup1 directory on top of the copy in your project directory.
If you are working on a project for a long time during the same session, or reach critical milestones in your work, you can stop working for a minute and make another backup. This will help if for some reason something goes wrong since you will not have to start over completely from the beginin of your session.
Back to the Top.