lab1 - Lab 1 Thursday September 4th and Friday September...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab 1 Thursday, September 4th and Friday September, 5th Activities Basic Linux commands Program creation and compilation Style and Commenting Using the Linux/UNIX operating system (to work in your eng101 directory): 1. Start a terminal window by rightclicking on the desktop then select Open Terminal. You will see a prompt, which is the name of your computer, like this: pierb50XPXX% 2. To display the path of your working directory (or where you are), at the prompt type: pierb50XPXX% pwd Your home directory, where you keep your personal (nonENG101) files, path should be: /afs/umich.edu/user/firstletter/secondletter/uniqname 3. To create a symbolic link to your eng101 directory type: ln s /afs/umich.edu/class/engr101/f08/300/section/uniqname eng101 4. To list the contents of your home directory type: pierb50XPXX% ls 5. To change from your home directory to your Eng101 directory, type: pierb50XPXX% cd eng101 6. Again, type: pierb50XPXX% pwd Your Eng101 directory path should be: /afs/umich.edu/class/engr101/f08/300/section/uniqname 7. To list the contents of your working directory, Eng101, type: pierb50XPXX% ls You should see your project subdirectories and a work directory created for you. 8. To change to your work subdirectory, type: pierb50XPXX% cd work 9. To change back to your Eng101 parent directory, type: pierb50XPXX% cd .. Some useful Linux/UNIX commands: Using the Emacs textbased text editor (to write text files and C++ source code): 1. In a terminal window, type: pierb50XPXX% emacs filename & The & (ampersand) allows Emacs to run in the background. 2. Press <ctrl>+x then <ctrl>+s to save the text to a file. 3. Press <ctrl>+x then <ctrl>+c to exit Emacs. Press <ctrl>+x then <ctrl>+f, then type a filename to open or create a file. Press <ctrl>+g to cancel an Emacs command at any time. Press <ctrl>+h then t to start the emacs builtin tutorial. Other textbased text editors you may try are vim and pico. Using the GEdit graphical text editor (to write text files and C++ source codes): 1. In a terminal window, type: pierb50XPXX% gedit filename & The & (ampersand) allows GEdit to run in the background. 2. Use the menu with the mouse to open, edit, and save your text. Other graphical text editors you may try are kwrite and nedit. Using the g++ compiler (to make executables of your C++ program): 1. In a terminal window, change to the directory that contains your code, and type: pierb50XPXX% g++ filename.cpp o executablename s where "filename.cpp" is the name of the C++ source code ready to be compiled, "o executablename" denotes the outputted executable program name, and "s" strips the executable thus making the executable smaller. ex: pierb50XPXX% g++ myprog.cpp o runmyprog s or ex: pierb50XPXX% g++ myprog.cpp o runmyprog (makes a stand alone executable called runmyprog) ex: pierb50XPXX% g++ myprog.cpp s (executable is named "a.out" by default) 2. To run the compiled C++ program, type the executable name: ex: pierb50XPXX% ./runmyprog (ensures program in working directory is run) or ex: pierb50XPXX% ./a.out (if no executable name was specified at compiling) Using the cp, mv, and rm commands (to copy, move, and remove your files): To copy a file from a source to a destination, type: pierb50XPXX% cp sourcepath/filetocopy destinationpath/newfilename ex: pierb50XPXX% cp myprog.cpp backupdir (simplest usage) or ex: pierb50XPXX% cp myprog.cpp ~/eng101/hw1 (with dest. path) or ex: pierb50XPXX% cp myprog.cpp ~/eng101/hw1/equation.cpp (w/new name) ex: pierb50XPXX% cp ~/myprog.cpp hw2 (with source path from home) or ex: pierb50XPXX% cp ../sample.cpp hw2 (with source path from parent) or ex: pierb50XPXX% cp ../sample.cpp ~/eng101/hw2/mysample.cpp (full usage) To move a file from a source to a destination, replace cp with mv in above examples. Note that moving a file deletes the source file; so use only when necessary. To remove or delete a file, type: pierb50XPXX% rm path/filetoremove ex: pierb50XPXX% rm myprog.cpp (simplest usage) or ex: pierb50XPXX% rm ~/eng101/myprog.cpp (with path) Note that removing a file permanently deletes the file. There is no undelete; so be careful! Using the enscript, lpq, and lprm print commands (to print your text files and C++ code): To print a text file, typically change to the directory that your file is in, then type: pierb50XPXX% enscript options Pprintername path/filename ex: pierb50XPXX% enscript Pb505pierpont myprog.cpp (simplest usage) or ex: pierb50XPXX% enscript 2Gr Pb505pierpont myprog.cpp (with 2column, fancy header, landscape formatting) Printer names can be found on or near the physical printer in any CAEN lab like: b505pierpont, b507pierpont, and b521pierpont. You may also use the nonformatting standard lpr print command instead. ex: pierb50XPXX% lpr Pb505pierpont myprog.cpp To check the print queue, type: pierb50XPXX% lpq Pprintername ex: pierb50XPXX% lpq Pb505pierpont To remove your own print job from the print queue, type: pierb50XPXX% lprm Pprintername jobnumber ex: pierb50XPXX% lprm Pb505pierpont 30 Using additional resources: CAEN provides a good source for additional info on the following topics: Email AFS Communications Printing Databases Connecting to CAEN UNIX Terminal Servers Web Resources Programming Applications Mathematics Text Editors Graphics & CAD and more. Check out both FAQs and software documentation at: http://www.engin.umich.edu/caen/docs . Project submission headings: All source files should include a commented heading up top, using // : Your actual name Your uniqname Eng101, Section #, Your GSI's name Homework # Date Filename of source code Description of program (i.e. title, what it does, inputs, outputs, etc.) Indentation style: Indent where appropriate to make your source code easier to read. You should indent with tabs or a consistent number of spaces inside of: Loop statements (while, for) Selection statements (if/else) Braces { } Commenting: Comment chunks of code with a short description for clarity and modularity. There is no need to comment every single statement. The following should be commented: Nondescriptive variable declarations Nontrivial assignment statements or calculations Loops (while, for) and selection statements (if/else) Userdefined functions ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online