Table of Contents

Logan Merrill's Fall 2011 Opus

C/C++ Musings from a Blind Computer User

Version 1.5.0, last updated on 9/27/2011 at 9:17 PM

Introduction

Hello, and thank you for dropping by my opus. I am a visually impaired college student and have been working with computers and technology for as long as I can remember. My key interests in the computer and technology fields include:

  • Designing, developing, upgrading, and maintaining Web sites and Web applications
  • Writing, testing, and repairing computer software applications
  • Providing technical support in person, over the phone, or via online communication methods
  • Hosting Web sites and Internet radio stations
  • Discovering new ways to use and benefit from assistive technology for the blind and visually impaired, including software applications like JAWS for Windows and hardware devices like the Icon and Braille+

I have worked extensively with Windows, Mac, and Linux operating systems, including Windows 98, ME, 2000, XP, Vista, and 7, Mac OS X 10.6 (Snow Leopard) and 10.7 (Lion), and Linux distributions that include CentOS, Fedora, Red Hat Enterprise Linux, Ubuntu, and Vinux. I also have experience in the Visual Basic and C# programming languages on the desktop platform, as well as PHP, HTML, and CSS on Web platforms and shell scripting on Unix and Linux platforms. Furthermore, I have also done extensive work with computer repair, including installing, troubleshooting, and upgrading software and operating systems, providing over-the-phone, in person, and online technical support, and working with other technical support specialists in a corporate environment.

When not working with computers and other technology, I like to spend my time reading, listening to music, writing music, or playing the drums or piano. I also enjoy various sports, especially those designed specifically for blind and visually impaired individuals, including Goalball and beep baseball. When not working on assignments at Corning Community College, I usually spend a good portion of my time involved with Airshock LLC, a company I started back in March 2011. At Airshock, we focus on providing high-quality, affordable, and professional Web and media services to the online community. These include Web design, Web hosting, Internet radio hosting, audio production, and many other useful tools and services. We also have a software development division in charge of creating engaging open source software for Windows, Mac, iPhone, and Android. For additional information about any of our services, or to see what we can do for you or your business, please contact us today by calling (607) 527-0803, e-mailing admin@airshock.net, or checking out our shopping cart at https://clients.airshock.net/cart.php. You may also follow us on Twitter at www.twitter.com/airshockllc or find us on Facebook by searching for “Airshock LLC.”

Thank you for taking the time to review my opus. Please feel free to contact me if you have any questions or concerns regarding the information contained in this document, or if you would like to learn more about me or about Airshock LLC. You may reach me by e-mail at admin@airshock.net, or you can also follow me on Twitter at www.twitter.com/neosonic2, find me on Facebook at www.facebook.com/neosonic2, add “neosonic2” as a contact on Skype, or send “neosonic2” an instant message on AIM.

Part 1

Entries

September 5, 2011

Welcome to the first entry in my opus. On this day, which happened to be a day during which Corning Community College was closed, I got my first real glimpse into the course by reviewing the course syllabus and completing the first assignment, “task 0.” The completion of this assignment also doubled as the only really significant thing that I did today as far as course work is concerned, but since the assignment was very straightforward I don't really have any questions about it, and didn't run into any problems while completing it.

I also established my Lab46 SVN repository today as well as became a member of the class mailing list, although problems with my Lab46 e-mail account prevent me from actually interacting with the list until said problems are resolved.

September 10, 2011

Today was really my first day diving into actual course content (e.g. the topics covered in the course). On this day, I started working with the C programming language by writing my first program in this language. While I have programmed before, I've never known or programmed in the C language, so the program I wrote today was a very basic application that followed the “hello world” example commonly found as a “jumping off point” in many programming languages.

The source code for this application is stored in my SVN repository in the ~/src/cprog/hello.c file, but since user Subversion repositories are private, I thought I'd write the code here as well. As stated, this is an extremely simple application, but it gave me my first glimpse of the C programming language, and when compiled it ran without problems.

/*
Author: Logan Merrill, Airshock LLC
Date: Sat 9/10/2011
Description: My first program written in C, using the classic "Hello world" example.
Compilation command: gcc -o hello.app hello.c
Execution command: ./hello.app
*/
 
#include <stdio.h>
 
main()
{
	printf("Hello world!\n");
	getchar();
	printf("The program will now close. Thank you for running this simple test application.\n");
	return 0;
}

I hope to explore more of the wonderful world of C as this course continues.

September 22, 2011

I know I haven't posted in a while, and that's because I haven't really done much with this course. This is entirely my fault, and I intend to remedy it in the upcoming days and weeks. Anyway, I thought I'd take just a few minutes to denote what I did today as far as the C/C++ Programming course is concerned.

Today, while trying to add two more keywords to my opus, I read about header files and arithmetic operators (see “Header files” and “Operators and operands” below). This was something significant because, while I knew what operators and operands were to an extent, as I have used them when programming in other languages (Visual Basic and PHP), I didn't know about the available operators in C, nor did I know about header files in C or C++.

One of the concepts that I'm struggling with a bit is header files. It seems to me like they're similar to include statements in PHP, which allow you to reference another file for inclusion into the current file. However, I don't rally understand what should be included in header files. Officially, or at least by definition, “function declarations and macro definitions” are what should be included in them, but what does this mean exactly? All of the examples I've seen show functions being declared in header files, but then also being declared in the source code file as well, along with the inclusion of said header file. An example of this is below. (Source: http://www.dgp.toronto.edu/~neff/teaching/CWebsite/headers.html)

/* File foo.h. This header file defines the function foo*/
 
/*  foo is a universally useless function*/
int foo(float f);
 
 
/* File foo.c. This file implements the function foo*/
 
#include "foo.h"
#include 
 
int foo(float f)
{
    printf("foo!\n");
    return 3;
}

Notice that the code in the above example, specifically the line “int foo(float f)” was used in both the header file (foo.h) and the source code file (foo.c). However, it seems to me that the following would be a more plausible usage for a header file.

/* File foo.h. This header file defines the function foo*/
 
/* foo is a universally useless function*/
int foo(float f);
 
 
/* File foo.c. This file implements the function foo*/
 
#include "foo.h"
#include <stdio.h>
 
int main()
{
    printf("foo!\n");
    return 3;
}

Now, I know my proficiency with C and C++ is almost non-existent, so perhaps some syntax in the second code example above is incorrect, but nevertheless that is my clarification of how I believe a header file should be used, based on what I know of header files and how I have seen them used in other programming languages such as PHP or Visual Basic. Perhaps readers of this document can offer some clarification on this, or perhaps I will gain a better understanding of header files as this course continues.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Topics

Standard I/O

“Standard I/O” refers to standard input and output and contains the following parts/components:

  • STDIN (standard input)
  • STDOUT (standard output)
  • STDERR (standard error)

Each of these components will be looked at further in the below subsections.

Standard input (STDIN)

The standard input stream (STDIO, or STDIN in C++) is used as the default source of data for applications, and is usually directed to the standard/default input device associated with a computer, which in most cases is a keyboard. Note, though, that this is not always the case, as standard input can also be handled at the operating system level rather than at the device level. This can occur when the standard input is a file rather than a hardware device (such as a keyboard), as seen in the following command line example:

lmerrill@ms1c.airshock.net:~# mysql -u root -p database < data.sql
Enter password:
lmerrill@ms1c.airshock.net:~#

In the above example, the MySQL command line utility accepts input from a file named data.sql and loads the data contained in that file into the database named “database.” The “<” sign in the command line argument tells the operating system to direct the standard input from whatever is on the right of the symbol to whatever command is being performed or whatever action is being taken on the left side of the symbol.

In the C programming language, the scanf function can be used when you want to accept standard input and use it in your program.

Standard output (STDOUT)

The standard output stream is the default destination of regular output for applications. Usually, this destination is a monitor/screen, but it too, like STDIN, can also be a file, as seen in the following example:

lmerrill@ms1c.airshock.net:~$ netstat -a > ~/netstat.txt

In the above example, the output of the netstat -a command, which would normally be printed to the screen, is written to the file ~/netstat.txt. This is indicated by the “>” symbol, which instructs the operating system to redirect the output of the command performed on the left side of the symbol to whatever is on the right side of the symbol, in this case the path to a file that is to be created and populated with the generated output.

In C, the printf function is used to send output to the standard output device. For example, the following code would create a program that would print the sentence “This is a test” to standard output.

/* Standard output example. */
 
#include <stdio.h>
 
int main()
{
	printf("This is a test.\n");
	return 0;
}

In the above example, the printf function is used and the sentence “This is a test” is passed to it, which then gets printed to the standard output device. In most cases this would be a screen, but the standard output of the above program could also be printed to a file if the following commands were performed. Note that in the below example the source code given above is stored in a file named test.c.

lmerrill@ms1c.airshock.net:~$ cd src/examples
lmerrill@ms1c.airshock.net:/home/lmerrill/src/examples$ gcc -o stdiotest test.c
lmerrill@ms1c.airshock.net:/home/lmerrill/src/examples$ ./stdiotest > results.out
lmerrill@ms1c.airshock.net:/home/lmerrill/src/examples$

In the above example, the program test.c is compiled and then executed, but the output of the execution is sent to the file results.out. If we were to examine the contents of said file, we would see the following:

lmerrill@ms1c.airshock.net:/home/lmerrill/src/examples$ cat results.out
This is a test.
lmerrill@ms1c.airshock.net:/home/lmerrill/src/examples$

Standard error (STDERR)

Finally, the standard error stream is the default destination for error messages and other diagnostic warnings, and is similar to STDOUT in that its output is also usually directed to the default output device. STDERR can be used as an argument to functions that expect an output stream as one of their parameters, like fputs or fprintf.

While both STDOUT and STDERR are associated with the same output, some applications may differentiate between what gets sent to STDOUT and what gets sent to STDERR in cases where one of them is redirected. For example, it is frequent to redirect STDOUT to a file, as seen in the above examples, while continuing to direct the output of STDERR to the screen, thus allowing error and other diagnostic messages to be separated from output that is written to a file or piped to another command.

Header files

A header file is one that contains function declarations and macro definitions that are to be shared between several source files in a C or C++ program. They are similar to modules in Perl or includes in PHP and other Web programming languages. To request the use of a header file in your program, simply include it by using the “#include” pre-processing directive, like this:

#include <math.h>
#include "algebra.h"
#include "geometry.h"

Header files serve two purposes:

  • System header files provide interfaces to various parts of the operating system. These types of header files are used when you want to invoke system calls and libraries because they provide the definitions and declarations required to do so. Examples of common system header files are stdio.h, which provides standard input and output functionality, strings.h, which provides the code necessary to handle formatted strings, stdlib.h, which provides miscellaneous functions, and math.h, which provides arithmetic functions.
  • Your own header files contain declarations for interfaces between the source files of your program. It is a good idea to create your own header files if you have a group of function declarations or macro definitions that need to be used in multiple source files.

Creating header files for use in your applications eliminates the need to update multiple files if you need to make a change to a function declaration or macro definition, similar to the way in which PHP or HTML include files eliminate the need to update code on every page of your Web site if you need to make a change to a global element, such as a navigational menu or text footer. Be sure to place include statements to header files at the top of your program, in the same locations that you would place function and global variable declarations.

Interesting fact: the most common header file included in any C program is the stdio.h file, which handles standard input and output. This is common because just about every application needs to print to standard output, or accept input from a standard input device, or print diagnostic and warning messages to an output device such as a screen or speech synthesizer. For additional information about standard input and output, see the above section, entitled “Standard I/O.”

Operators and operands

Operators are symbols which take one or more operands or expressions and perform arithmetic or logical computations on the given data. There are four types of operators available in the C programming language:

  • Arithmetic
  • Assignment
  • Bitwise
  • Logical/relational

Here is a listing of the operators that fall under each of the four types mentioned above.

Arithmetic operators

  • + (for performing addition)
  • - (for performing subtraction)
  • * (for multiplication)
  • / (for division)
  • % (modulo for finding remainder in division operation)
  • – (decrement post and pre)
  • ++ (increment post and pre)

Assignment operators

  • = (equals)
  • *= (multiply)
  • /= (divide)
  • %= (modulus)
  • += (add)
  • -= subtract)

Bitwise operators

  • & (AND)
  • | (inclusive OR)
  • ^ (exclusive OR)
  • « (shift left)
  • » (shift right)
  • ~ (one's compliment)

Logic/relational operators

  • == (is equal to)
  • != (not equal to)
  • < (less than)
  • > (greater than)
  • ⇐ (less than or equal to)
  • >= (greater than or equal to)
  • && (logical AND)
  • || (logical OR)
  • ! (logical NOT)

Variables

So far, I know enough of the C programming language where I should be able to write a simple program that outputs information based on a given input and that is marked up with simple comments detailing how to build and execute the application. That's fine and dandy for programs like the classic “Hello world” example, but what if I wanted to write more complicated applications, ones that, say, actually interacted with the user? Fortunately, C allows us to write programs that accept input from users as well as generate and display output.

It seems logical that before I can receive input from the users of my application I must have a place to store that input. Storing the input also allows me to manipulate it and generate output based on the manipulated (or initially-given) data. In programming, input and data are stored in variables, and these get manipulated by both the programmer (at compile time) and the user (at run time).

There are several different types of variables, so when you tell the compiler about a variable you also must declare the name and data type of that variable. You can give your variable any name, but there are specific names for data types based on the type of data your variable is going to hold. Several basic types include char, int, and float. In the following list, variable sizes appear in parentheses. Be sure to select the right data type that allows for the size of the data you are attempting to store in a variable before creating such a variable in your programs.

  • char: the most basic unit that the machine can address, typically a single octet (one byte).
  • int: the most natural size of integer for the machine, typically a 16, 32, or 64-bit addressable word (2, 4, or 8 bytes, respectively).
  • float: a single-precision floating point value (4 bytes).

In other words, variables of type char store a single character, while variables of type int store integers (whole numbers without decimals) and variables of type float store numbers with decimals. Note that each type of variable has a specific range associated with it that governs the data it can hold.

  • int: -32,768 to 32,767
  • char: all ASCII characters
  • float: 1.2 X 10-38 to 3.4 X 1038

As mentioned above, before you can use a variable you must tell the compiler about it by giving it a name and specifying it's type. To declare a variable, use the syntax <variable name> <variable type>, like this:

/* Note the semi-colon in the following variable declaration. Although we are not calling a function it is still required at the end of the "expression." */
 
int serverStatus;

The above code creates a variable of type int whose name is “serverStatus”. This variable could then be used later in the program. If we were writing an application that, for example, allows us to control the Apache HTTPD Server, then the variable “serverStatus” could be used later in the program to specify whether the server was running or had been shut down.

It is also possible to declare multiple variables of the same type on the same line. However, if you attempt to use an undefined variable, your program will not run, and the compiler will output an error message informing you that you have made a mistake. Here are several variable declaration examples:

/* Variable declaration examples */
 
int x;
int a, b, c, d;
char letter;
float the_float;

Warning: While you can have multiple variables of the same type, you can not have multiple variables with the same name, nor can you have variables and functions with the same name. A final restriction on variables is that variable declarations must come before any other statements in your code block (code between the left and right braces in your source file). In other words, you need to declare all of your variables before you do anything else. For example:

/* The following code is incorrect. */
 
#include <stdio.h>
 
int main()
{
    /* wrong!  The variable declaration must appear first */
    printf( "Declare x next" );
    int x;
    return 0;
}
 
/* This is how your code is supposed to look. */
 
#include <stdio.h>
 
int main() 
{
    int x;
    printf( "Declare x first" );
    return 0;
}

Note: Code examples and information on variables used in this section has been taken from http://www.cprogramming.com/tutorial/c/lesson1.html. Information on variable sizes was taken from http://www.cplusplus.com/doc/tutorial/variables/. Ranges for the given variable types in this section were taken from http://www.learn-programming.za.net/programming_c_learn02.html.

Formatted text string

A formatted text string is a string of characters, normally passed as an argument to the printf function. According to the printf(3) manual page, “The format string is a character string, beginning and ending in its initial shift state, if any. The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between there may be (in this order) zero or more flags, an optional minimum field width, an optional precision and an optional length modifier. … By default, the arguments are used in the order given, where each '*' and each conversion specifier asks for the next argument (and it is an error if insufficiently many arguments are given). One can also specify explicitly which argument is taken, at each place where an argument is required, by writing '%m$' instead of '%' and '*m$' instead of '*', where the decimal integer m denotes the position in the argument list of the desired argument, indexed starting from 1.”

Here are a few examples of the formatted text string in action, by way of the fprintf function. Note that these examples were taken, unmodified, from the printf(3) manual page.

To print pi to five decimal places, write the following code:

#include <math.h>
#include <stdio.h>
 
fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));

To print a date and time in the form 'Sunday, July 3, 10:02', where weekday and month are pointers to strings, write the following code:

#include <stdio.h>
 
fprintf(stdout, "%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min); 

Many countries use the day-month-year order. Hence, an internationalized version must be able to print the arguments in an order specified by the format:

#include <stdio.h>
 
fprintf(stdout, format, weekday, month, day, hour, min);

In the code above, “format” depends on locale, and may permute the arguments. With the value “%1$s, %3$d. %2$s, %4$d:%5$.2d\n” one might obtain 'Sonntag, 3. Juli, 10:02'.

For additional information about formatted text strings or the printf/fprintf functions, please see the printf(3) manual page.

Scope

In programming, solving a complex problem usually involves breaking that problem down into smaller pieces and writing one or two functions or routines to deal with each piece. Then, all the functions are put together to create a complete program that can solve the complex problem. This program usually contains some variables that need to be shared between all of the functions in the application, and others that need to be limited to only certain functions. In other words, the visibility of those variables is limited, and values assigned to those variables are hidden to all functions except those to which the variable is visible.

As a practical example, limiting the scope of variables can be very useful when several developers are working on different parts of the same program. If they limit the variables they use to their own, individual pieces of code, then they don't have to worry about conflicting with variables of the same name used by other developers in other parts of the program.

In C, you can indicate the visibility level of a declared variable by designating its scope. The following subsections explain the different scopes–block, function, program, and file–that are available in the C programming language, and how to declare variables that fall under each scope.

Block scope

A variable declared within a block (a set of statements enclosed in braces) has block scope. Therefore, the variable is active and accessible from its declaration point to the end of the block. Note that block scope is also called local scope, and that variables with local scope are usually called local variables.

In the following example, notice that the variable “i” declared within the block of the “main” function has block scope.

int main()
{
   int i;   /* block scope */
   .
   .
   .
   return 0;
}

Function scope

Function scope refers to variables that are active and visible only from the beginning of a function to the end of that function. In C, only the goto label has function scope. For example, the goto label “start” shown in the following code sample has function scope.

int main()
{
   int i;   /* block scope */
   .
   .
   .
   start:   /* A goto label has function scope */
   .
   .
   .
   goto  start;  /* the goto statement */
   .
   .
   .
   return 0;
}

In the above code sample, the “start” label is only visible from the beginning to the end of the “main” function. Therefore, there should not be more than one label having the same name in this function.

Program scope

A variable is said to have program sscope when it is declared outside of a function. These variables are also called global variables because they are visible among the different source files that make up an executable program and are not limited to use only within specific functions or files. The following code sample demonstrates the use of program scope. Notice that the int variable (“x”) and the float variable (“y”) have program scope.

/* Note that a global variable is declared with an initializer outside of a function. */
 
int x = 0;        /* program scope */
float y = 0.0;    /* program scope */
int main()
{
   int i;   /* block scope */
   .
   .
   .
   return 0;
}

File scope

In C, global variables are said to have “file scope” when they are declared with a static specifier. Variables with file scope are visible from their declaration point to the end of the file in which they are contained.

The following portion of source code shows variables with file scope:

int x = 0;             /* program scope */
static int y = 0;      /* file scope */
static float z = 0.0;  /* file scope */
int main()
{
   int i;   /* block scope */
   .
   .
   .
   return 0;
}

In the above example, the int variable (“y”) and the float variable (“z”) both have file scope.

Comparing block and program scope

The following C program illustrates the relationship between block and program scope. Note that the entirety of the code used to create this program was taken from http://aelinik.free.fr/c/ch14.htm.

/*
Compilation instructions: if source file is named scope.c, run: gcc -o scope.app scope.c
Execution instructions: if the executable file is named scope.app, run: ./scope.app
*/
 
#include <stdio.h>
 
int x = 1234;         /* program scope */
double y = 1.234567;  /* program scope */
void function_1()
  {
     printf("From function_1:\n  x=%d, y=%f\n", x, y);
  }
 
main()
 {
    int x = 4321;   /* block scope 1*/
 
    function_1();
    printf("Within the main block:\n  x=%d, y=%f\n", x, y);
    /* a nested block */
    {
       double y = 7.654321;  /* block scope 2 */
       function_1();
       printf("Within the nested block:\n  x=%d, y=%f\n", x, y);
    }
    return 0;
 }

Pointers

Simply put, a pointer is a memory address. To better understand a pointer, though, consider the following scenario.

A variable of type int, named num, is declared at the beginning of a source code file.

int num;

This variable occupies some memory. More specifically, it occupies 4 bytes of memory on current mainstream Intel systems because an int variable is 4 bytes wide (see “Variables” above).

Next, another variable is declared below the previous declaration in the same source file.

int *num_ptr = &num;

in the code above, num_ptr is a pointer to int, and has been initialized to point to num.

As stated, the “num” variable occupies some memory, and its location in memory is called its “address.” Furthermore, &num (see above) is a pointer to num (which is why & is called the “address-of operator”).

Think of every variable as a box. In the above scenario, num is a box that is 4 [sizeof(int)] bytes in size, and the location of this box is its address. When you access this address, you are actually accessing the contents of the box it points to. This is true of all variables, regardless of whether they are of type char, double, float, or int. In fact, grammatically speaking, there is no such thing as a “pointer variable” because all variables are the same. There are, however, variables with different types. In the above scenario, num's type is int, and num_ptr's type is int*. Thus, “pointer variable” really means “variable of a pointer type.”

If you learn only one thing from the above text, it should be that the pointer is not the variable. In other words, the pointer to num is the contents of num_ptr. The box would still be num_ptr even if you put a different pointer in the box. Note though that doing this would cause the num_ptr box to no longer point to the contents of the num variable.

Keep in mind that the pointer has a type as well. It's type is int, thus it is an “int pointer” (a pointer to int). An int **'s type is int * (it points to a pointer to int). The use of pointers to pointers is called “multiple indirection.”

Assignment

The following code is an obvious way to assign an integer to the num_ptr pointer specified above.

num_ptr = 71;

However, this code is also wrong. This is because any direct assignment to a pointer variable will change the address of the variable, not the value in that address. In the above code sample, the new value of num_ptr, that is, the new pointer in that variable is 71. However, it is unknown as to whether or not this points to anything. Therefore, trying to access this address will most likely result in a segmentation violation, which will crash the program.

Thankfully, compilers usually output a warning when you try to assign an integer to a pointer variable, allowing you to correct the assignment and continue compiling your code. An example of this warning is the output generated by GCC when this warning is raised, which reads, “warning: initialization makes pointer from integer without a cast.”

How, then, does one access the value at a pointer? By dereferencing it.

Dereferencing

In the following declaration, the dereference operator (prefix *, not to be confused with the multiplication operator) looks up the value that exists at the address pointed to by num_ptr. This is called a “load” operation.

int load = *num_ptr;

It's also possible to write to a dereference expression. The C way of saying this is that a dereference expression is an lvalue, meaning that it can appear on the left side of an assignment. This is called a “store” operation.

/* The following line of code sets the value of the num variable to 71. */
 
*num_ptr = 71;

A note on declaration syntax

As seen in the “Variables” section above, multiple variables of the same type can be declared on the same line, eliminating the need to take up more vertical space in a source file with same-type declarations. For example, the following C code declares several int variables on the same line and compares that to declaring the same variables on multiple lines.

/* The following int variables are declared on the same line. This is possible only if all fo the variables being declared have the same type. */
 
int x, y, z;
 
/* Next, these same variables are being declared on multiple lines. */
 
int x;
int y;
int z;

Therefore, given the code above and the availability of declaring variables of the same type on the same line, it would seem that two pointer variables can also be declared on a single line, as seen in the following code example:

int* ptr_a, ptr_b;

In other words, and as demonstrated in the code above, if the type of a variable pointing to int is int *, and a single declaration )line of code) can declare multiple variables of the same type simply by providing a comma-separated list (e.g., ptr_a, ptr_b), then you should be able to declare multiple int pointer variables by giving the int pointer type (int *) followed by a comma-separated list of names to use for the variables (ptr_a, ptr_b).

Given this information, is int * the type of the variable ptr_b? Many newcomers to C would say yes, but this is actually incorrect. The type of ptr_b is int. It is not a pointer. This is because C's declaration syntax ignores the pointer asterisks when carrying a variable type over to multiple declarations. In other words, if you split up the declaration of ptr_a and ptr_b so that each is declared on its own line, the result would look like this:

int *ptr_a;
int ptr_b;

Think of it as assigning a base type to each variable, in this case “int,” plus a level of indirection, indicated by the number of asterisks on the left side of the variable name (ptr_b has 0, ptr_a has 1).

All this to say that it is possible to perform a single-line declaration in a clear and concise way, as seen below.

/* Notice that the asterisk has moved. It is now right next to the word ptr_a. */
 
int *ptr_a, ptr_b;

An even more clear and concise method would be to write the declaration in a way that puts the non-pointer variables first, like this:

/* Notice that the position of the asterisk has not changed even though the order of the ptr_a and ptr_b variables has changed. */
 
int ptr_b, *ptr_a;

Finally, keep in mind that the following is also acceptable:

int *ptr_a, *ptr_b;

See also

For additional information on pointers, including information not mentioned in this document, please see http://boredzo.org/pointers/. Note that code examples used in this section were adapted from those provided at the aforementioned URL.

Typecasting

“Typecasting” is the process by which a variable of one type acts like another type for a single operation. For example, one could use typecasting to make a variable of type int act like a variable of type char. To typecast something, simply put the type of variable you want the actual variable to act as inside of parentheses and place those parentheses in front of the actual variable, like this:

#include <stdio.h> 
 
int main()       
{
  /* The (char) is a typecast, telling the computer to interpret the 65 as a character, not as a number.  It is going to give the character output of 
  the equivalent of the number 65 (It should be the letter A for ASCII). Note that the %c below is the format code for printing a single character. */
  printf( "%c\n", (char)65 );
  getchar();
  return 0;
}

One possible use for typecasting is when you want to use ASCII characters. For example, to create a chart of all 256 ASCII characters you would need to use typecasting to print out the integer as its character equivalent, as seen in the following code sample.

#include <stdio.h>
 
int main()
{
    for ( int x = 0; x < 256; x++ ) {
        /* Note the use of the int version of x to output a number and the use of (char) to typecast the x into a character which outputs the
        ASCII character that corresponds to the current number. */
        printf( "%d = %c\n", x, (char)x );
        }
    getchar();
}

Note: Code samples used in this section were taken, unmodified, from http://www.cprogramming.com/tutorial/c/lesson11.html.

Selection structures

So ffar, all of the code samples given in this document have been applications that are executed based on a specific set of instructions that are followed from start to finish every time the program is run. These programs are few and far between in the software universe because they serve very few purposes and cannot be used to perform large, complex tasks. Instead, it is much more common to write programs that are executed based on user interaction and conditional statements rather than a flat set of instructions. Such programs are called “selection structure” programs and are the focus of this section.

As previously stated, programs based on a selection structure are more common and benefitial than programs based on a sequence structure because they allow for varying results and output based on user input gathered from conditional statements placed throughout the program. Two such conditional statements are “if” statements and “switch” statements.

If statements

Simply put, the if statement evaluates an expression. If that expression is true, then a corresponding statement is executed. If an else clause is given and the expression is false, then the else statement is executed, otherwise the program continues normal execution at whatever statement is written after the if statement.

The syntax of an if statement is as follows:

/* Notice that the following if statement consists only of the expression and the statement. */
if( expression ) statement1;
 
/* Notice that an else clause is given in the following if statement. */
if( expression ) statement1;
else statement2;

Here is an example of an if statement in action:

if(loop<3) counter++;
 
if(x==y)
  x++;
else
  y++;
 
if(z>x)
 {
  z=5;
  x=3;
 }
else
 {
  z=3;
  x=5;
 }

Switch statements

A switch statement allows a single variable to be compared with several possible constants. If the variable matches one of the constants, then program execution jumps to that point. Note that a constant cannot appear more than once, and there can only be one default expression.

The syntax of a switch statement is as follows:

switch ( variable )
 {
  case const:
   statements...;
  default:
   statements...;
 }

Here is an example of a switch statement in action:

switch(betty)
 {
  case 1:
    printf("betty=1\n");
  case 2:
    printf("betty=2\n");
    break;
  case 3:
    printf("betty=3\n");
    break;
  default:
    printf("Not sure.\n");
 }

In the above example, two lines are printed if betty is equal to 1. However, if betty is 2, then only one line is printed. If betty equals 3, then only one line is printed, but if betty does not equal 1, 2, or 3, then the line “Not sure” is printed.

See also

For additional information about selection structures, including additional statements (while, do, for, goto, continue, break, and return) please see http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.6.html. Note that code samples used in this section were taken, unmodified, from the aforementioned URL.

Repetition and iteration structures

Repetition, also called iteration, is used when something needs to be repeated over and over again, and is seen most prominently in loop statements such as the ones examined in the below subsections.

while loop

Put simply, the while statement provides an iterative loop. The syntax for such a statement is shown in the code sample below.

while( expression ) statement...

In the code above, “statement” is executed repeatedly as long as “expression” is true, and the test on “expression” takes place before each execution of “statement”.

Here is an example of a while loop in action:

while(*pointer!='j') pointer++;
 
while(counter<5)
 {
  printf("counter=%i",counter);
  counter++;
 }

do while loop

The do…while construct provides an iterative loop. Its syntax is given below.

do statement... while( expression );

In a do while loop, which is similar to a while loop (see the “while loop” subsection), the “statement” in the syntax above is executed repeatedly as long as “expression” is true, and the test on “expression” takes place after each execution of “statement”.

Below is an example of the do while loop in action.

do {
  betty++;
  printf("%i",betty);
} while (betty<100);

for loop

The for statement provides for a controlled loop. Its syntax is below.

for( expression1 ; expression2 ; expression3 ) statement...

In the code above, “expression1” is evaluated before the first iteration, and “expression3” is evaluated after each iteration. Both “expression1” and “expression3” may be omitted. If “expression2” is omitted, it is assumed to equal 1. “statement” is executed repeatedly until the value of “expression2” is 0. Finally, the test on “expression2” occurs before each execution of “statement”.

Here are some examples of a for loop in action:

/* Print numbers 0 through 999. */
 
for(loop=0;loop<1000;loop++)
  printf("%i\n",loop);
/* Print numbers 3 through 53. "some_function" is called 51 times. */
 
for(x=3, y=5; x<100+y; x++, y--)
 {
  printf("%i\n",x);
  some_function();

See also

For more information about repetition structures, please see http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.6.html. Note that code samples used in this section were taken, unmodified, from the aforementioned URL.

Arrays and pointer arithmetic

Arrays

Arrays allow programmers to store related data under a single variable name with an index, also known as a subscript. They can also be thought of as a list or ordered grouping of variables of the same type. As such, arrays are used to help programmers organize collections of related data efficiently and intuitively.

Creating and initializing arrays

Creating an array is a quick and simple process that involves only one line of code:

int numbers[6];

The above line of code creates an array with 6 integers or numbers. To create an array containing six characters, write the following line of code:

char letters[6];

If you want to initialize the array as it is being created, simply write the following code, replacing values where necessary. Note that array elements that are not initialized when the array is declared will contain a value of 0.

int point[6]={0,0,1,0,0,0};
Accessing array data

You can access variables stored in arrays by referencing the index of the element you want to access. Given the code in the subsection above, the following would store a 1 in the variable x:

int x;
x = point[2];

Keep in mind that, in C, array indexes start with 0 rather than 1. The first element of the above array is 0, while the index to the last value in the array is the array size (6) minus 1. Also, keep in mind that C does not guarantee bounds checking on array accesses. This means that your application may still compile even if you try to access an array index that is out of bounds of said array. For example, some compilers may not complain about the following (though most good ones do)

w

char y;
int z = 9;
char point[6] = { 1, 2, 3, 4, 5, 6 };
//examples of accessing outside the array. A compile error is not always raised
y = point[15];
y = point[-4];
y = point[z];

Furthermore, during program execution, an out-of-bounds array access attempt does not always cause a runtime error. In other words, your application may continue with no problems after attempting to retrieve a value from point -1. To alleviate indexing problems, the sizeof expression is commonly used when writing loops that process arrays.

int ix;
short anArray[]= { 3, 6, 9, 12, 15 }; 
for (ix=0; ix< (sizeof(anArray)/sizeof(short)); ++ix) {
  DoSomethingWith("%d", anArray[ix] );
}

In the above example, the size of the array was not explicitly specified. Rather, the compiler knows to size it at 5 because of the five values in the initializer list. Adding an additional value to the list will cause it to be sized to 6, and the code will automatically adjust to this change thanks to the sizeof expression in the for loop.

Pointer arithmetic

Pointer arithmetic refers to performing simple mathematical operations, such as addition or subtraction, on a pointer to output another address. Put simply, an integer can be added to a pointer to get another address. The following code snippet illustrates this concept.

int array[100];
int *ptr1 = array;
int *ptr2;
 
ptr2 = ptr1 + 5;

In the code above, the integer 5 is dependent upon the variable type of ptr1, which is int. Recall that variables of type int are 4 bytes in size. Therefore, 5 multiplied by 4 is 20, and the address of ptr1 + 20 is the address of ptr2.

Recall that a pointer is the address of the first element in an array. This means that ptr1 is the address of the first element of the array and pt2 is the address of the sixth element.

In the following code sample, notice that the two statements are the same.

ptr2 = &(ptr1[5]);  /* this is the same as below */
ptr2 = ptr1 + 5;

Here are several additional lines of code to further illustrate the above two statements.

int x[10]; // or
int *x;
 
    /* The following two statements are completely interchangeable. */
x[10];
*(x + 10);
 
    /* or (these two are also interchangeable) */
&(x[10]);
x + 10;

For additional illustrations of pointer arithmetic, review the following C program.

/*
 *
 * arithmetic.c
 *
 * Program to demonstrate the use of pointer arithmetic
 *
 * by Mark Virtue, 2001.
 *
 */
 
#include <stdio.h>
#include <stdlib.h>
 
static void goodbye() {
    while (getchar() != '\n') {}
    printf("\nPress ENTER to exit: ");
    fflush(stdin);
    getchar();
}
 
main() {
    int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int *ptr = array;
    int element;
 
    atexit(goodbye);
 
    printf("Please enter which element you would like: ");
    scanf("%d", &element);
 
        // The output for the following statements are the same, all print out the value for the specified element of the array
    printf("\narray[%d] is %d\n", element, array[element]);
    printf("*(array + %d) is %d\n", element, *(array + element));
    printf("*ptr[%d] is %d\n", element, ptr[element]);
    printf("*(ptr + %d) is %d\n", element, *(ptr + element));
 
        // The following statements print out the memory address for the specified element of the array
    printf("\n&(ptr[%d]) is %d\n", element, &(ptr[element]));
    printf("ptr + %d is %d\n", element, ptr + element);
 
        // This prints out the address difference between two elements of the array through subtraction
    printf("\nThe ADDRESS difference between element 9 and element 1 is %d\n", &(ptr[9]) - &(ptr[1]));
}

Note: Code samples used in this section were taken, unmodified, from http://blog.robbychen.com/2011/02/02/the-c-pointer-arithmetic/.

Multi-dimensional arrays

Recall from previous sections that arrays are used in C to allow programmers to store related data under a single variable name, and that access to data in arrays involves the use of an array index (an integer between 0 and one number less than the total number of elements in the array).

Multi-dimensional arrays build on the concept of arrays in that they are arrays whose elements are arrays. In other words, multi-dimensional arrays are really just one-dimensional arrays who elements are arrays. The syntax for declaring multi-dimensional arrays is as follows:

int array2d[ROWS][COLUMNS];

In the syntax above, “rows” and “columns” are constants. This defines a two-dimensional array, but arrays with even more dimensions are possible. Reading the subscripts from left to right, array2d is an array of length “rows,” each element of which is an array of “columns” integers.

To access an integer element in this multi-dimensional array, the following code would be used:

array2d[4][3]

Again, reading from left to right, the above line of code accesses the fifth row of the array and the fourth element in that row. The expression array2d[4] is an array, which is then being subscripted with 3 to access the fourth integer.

For additional information about multi-dimensional arrays, please see http://en.wikipedia.org/wiki/C_syntax#Multidimensional_arrays. Note that code examples used in this section were taken, unmodified, from the aforementioned wiki page.

Objectives

Objective 1

The first course objective that I am going to look at during this course is to understand the difference between procedural and object-oriented programming languages. This entails understanding the difference between procedural and object-oriented programming, as ultimately many programming languages allow you to write both types of applications. Therefore, it is your job as the programmer to understand the difference between these types of programs and to be able to determine which is better suited for the program you want to write.

Method

One of the best ways to measure this course objective is to think of measuring the objective as answering a question on a course-related quiz. For example, if a quiz were given on course materials, one of the questions might read as follows: “Create a scenario that demonstrates proper understanding of the key differences between procedural and object-oriented programming and that clearly demonstrates the advantages and disadvantages of both programming types.”

Measurement

As per the method of measurement given above, the following would be my answer to the mock quiz question, and the way that I would demonstrate my understanding of the given course objective.

As one of the programmers and server administrators for Airshock LLC, a company specializing in providing Web and media services to the online community, I have been tasked with writing a program to determine and output the status of several services on the company's flagship server. The services that need to be monitored are the Apache HTTP Server, the ProFTPD Server, the Postfix SMTP Server, and the Dovecot IMAP/POP3 Mail Server. For each service, the following items need to be monitored:

  • whether the service is running, and
  • whether the service can accept incoming connections on its designated port number.

In addition, the following service-specific items need to be monitored:

  • Do clients using the Apache HTTP Server have the correct permissions necessary to update files on their Web site?
  • Is the Postfix Mail Server able to send messages to hosts outside of the company's network?
  • Is the Dovecot IMAP/POP3 Mail Server able to write to users' mailboxes on the server when new messages are received?

There are two ways to perform this task: write separate programs for each service that essentially contain the same instructions for shared monitoring operations, or write programs for each service that share common functions used by all services. The first way is an example of writing a procedural program, while the second way illustrates the creation of an object-oriented program.

There are advantages and disadvantages to both methods described above. If I wanted to create a mock-up of the service monitoring program then I would write procedural applications for each service that needed to be monitored. However, if I wanted to actually write a program that would be used in a production environment, in this case the company's network, I would need to write an object-oriented program, as it is easier to mantain and update and requires less system resources, such as disk space for the source and executable files.

As mentioned above, the first method of accomplishing the tasks mentioned in this scenario is to write a separate program for each service. This can become very tedious because each service shares some of the same monitoring requirements as the other services. For example, each service needs to be monitored for uptime and end-user connectivity. Therefore, the program written for each service would contain each of these functions, which means that in a sense they would have to be written out four different times. These programs would of course need to contain the service-specific functions given above as well as the shared functions.

This method of solving the scenario is insufficient primarily because it involves a lot of repetitive coding. Because all services share some of the same monitoring requirements, the same functions would need to be included in each program. It also makes function modifications extremely difficult. For example, what if I was then asked to modify the program so that each service was restarted if it was found to be offline or unavailable? I would then have to go into each application and re-write, or add to, the service uptime function to incorporate this new functionality.

However, in the second approach to solving this scenario, I would still write a program for each service, but I would also incorporate shared functions that would be defined in a separate file, such as a header file (e.g. functions.h). This way, I wouldn't need to re-write the same code four different times, but could rather just call it from an included header file. I would still need to incorporate service-specific functions into each application, but I would now be able to more easily modify service monitoring requirements because I would only have to edit the associated header file, rather than having to edit each program file separately. For example, if I needed to automatically restart a service that was found to be offline or unavailable, I would just re-write, or add to, the service uptime function in the header file to incorporate this functionality, instead of adding to or re-writing the code in each program file. Furthermore, because each program file includes the same shared functions, any changes made to said functions would be reflected automatically throughout each program file when the program is next compiled.

Therefore, it seems to me that the object-oriented approach to programming would be better suited for this scenario, at least for use in a production environment, because it would require less coding and provide for quick deployment of changes in or additions to the monitoring requirements.

Analysis

After reflecting on the information in the above subsection, I feel that this information was an accurate measurement of the course objective based on the method given for measuring it. I had originally asked an appropriate quiz question to assist in measuring my understanding of the objective, and feel that the information in the above subsection answered such question clearly and efficiently, and that it also demonstrated my understanding of the given course objective. In other words, i believe that, as illustrated by the scenario above, I now have a pretty good understanding of the differences between procedural and object-oriented programming.

I do feel, however, that this course objective could be improved. In the course syllabus, the objective refers to procedural and object-oriented “languages” instead of “programming” or “programs.” This originally threw me off because many programming languages allow you to write both procedural and object-oriented programs, and as such I interpreted it to mean “programming” and used that interpretation for the basis of my measurement and analysis.

Overall, however, I believe this course objective is written clearly and concisely, and I believe my method of measurement was successful in gauging my understanding of the objective.

Experiments

Manipulating Output in C

Question

How important is the inclusion of the “\n” character as an argument to the printf function in regards to the output of an executed application?

Resources

This experiment makes heavy use of the printf function, which prints output to the standard output device based on the arguments it is passed. Therefore, a rudimentary understanding of this function, and how to incorporate it into a C program, is necessary in order to successfully understand, evaluate, and benefit from this experiment.

Hypothesis

Based on what I've read with respect to the question I originally created (see the top of this experiment), I believe that the “\n” character is extremely important when using the printf function to generate output, such as a string constant, that is sent to the standard output device.

Experiment

In order to test my hypothesis, I will need to create two programs written in the C programming language. Both programs will essentially perform the same actions, that is, both programs will print output to the standard output device with the help of the printf function. However, these two applications will be different in that one will make use of the “\n” character, while the other will not. I will then compile the programs, execute them, and document their output.

Note that this experiment could be completed by writing only one program that contains the contents of the two programs just mentioned, but for clarification purposes I thought I would break the experiment up into two separate yet similar applications.

Data

Source code

The first portion of this experiment involves writing the programs that will be used to test my hypothesis. Here is the code used for each program.

/*
Program #1 (1-1.c)
Author: Logan Merrill
Description: First program of the "\n" character inclusion experiment. Includes the character in the printf function.
Compilation instructions: gcc -o 1-1.out 1-1.c
Execution instructions: ./1-1.out
Copyright 2011 Airshock LLC. All rights reserved.
*/
 
#include <stdio.h>
 
main()
{
	printf("Testing, 1, 2, 3.\n");
	return 0;
}
/*
Program #2 (1-2.c)
Author: Logan Merrill
Description: Second program in the "\n" character inclusion experiment. Does not include this character in the arguments passed to the printf function.
Compilation instructions: gcc -o 1-2.out 1-2.c
Execution instructions: ./1-2.out
Copyright 2011 Airshock LLC. All rights reserved.
*/
 
#include <stdio.h>
 
main()
{
	printf("Testing, 1, 2, 3.");
	return 0;
}
Output

I saved the two programs above as 1-1.c and 1-2.c, respectively, and then compiled and ran them on the command line. The output of these operations is as follows:

lab46:~$ cd src/cprog/experiments
lab46:~/src/cprog/experiments$ gcc -o 1-1.out 1-1.c
lab46:~/src/cprog/experiments$ ./1-1.out
Testing, 1, 2, 3.
lab46:~/src/cprog/experiments$ gcc -o 1-2.out 1-2.c
lab46:~/src/cprog/experiments$ ./1-2.out
Testing, 1, 2, 3.lab46:~/src/cprog/experiments$

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes, in that the data I collected during this experiment signified just how important the “\n” (backslash escape) character is when using the printf function.
  • was your hypothesis not applicable? No, actually. I thought it was very applicable to what I was trying to discover.
  • is there more going on than you originally thought? I don't think so. It seems that “\n” is used for only one purpose, to create newlines and “tidy up” the output of the printf function, which when considered in the context of programming is very significant when writing software applications. My hypothesis tested the significance of the “\n” backslash escape character, and the data I collected proved and conformed to my hypothesis.
  • what shortcomings might there be in your experiment? None that I have observed thus far.
  • what shortcomings might there be in your data? None that I have observed thus far.

Conclusions

Based on my experiment, I have surmised that the “\n” backslash escape character is indeed very important when used as part of an argument passed to the printf function because it creates newlines in the output of compiled programs. If newlines were not used, thus if the “\n” character were not employed, the output of formatted text strings would look weird, as seen in the data collected above, and may even alter the output of other parts of the program or interfere with the correct user interpretation of program output. From this experiment, I can now conclude that it is always a good idea to use the “\n” backslash escape character when using the printf function in your code.

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Experiment 3

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Retest

If you're doing an experiment instead of a retest, delete this section.

If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Are there additional resources you've found that you can add to the resources list?
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • If you find a deviation in opinion, state why you think this might exist.

Hypothesis

State their experiment's hypothesis. Answer the following questions:

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
  • What improvements could you make to their hypothesis, if any?

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

  • Are the instructions correct in successfully achieving the results?
  • Is there room for improvement in the experiment instructions/description? What suggestions would you make?
  • Would you make any alterations to the structure of the experiment to yield better results? What, and why?

Data

Publish the data you have gained from your performing of the experiment here.

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author?
  • Can you explain any deviations?
  • How about any sources of error?
  • Is the stated hypothesis adequate?

Conclusions

Answer the following:

  • What conclusions can you make based on performing the experiment?
  • Do you feel the experiment was adequate in obtaining a further understanding of a concept?
  • Does the original author appear to have gotten some value out of performing the experiment?
  • Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).

Part 2

Entries

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

cprog Topics

Keyword 1

Identification and definition of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 2

Identification and definition of the chosen keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 3

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 4

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 5

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 6

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 7

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 8

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 9

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 10

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 11

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 12

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

cprog Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Experiments

Experiment 1

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Retest

If you're doing an experiment instead of a retest, delete this section.

If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Are there additional resources you've found that you can add to the resources list?
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • If you find a deviation in opinion, state why you think this might exist.

Hypothesis

State their experiment's hypothesis. Answer the following questions:

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
  • What improvements could you make to their hypothesis, if any?

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

  • Are the instructions correct in successfully achieving the results?
  • Is there room for improvement in the experiment instructions/description? What suggestions would you make?
  • Would you make any alterations to the structure of the experiment to yield better results? What, and why?

Data

Publish the data you have gained from your performing of the experiment here.

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author?
  • Can you explain any deviations?
  • How about any sources of error?
  • Is the stated hypothesis adequate?

Conclusions

Answer the following:

  • What conclusions can you make based on performing the experiment?
  • Do you feel the experiment was adequate in obtaining a further understanding of a concept?
  • Does the original author appear to have gotten some value out of performing the experiment?
  • Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).

Part 3

Entries

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Month Day, Year

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

cprog Topics

Keyword 1

Identification and definition of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 2

Identification and definition of the chosen keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 3

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 4

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 5

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 6

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 7

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 8

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 9

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 10

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 11

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 12

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

cprog Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Experiments

Experiment 1

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Retest

If you're doing an experiment instead of a retest, delete this section.

If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Are there additional resources you've found that you can add to the resources list?
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • If you find a deviation in opinion, state why you think this might exist.

Hypothesis

State their experiment's hypothesis. Answer the following questions:

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
  • What improvements could you make to their hypothesis, if any?

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

  • Are the instructions correct in successfully achieving the results?
  • Is there room for improvement in the experiment instructions/description? What suggestions would you make?
  • Would you make any alterations to the structure of the experiment to yield better results? What, and why?

Data

Publish the data you have gained from your performing of the experiment here.

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author?
  • Can you explain any deviations?
  • How about any sources of error?
  • Is the stated hypothesis adequate?

Conclusions

Answer the following:

  • What conclusions can you make based on performing the experiment?
  • Do you feel the experiment was adequate in obtaining a further understanding of a concept?
  • Does the original author appear to have gotten some value out of performing the experiment?
  • Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).