User Tools

Site Tools


haas:spring2014:cprog:projects:helloworld

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:spring2014:cprog:projects:helloworld [2014/01/12 18:17] – [Compile the program using gcc] wedgehaas:spring2014:cprog:projects:helloworld [2014/01/27 14:58] (current) – [Verify submission] wedge
Line 1: Line 1:
 +<WRAP centeralign round box>
 +<WRAP><color red><fs 200%>Corning Community College</fs></color></WRAP>
 +<WRAP><fs 150%>CSCS1320 C/C++ Programming</fs></WRAP>
 +</WRAP>
 +
 +~~TOC~~
 +
 ======Hello, World! (first program, and development cycle)====== ======Hello, World! (first program, and development cycle)======
  
Line 70: Line 77:
 As we are to be focusing on learning a particular language this semester (C) As we are to be focusing on learning a particular language this semester (C)
  
-Following is the layout of a typical single-file C program:+Following is the layout of a typical single-file C program (NOTE that this is not something you should type in- it is more of a diagram, and certainly no working program):
  
 <code c> <code c>
Line 126: Line 133:
 It isn't difficult, but needs practice to develop this skill. It isn't difficult, but needs practice to develop this skill.
  
 +=====Preparing a source directory=====
 +Every user on lab46 has their own **src/** subdirectory where they can place files generated through coursework.
 +
 +The purpose of directories is mostly a human satisfying of sanity through organization. While there are mild performance implications, directories help us keep our data sorted (provided we put in the effort to maintain some form of organization).
 +
 +For this reason, we are going to take one more step and create a custom directory for this class (so you can re-use your **src/** directory for additional classes and pursuits).
 +
 +You can name it whatever you want... for this example I will be running with the name "**cprog**".. if you want to use something else feel free (just remember to substitute your name in as appropriate).
 +
 +====Change into src/====
 +First step, we need to change into our **src/** directory (note the prompts):
 +
 +<cli>
 +lab46:~$ cd src
 +lab46:~/src$ 
 +</cli>
 +
 +====Create a cprog subdirectory====
 +Now, we're going to create a directory just for our C/C++ program files:
 +
 +<cli>
 +lab46:~/src$ mkdir cprog
 +lab46:~/src$ 
 +</cli>
 +
 +====Change into your cprog directory====
 +Once created, we can change into it:
 +
 +<cli>
 +lab46:~/src$ cd cprog
 +lab46:~/src/cprog$ 
 +</cli>
 +
 +and voila! If you remember to change into here each time you come to class, or set about working on coursework, all your C/C++ coursework will be nicely organized here (you do not need to recreate the cprog directory-- that only needs to be done once).
 +
 +And, for those really embracing these provided resources, feel free to create additional subdirectories to further organize your code. We'll be creating a lot of programs in here, and even this mild organization isn't enough to ward off a little searching later in the semester as the example programs pile up.
 +
 +=====Text Editor=====
 +Text editors can be a matter of great personal preference.
 +
 +Ultimately, they are a fundamental program development tool, for they handle the various low-level file operations, enabling you to place desired content in specified files.
 +
 +If you are entirely new to lab46 (and don't know any better), I would recommend the use of the **nano** text editor. It works in a manner consistent to other text entry programs you are likely accustomed.
 +
 +To open **nano** on a new or existing file, merely specify the file name after the editor on the command-line. In this example, we will be creating a new file called **hello.c** in our current working directory:
 +
 +<cli>
 +lab46:~/src/cprog$ nano hello.c
 +</cli>
 +
 +nano is a full screen editor, you'll notice a status bar on the top of the screen, and commands listed on the bottom few rows (<nowiki>^X</nowiki> means to press and hold the **CTRL** meta key and then hit the "X" key.. this particular example will let you save and exit).
 +
 +If you have experience in UNIX on the command-line and know of/prefer other editors, feel free to use them.
 +
 +For those also taking UNIX, you'll be learning the **vi** text editor, and I would encourage you to use it in as many settings as possible to aid you in your UNIX coursework (if you are not taking UNIX do not concern yourself with **vi**, it is a powerful editor that works according to a different philosophy).
 =====Hello, World====== =====Hello, World======
 For our purposes here, we will be writing our first program, which is also considered a classic. For our purposes here, we will be writing our first program, which is also considered a classic.
Line 189: Line 251:
   * http://en.wikibooks.org/wiki/C_Programming/Compiling   * http://en.wikibooks.org/wiki/C_Programming/Compiling
  
-The nature of compilers themselves can warrant entire courses unto themselves. If you go on in Computer Science, at the 3rd/4th year or graduate level it is not uncommon to encounter "Compiler Construction" course.+The nature of compilers themselves can warrant entire courses unto themselves. If you go on in Computer Science, at the 3rd/4th year or graduate level it is not uncommon to encounter "Compiler Construction" course. 
 + 
 +====Familiarize yourself with file states==== 
 +Before we get to actually compiling, you may want to take a look at the existing state of your working directory, so that you can see the results of your actions. 
 + 
 +At this point, you should have just finished typing in your first program (**hello.c**), saved it, and exited from your text editor and be sitting at a lab46 prompt: 
 + 
 +<cli> 
 +lab46:~/src/cprog$  
 +</cli> 
 + 
 +At this point we are going to run the UNIX command **ls**, which will list all the files in the current directory (your **~/src/cprog/** directory). Depending on any previous or outside activity, you may have additional files kicking about. 
 + 
 +<cli> 
 +lab46:~/src/cprog$ ls 
 +hello.c 
 +lab46:~/src/cprog$  
 +</cli>
  
 ====Compile the program using gcc==== ====Compile the program using gcc====
 The compiler on Lab46 is the GNU C compiler (**gcc** command). The compiler on Lab46 is the GNU C compiler (**gcc** command).
  
-To use it on a single file, in this case named **hello.cc**, to create an executable named **hello**, we would run the following at the prompt:+To use it on a single file, in this case named **hello.c**, to create an executable named **hello**, we would run the following at the prompt:
  
 <cli> <cli>
Line 208: Line 287:
  
 Running the **ls** command before and after running **gcc** should show the lack and then presence of the executable. Running the **ls** command before and after running **gcc** should show the lack and then presence of the executable.
- 
 =====Executing your compiled program===== =====Executing your compiled program=====
 At this point you should have written your first program in a text editor, saved it, compiled it successfully, and now await the moment of truth- running the very program you just wrote. At this point you should have written your first program in a text editor, saved it, compiled it successfully, and now await the moment of truth- running the very program you just wrote.
Line 219: Line 297:
 lab46:~/src/cprog$ ./hello lab46:~/src/cprog$ ./hello
 Hello, World! Hello, World!
-lab46:~/src/cprog$+lab46:~/src/cprog$ 
 </cli> </cli>
  
Line 226: Line 304:
 Now we just have to learn all the various keywords and language rules, and familiarize ourselves with the necessary library functions to pull off even more spectacular solutions to problems. Now we just have to learn all the various keywords and language rules, and familiarize ourselves with the necessary library functions to pull off even more spectacular solutions to problems.
  
-You may want to place your C source code (**hello.c**) in a repository for safe keeping- working with repositories is another helpful programming habit to have.+You will want to place your C source code (**hello.c**) in a repository for safe keeping- working with repositories is another helpful programming habit to have. 
 + 
 +=====Submission===== 
 +To successfully complete this project, the following criteria must be met: 
 + 
 +  * Code must compile cleanly (no warnings or errors) 
 +  * Executed program must display the intended message, exactly as presented, to STDOUT. 
 +  * Output must be correct (as per project specifications) 
 +  * Code must be nicely and consistently indented (you may use the **indent** tool) 
 +  * Code must be commented 
 +    * have a properly filled-out comment banner at the top 
 +    * have at least 5% of your program consist of **<nowiki>//</nowiki>**-style descriptive comments 
 +  * Output Formatting (including spacing) of program must conform to the provided output (see sample program output above). 
 +  * Track/version the source code in a repository 
 +  * Submit a copy of your source code to me using the **submit** tool. 
 + 
 +To submit this program to me using the **submit** tool, run the following command at your lab46 prompt: 
 + 
 +<cli> 
 +$ submit cprog helloworld hello.c 
 +Submitting cprog project "helloworld": 
 +    -> hello.c(OK) 
 + 
 +SUCCESSFULLY SUBMITTED 
 +</cli> 
 + 
 +You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. 
 + 
haas/spring2014/cprog/projects/helloworld.1389550674.txt.gz · Last modified: 2014/01/12 18:17 by wedge