Table of Contents

Brian Robbins Spring 2012 Opus

A window into a journey of learning

Introduction

Hi, my name is Brian Robbins. I am enrolled in the Information Technology program at Corning Community College and my major is “Technicial Support Specialist”. I am in my senior year of college and due to graduate in May of 2012 with an associates in applied science. I love working on computers and electronics, its more of a passion of mine than a future job. To take an old device and resurect it or do something to it and make it better than it was is not only fun, but is a great learning experience. I have diverse taste in music as I listen too all kinds from rock to techno. In my free time I like to go 4 wheeling, work my car and quad, and travel to new places (when time and money permits, lol). Programming is all new too me as I have mostly concentrated on the hardware aspect of computers up untill this point so taking a programming class will definately be a new, challenging experience for me. I hope to walk away from my last college semester with some new found knowledge that will broaden my horizons and allow me to look for work in other fields.

Part 1

Entries

Entry 1: February 3, 2012

Today we made progress with the online assignments that are due for my UNIX/Linux Fundamentals class. As part of one of the assignments we had to draw an ASCII file tree that showed our home directory within the UNIX directory structure. we also had to show 3 folders and 3 files that are contained within our home directory. Below is the finished image I created.

Entry 2: February 5, 2012

Well the first two weeks of classes are down and already I have learned so much about the C programming language. We have already written and compiled a few simple programs and it definitely been a fun learning experience. So far in class we have been focusing on the base structure of C programming, working with “printf” and “scanf” functions along with memory allocation (malloc) and learning how to use pointers in programming. All of these are siginificant because it is the basis of the programming. Without this knowledge a person cannot properely write code and expect it to compile and work with no issues. This information is also significant because it will also be used heavly utilized durring the progression of the course. This will definitely be the most challenging course that I have taken to date due to the fact that I have never taken a programming course, so this is definitely going to be an interesting semester.

  • The most significant thing learned to date would be pointers.
  • Pointers are very siginificant because they allow us to accomplish many tasks within a program while reducing the overall ammount of code that is required to make the program function properly.
  • Through the use of pointers you can have several processes access and control the information that is stored in one particular memory address instead of having to allocate more memory to perform a task.

Entry 3: February 9, 2012

Just completed the puzzlebox challenge for my UNIX/Linux class. The first parts I thought were pretty easy. I had to figure out the file type using the “file” command in Linux and then change the filenames so I could uncompress the files using various tools such as gzip and zip. The last part was pure evil for me and took me the better part of 2 days to figure out. The message was backwards and had a bunch of erroneous characters within it that had to be removed. I used a combination of the “sed” and “rev” commands to finally decrypt the message.

  • Today I learned how to identify files in UNIX/Linux with the “file” command.
  • This is significant because a user cannot rely on file extensions alone to determine what kind of file they are dealing with.
  • So far all of the concepts that I am learning in class are making sense due to my previous experiences with the UNIX/Linux operating system
  • So far the only challenge I have been faced with was the puzzlebox challenge that I just completed, mostly because I have never had any experience with the “sed” and “rev” commands.

Entry 4: February 16, 2012

Today was a challenging day in my C/C++ class. We were asked to write a program that encompassed all of the things that we have learned to date. The program had to accept command line arguments, prompt a user for a number between 0 and 4, and have data stored in a 2d array that could be called on by the selected numerical option. This was challenging simply because I have never wrote any code before. After writing the program and getting a helper or two from my instructor and classmates I finally understood how 2d arrays worked in C and I also learned the proper syntax for a while loop when using the loop to verify more then one rule.

Entry 5: February 23, 2012

Wow, what a week! Coming back from a mini break a the second project of the semester is coming due in my C/C++ class. I have already learned that I shouldn't wait until its almost due before I do the work as I sit here pounding my head against my desk. The program I have to create needs to cipher a message using a key that is provided either as a command line argument or is provided in an external text file. The message to be ciphered needs to be read from a test file and the new, ciphered message, needs to be wrote to a new text file. The hardest part of this entire program is figuring out the process that needs to occur and what statements need to be used to properly cipher the message. As this is not already hard enough a second program needs to be created that can decipher the ciphered message using the same key file or by providing the same key as a command line argument like the cipher program. Good thing its not due until tomorrow evening, I still have some time to get help on this from the IRC, lol.

Entry 6: February 25, 2012

Thank god! My instructor had mercy on our souls during this current project and has graciously extended our due date by another day. On top of that he has provided us with a hint as to what needs to be included in our code to make the programs work. Well after looking at the hint and implementing it into my program I still had issues. The message would cipher, but not correctly. The program was not ciphering by the key contained within the key file. The IRC was my biggest savior this time. After bouncing ideas back and forth with a fellow classmate I was finally able to get my programs to work properly. The hint was to make the program convert all characters within the message to there ASCII values, then cipher them with the key by adding the key to the ASCII value and then writing that value to a new file in its character form. The decipher program basically did the same thing but only the math in the program was reversed. Where you added in the cipher program, you subtracted in the decipher program. The issue with the key file turned out to be a simple statement make the program accept the numerical key from the file when performing the ciphering and deciphering equations. Finally my programs and the project are done and I can sleep a little easier tonight.

Entry 7: February 28, 2012

Today in class we dove into functions and wrote a small program that utilized a few different functions. The program would take a two command line arguments, the first would tell how many iterations of the program would run, then the second would determine the threshold of the resulting answers. Then the program would perform modular division using the second argument and a seed from srand. As long as the quotient is below the threshold the program would determine wether the answer was even or odd and then output the results on stdout. This was a new and interesting because I learned how functions actually work and how they are utilized witin a program, how to pump information into a function and get something meaningful in return. Before I started this class I thought I didn't neew any programming expreience because I didn't want to become a programmer, but now I am happy I have the change to learn about this because it's not only interesting, but it's something I can use later.

Entry 8: March 2, 2012

Working on finishing up the first part of this opus as it is due tonight at midnight. Thus far I have really learned alot between both classes, but more so in the C / C++ programming class. Its definatelly interesting and something I can use. I have also realized why Matt wants all students to create an opus. It allows us to not only keep a record of what we have learned but also allows us to show off our new found knowledge through the experiments that we do. To me this also seems like a great piece of work that could be added to a resume to allow a potential employer see what has been learned while earning your degree.

Keywords

cprog Keywords

Pointers

Definition

A pointer is a special type of variable in the C programming language that holds the memory address of another variable. The anatomy of a pointer is broken down into three parts, the address of, the assignment, and the dereferencing. First comes the addressing of the pointer. At this stage a pointer is defined within the programming language but currently doen not point to anything. Next comes the assignment of the pointer. In this stage the pointer is is referenced, or given a value to point at in memory. Last comes the dereferencing of the pointer. In this last stage the pointer is called on within the programming code. Because a pointer points to a value in memory, the value is being pointed to is either read out or written too depending on the operation that is taking place.

Demonstration

Below is a sample code of a pointer as found in the C programming language:

Note: A pointer is defined with a astrix before its name. The ampersand before “test” means “address of”, so we have basically said the pointer “link” points to the memory address of “data”.

/*
 * Sample code for a pointer
 */
#include <stdio.h>
 
int main()
{
    int data
    int *link; //On this line the pointer "link" is defined.
 
    *link = &data; //On this line we have set the "link' pointer to "point" to the information stored in "data".
    printf("The integer named "data" contains the value %hhu\n", data);
    printf("The pointer named "link" contains the value %hhu\n", *link);
 
    return(0);

Below is the resulting output of the above code once compiled:

lab46:~$ ./test
The integer named data contains the value 42
The pointer named link contains the value 42
lab46:~$

Header Files

Definition

A “header file” is a file that contains specific elements of a programs code such as commonly used declarations, variables, and other commonly used code into a packaged that is easily distributed and are reusable in other works. Commonly used header files include “stdio.h” which defines a systems standard input and output devices such as the monitor and keyboard, and “stdlib.h” which is a systems general utilities library and handels things like dynamic memory management and random number generation.

Demonstration

Below is a sample of header files being used within the code of a program.

/*
 * Sample code block
 */
#include <stdio.h> // On this line we are including the library "stdio.h" ("stdio" stands for "standard input/output")
#include <stdlib.h> // On this line we are including the library "stdlib.h" ("stdlih" stands for "standard library")
 
int main()
{
    char = *word
    word=(char*)malloc(sizeof(char)*24);
    return(0);
}

Standard I/O (STDIO, STDOUT, STDERR)

Definition

Input and output are absoutely necessary in a computer based world. If a computer has no input it has no purpose, and without an output we are unable to tell what the computer has done with the data we fed to it. But what if there is a problem, the computer needs a way to deal with a problem or error within the data that it has been fed. There exists a library, the C Standard Input and Output Library, known as stdio.h in the C language that contains all the necessary information a computer needs to interface with any standard input and output device. This library contains three standard streams, stdin, stdout, and stderr. Stdin handles input such as your keyboard and mouse. Stdout handles output to devices such as a monitor or printer. Stderr handles any error that may occurs and outputs an error message to the standard output device which is normally the monitor. These streams are automatically created and opened for any programs that access the library.

Demonstration

Below is an exmaple of Standard I/O as used in the C language.

/*
 * Sample code block
 */
#include<stdio.h> // This is where the C Standard Input/Output Library is introduced into the program code.
#include<stdlib.h>
 
int main()
{
        int datain=0, *dataout;
        dataout = &datain;
        printf("Please enter a number that is 0 or greater.");
        fscanf(stdin, "%d", &datain); // On this line the program accepts an input from a standard input device, most commonly the keyboard.
        while( datain < 0 )
        {
                fprintf(stderr, "You entered a number less than 0. Try again."); // This line tells the program to output an error message when an invalid value is given. Normally this error is directed to another file but in this case it has been redirected to the screen through the use of the fprintf statement.
                printf("\n");
                printf("\n");
                printf("Please enter a number that is 0 or greater.");
                fscanf(stdin, "%d", &datain);
                printf("\n");
        }
        printf("Your number is %d\n", *dataout); // Here the program outputs a result to the standard output device, most commonly the monitor.
        printf("\n");
        return(0);
}

Below is the output of the above code once compiled and executed:

lab46:~$ ./test
Please enter a number that is 0 or greater.0
Your number is 0

lab46:~$ ./test
Please enter a number that is 0 or greater.-1
You entered a number less than 0. Try again.

Please enter a number that is 0 or greater.1

Your number is 1

lab46:~$

Repetition/Iteration Structures (for, while, do while)

Definition

Repetition/Iteration structures are essential in the C programming language. These structures allow for a program to do multiple things without having to be restarted for each new process. There are 3 different types of structures, for, while, and do while, and each of these structures have a different purpose. A “for loop” will loop from one integer to the next while incrementing by specified ammount. A “while loop” can be used to run a process repetitively when the number of times a loop need to run is not known. A “do while loop” is almost the same as a while loop with one exception. After the loop has run once it will test the data to see if we have to continue or end the loop.

Demonstration

Below is an example of a repetition/iteration structure as found in the C programming language.

/*
 * Sample code block
 */
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        int datain=0, *dataout;
        dataout = &datain;
        printf("Please enter a number that is 0 or greater.");
        fscanf(stdin, "%d", &datain);
        while( datain < 0 ) // this is the beginning of the iteration structure. This iteration structure is a while loop and is designed to loop untill the proper input is given.
        {
                printf("You entered a number less than 0. Try again.");
                printf("\n");
                printf("\n");
                printf("Please enter a number that is 0 or greater.");
                fscanf(stdin, "%d", &datain);
                printf("\n");
        }
        printf("Your number is %d\n", *dataout);
        printf("\n");
        return(0);
}

Below is the output of the above code once compiled and ran:

lab46:~$ ./test
Please enter a number that is 0 or greater.0
Your number is 0

lab46:~$ ./test
Please enter a number that is 0 or greater.-1
You entered a number less than 0. Try again.

Please enter a number that is 0 or greater.1

Your number is 1

lab46:~$

File Access

Definition

File access in the C programming is the act of a program accessing a file for the purpose of reading the contents of a file, writing data to a new or existing file, or appending data to an existing file.

Demonstration

Below is an example of File access in the C programming language.

#include<stdio.h>
#include<stdlib.h>
 
int main()
 
{
        FILE *in,*out; // Here two file pointers are defined named in and out.
        char value=0;
        in=fopen("file.txt","r"); // Here the file "file.txt" is opened with read permissions.
        out=fopen("out.txt","w"); // Here the file "out.txt" is opened with write permissions.
        if(in==NULL)
        {
                printf("ERROR!\n");
                exit(1);
        }
        fscanf(in,"%hhd",&value);
        while(value!=-1)
        {
                value*=2;
                fprintf(out,"%hhd\n",value); // Here the program writes data to the file "out.txt" via the file pointer "out".
                fscanf(in,"%hhd",&value); // Here the program reads data from the file "file.txt" via the file pointer "in".
        }
        fclose(in); // Here the file "file.txt" is closed via the file pointer "in".
        fclose(out); // Here the file "out.txt" is closed via the file pointer "out".
        return(0);
}

Functions, Parameters

Definition

A function in the C programming language is a block of code that has a name and property that are reusable. This means that a function can be called on from as many different points in the program as needed.

A Parameter in the C programming language is any data that is passed to a function.

Demonstration

Below is an example of functions and parameters as found in the C programming language.

#include<stdio.h>
#include<stdlib.h>
 
int sum(int, int, int, int); //This is a function prototype for sum
 
float avg(int, int, int, int); //This is a function prototype for average
 
int main() // This is the "main" function of the program. "Main" defines what the program will actually accomplish when executed.
 
{
        int a=0, b=0, c=0, d=0, max=0, min=0;
 
        printf("Enter first value");
        fscanf(stdin, "%d", &a);
 
        if(a > max)
        {
                max=a;
        }
 
        printf("Enter second value");
        fscanf(stdin, "%d", &b);
 
        if(b > max)
        {
                max=b;
        }
 
        printf("Ented third value");
        fscanf(stdin, "%d", &c);
 
        if(c > max)
        {
                max=c;
        }
 
        printf("Enter fourth value");
        fscanf(stdin, "%d", &d);
 
        if(d > max)
        {
                max=d;
        }
 
        if((a < b)&&(a < c)&&(a < d))
        {
                min=a;
        }
 
        if((b < a)&&(b < c)&&(b < d))
        {
                min=b;
        }
 
        if((c < a)&&(c < b)&&(c < d))
        {
                min=c;
        }
 
        if((d < a)&&(d < b)&&(d < c))
        {
                min=d;
        }
 
        fprintf(stdout, "The sum of %d, %d, %d, and %d is %d\n", a,b,c,d,sum(a,b,c,d));
 
        fprintf(stdout, "The average of %d, %d, %d, and %d is %f\n", a,b,c,d,avg(a,b,c,d));
 
        fprintf(stdout, "The highest value entered is %d\n", max);
 
        fprintf(stdout, "The smallest value entered is %d\n", min);
 
        return(0);
}
 
int sum(int n1, int n2, int n3, int n4) // Here a function named "sum" is defined and the integer parameters n1, n2, n3, and n4 are passed to it. 
 
{
        int total=0;
        total=n1+n2+n3+n4;
        return(total);
}
 
float avg(int n1, int n2, int n3, int n4) // Here another function named "avg" is defined and the integer parameters n1, n2, n3, and n4 are passed to it.
 
{
        float total=0;
        total=(float)(n1+n2+n3+n4)/(4);
        return(total);
}

Arrays

Definition

An array is a collection of memory addresses that all store the same data type of and can be referenced through a common variable name. An array must be declared before they can be used in a program.

Standard notation is the standard syntax used within the C programming language to create or access an array.

Pointer Arithmetic is the method used to access an element or elements of an array.

There are two types of arrays that exist, single-dimensional and multi-dimensional. A single-dimensional array is an array that is organized into one single row or column. A multi-dimensional array is an array that is organized into multiple rows or columns.

Demonstration

Below is an example of arrays as found in the C programming language.

#include<stdio.h>
#include<stdlib.h>
 
int main(int argc, char **argv) // Here **argv is defining a multi-dimensional array. This array is fed from arguments that are entered at the time of the programs execution. 
{
        int datain;
        unsigned char i;
 
        printf("Please enter a value between 0 and 4");
        fscanf(stdin, "%d", &datain);
        while( datain < 0 || datain > 4) 
        {
                printf("You entered a value that is not between 0 and 4. Please try again");
                printf("\n");
                printf("Please enter a value between 0 and 4");
                fscanf(stdin, "%d", &datain);
        }
        for(i=0; i < argc; i++)
        {
                printf("argv[%hhu]: %c\n", i, *(*(argv+i)+datain)); // Here the array is de-referenced through the use of pointer arithmetic and an array element is read based on the result from the arithmetic. Note how the array is referenced as this is the standard notation for working with arrays.
        }
        return(0);
}

Variables

Definition

Within the C programming language, a variable is a name that is used to refer to a specific point in memory. There are four different types of variables which are int, char, float, and double.

The “int” variable type is used to store integers that are in the form of whole numbers. On a 32 bit computer system an “int” is 32 bits or 32/8 which is 4 bytes length. This means that an “int” has the possibility of storing one of 4294967296 different possibilities.

The “char” variable is capable of holding any member of the character execution set. A char can hold the same kind of data that an “int” can but a char is normally 8 bits or 8/8 which is 1 byte in length.

The “float” variable, short for “floating point” is used to store real numbers. A “float” is only the size of one machine word size which on todays system is typically 32 bits or 32/8 which is 4 bytes in length.

The “double” variable, short for “double floating point” is similar to a normal “float”. While a “float” only allows for the storage of integers a “double” allows for the storage of both integer and non-integer data. The reason its called a “double” is due to the fact that it is double the size of a “float” which makes it 64 bits or 64/8 which is 8 bytes in length.

Demonstration

Demonstration 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()
{
    int num=8; // Here an "int" variable is declared and is initialized with the integer number 8.
    char i; // Here a "char" variable named "i" is declared.
    float data; // Here a "float" variable named "data" is declared.
    double input=2x; // Here a "double" variable named "input" is declared and it initialised with a value of 2x.
    return(0);
}

cprog Objective

cprog Objective

The objective of this course is to learn both the C and C++ programming languages and how to properely utilize them.

Definition

This objective entials that a working knowledge of the C and C++ languages will be gained. This includes understading the languges and there proper syntax which includes the usage of pointers and variables, if/then/else statements, memory management, how to compile source code composed of C or C++ language.

Method

Successfull completion of this objective means that I would be able to look at any source code that is written in C or C++ and be able to understand what the program is accomplishing.

Measurement

Due to the current stage of completion of this course I cannot yet measure this accurately. While I have learned a great deal thus far I am still not at a level where I could say that I have met all of the course objective.

Analysis

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

  • At this point in time I do believe I am progressing at a good pace.
  • I do believe there is room for improvement but this inprovement will occur with further progression within the course.
  • Yes, the measurement could be enhanced to further reflect on many different parts of the course obective.
  • I do think this enhancement would be effective to employ and I will be employing this enhancement durring the progression of the course.

unix Keywords

Local Host

Definition

A “local host” is the local computer that a user is operating. A “local host” is also the standard name given to the loopback IP address of the network interface of a computer. This “local host” address is the address a computer can use to refer to itself when doing anything network or internet related.

Remote Host

Definition

A “remote host” is the term used to decsribe a remote system that users can connect to. Examples of a “remote host” would include webserver, file server or any system that allows remote client to connect to it.

Home Directory

Definition

The “home directory” is the directory for a particular user on a multi-user operating system. This directory contains all of the users settings and any files the particular user created.

Current Working Directory

Definition

The “current working directory” is the directory the user is currently residing in. A user can change there “current working directory” by issuing the “cd” or change directory command at the Linux command prompt.

Demonstration

Below is a sample that shows the “current working directory” and how to change the “current working directory”:

lab46:~$                   // This line shows that the current working directory is the home directory which is denotated by the "~" symbol.
lab46:~$ cd src            // This line shows the "cd" command being used and the directory name the user wants to switch to that is inside the home directory.
lab46:~/src$               // This line shows the result of the "cd" command that was issued. Note how the prompt has changed to show the new current working directory and its location to the home directory.

Types of Files

Definition

The Unix / Linux operating systems have 3 types of files which are, directory, regular, special.

The “directory” file type is a type of file that contains a list of other files and directories within it. these files are denotated with a “d” when a long directory listing is done.

The “regular” file type is the most common file type. These are the kinds of files that contain user data such as programs, documents, audio/video files, etc. these files are denotated by a hyphen when a long directoty listing is done.

The “special” file type encomapsses all other files that are not classified under the “directory” or “regular” types. These files include symbolic links which is denotated by an “l” when doing a long directory listing, a character deivce denotated by a “c”, a block device denotated by a “b”, etc.

Demonstration

Below is an example of the different file types found, note the information in the long directory listing.

system:/dev$ ls -l
crw------- 1 root root  10, 231 Jan 17 15:39 snapshot  //This is a character device which is a special file type, note the "c" designation for the character device file type.
drwxr-xr-x 2 root root       60 Jan 17 15:39 snd       //This is a "directory" file type, note the "d" designation for the file type.
lrwxrwxrwx 1 root root       24 Jan 17 15:39 sndstat -> /proc/asound/oss/sndstat  //This a also a special file type called a symbolic link, note the "l" designation for the file type.
-rw-r--r-- 1 user user      485 Feb 16 21:45 test.c    //This is a "regular" file type, note the "-" designation for the file type.
system:/dev$

The Unix Shell

Definition

The Unix Shell is the command line inteperter for Unix and Unix-like operating systems. This shell provides the user with a command line driven interface for the operating system. From this interface a user can execute programs, perform file manipulation and more. The Shell is also a scripting programming language for these operating system. Common operations performed with shell script include file manipulation, the execution of programs, and printing text.

Demonstration

Below is an example of the Unix Shell interface.

lab46:~$ cp test.c ~/script/test.c // Here file manipulation is occuring, the file test.c is being copied into the folder named "script" and is being named "test.c".
lab46:-$

Shell Scripting

Definition

Shell scripting is a programming language for the shell environment. Unline some programming languages this is a high level programming language. Shell scripts are most useful for program automation or when several programs need to be ran over and over. Instead of a user having to enter the commands over and over a script file can be created with the commands that are needed and then only the single script file needs to be executed, and in turn, the script will be read by the command interperter and the commands will be executed.

Demonstration

Below is an example of a Unix shell script. The script below will execute the mount command and mount a cd that is inserted in a cdrom drive at the mount point “/mnt/cdrom”. Then the script will then execute the cp command and copy the contents of the cdrom to a folder named “files” in the root directory. The the “tar” command is executed and the files located in the file/ directory are copied into an archive named “cdrom.tar”. Lastly the gzip command executes and conpressed the cdrom.tar archive.

/*
 * Sample Shell Script Code
 */
#!/bin/bash
mount /dev/cdrom /mnt/cdrom
cp /mnt/cdrom/file1*.* /files/
tar -cf cdrom.tar /files/*.*
gzip cdrom.tar

File Manipulation

Definition

File manipulation is the process of accessing a file or files for the purpose of performing some action upon them. These actions include but are not limited to reading the contents of a file, writing data to a file, deleting a file, changing the permissions on a file, etc.

Demonstration

Below is an example of file manipulation.

lab46:~$ cp file1 file2.txt                   //Here file manipulation occurs in the form of a file copy. The contents of file1 are being copied into a file named "file2.txt".
lab46:~$ rm file1                             //Here file manipulation occurs in the form of the deletion of the file named file1.
lab46:~$ echo "Hello World!" > file3.txt      //Here file manipulation occurs in the form of file creation and a file write procedure. The output of the echo command is piped into a file named "file3.txt". If this file didn't exist before, the file is created and then the output is written to the file.
lab46:~$ cat file3.txt                        //Here file manipulation occurs in the form of a file read. The file "file3.txt" is being read out and the contents are printed on the standard output device.
Hello World!
lab46:~/src$ 

unix Objective

unix Objective

The objective of this course is to gain a working knowledge of the Unix / Linux operating systems. This includes file manipulation, package management, shell scripting, desktop environments, etc.

Definition

This objective entails a systematic learning experience of the different parts of the Unix / Linux operating system from very basics such as file manipulation, to more advnace techniques such as shell scripting, which is the creation of scripts to automate certiant processes within the Unix / Linux operating system.

Method

By completing the labs and case studies associated with the course and by reading the text for the course and applying that knowledge to the course work I shall gain a mountain of knowledge of the Unix / Linux operating systems.

Measurement

Successfull completion of this course would entail gaining a working knowledge of the information gathered from the course and being able to demonstrate the knowleged that was obtained from the text and prior coursework.

Analysis

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

  • So far I believe I am progressing at a good pace.
  • There is always room for inprovement due to the fact that there is always more to learn.
  • I do not believe the process could be improved. The only way to really learn is by doing, so by doing the associated work I will learn the new information.
  • I do not believe the course objective could be altered. This course is about Unix / Linux, which means I will be learning about these operating systems which I believe my statement of the course objective covers.

Experiments

Experiment 1

Question

A question was asked in class today. That question was, what would happen if the “break” argument inside a function was replaced with the “exit” command? Would this cause just the function embedded within a program to end or would this cause the entire program to unexpectedly exit?

Resources

C Programming Language Second Edition C Pocket Reference

Hypothesis

Based on what I have learned about the C programming language thus far, I believe that the use of the exit command within a function will only cause the function to exit and not the entire program due to the fact that the exit argument would only be in scope with the current function and not the rest of the program.

Experiment

To test my hypothesis I am going to modify a program that was created in class on March 1, 2012. I will first however execute the program as it was created and record the resulting output so I will have something to test against and compare data with. The program that I will be modifying is the same program that brought about this interesting question. I will modify one of the functions within the program to reflect the arguments in question, then compile the program, execute it and record the resulting output. By comparing the output from the two I will then be able to draw a conclusion about the arguments in question.

Data

This is the original code that I will utilize in this experiment.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int iseven(int value)
{
        int tmp;
        tmp=value % 2;
        return(tmp);
}
 
void add(int *list, int total, int value)
{
        int i, s=0;
        for(i=0; i < total; i++)
        {
                if(*(list+i)==-1)
                {
                        *(list+i)=value;
                        s=i;
                        break;
                }
        }
}
 
int *init(int total, int *status)
{
        int i, *tmp;
        *status=0;
        if(total > 0)
        {
                tmp=(int*)malloc(sizeof(int)*total);
                for(i=0; i < total; i++)
                {
                        *(tmp+i)=-1;
                }
                *status=1;
        }
        return(tmp);
}
 
int main(int argc, char **argv)
{
        int *list, i, x=0;
        list=init(atoi(*(argv+1)),&x);
        if(x==0)
        {
                fprintf(stderr, "Error on initialization!");
                exit(1);
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                if(iseven(*(list+i))==0)
                {
                        fprintf(stdout, "%d is even\n", *(list+i));
                }
                else
                        fprintf(stdout, "%d is odd\n", *(list+i));
        }
        return(0);
}

This is the output received from the unmodified code.

lab46:~/src/cprog$ ./iseven 5 30
13 is odd
16 is even
27 is odd
25 is odd
23 is odd
lab46:~/src/cprog$

The following is the code that has been modified to reflect the question above. Note the change in the “add” function, the “break” statement has been changed to an “exit” statement with a return code of zero. Also note the inclusion if the new printf statements within each function. These are included so I am able to tell how far the program progresses.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int iseven(int value)
{
        printf("Diag 1\n");
        int tmp;
        tmp=value % 2;
        return(tmp);
}
 
void add(int *list, int total, int value)
{
        printf("Diag 2\n");
        int i, s=0;
        for(i=0; i < total; i++)
        {
                if(*(list+i)==-1)
                {
                        *(list+i)=value;
                        s=i;
                        exit(0);
                }
        }
}
 
int *init(int total, int *status)
{
        printf("Diag 3\n");
        int i, *tmp;
        *status=0;
        if(total > 0)
        {
                tmp=(int*)malloc(sizeof(int)*total);
                for(i=0; i < total; i++)
                {
                        *(tmp+i)=-1;
                }
                *status=1;
        }
        return(tmp);
}
 
int main(int argc, char **argv)
{
        printf("Diag 4A\n");
        int *list, i, x=0;
        printf("Diag 4B\n");
        list=init(atoi(*(argv+1)),&x);
        printf("Diag 4C\n");
        if(x==0)
        {
                fprintf(stderr, "Error on initialization!");
                exit(1);
        }
        printf("Diag 4D\n");
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                printf("Diag 4Da\n");
                add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
                printf("Diag 4Db\n");
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                if(iseven(*(list+i))==0)
                {
                        fprintf(stdout, "%d is even\n", *(list+i));
                }
                else
                        fprintf(stdout, "%d is odd\n", *(list+i));
        }
        return(0);
}

The following is the resulting output after the modifications were made to the original code, and the code was compiled and executed.

lab46:~/src/cprog$ ./iseven 5 30
Diag 4A
Diag 4B
Diag 3
Diag 4C
Diag 4D
Diag 4Da
Diag 2
lab46:~/src/cprog$

Analysis

Based on the data collected:

It turns out after reviewing the collected data that my original hypothesis appears to be incorrect. The modified program runs to the point of calling the “add” function. When the program calls the “add” function, the function is executed and the “exit” function is read which then terminates the entire program instead of terminating the parent function and returning back to the “main” function to allow the program to complete.

Conclusions

I have concluded that it does matter where the “exit” function is located within a program due to the fact that it will terminate whatever is happening at that point in time. Within the scope of this experiment and the above program it is best to use the “break” function to allow the program to continue its function and complete the program routine.

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.

Part 2

Entries

Entry 5: March 9, 2012

Today I worked on case study 7 for my Unix / Linux class and learned about the time based job-scheduler named 'cron' and I also learned about IRC bots. As it turns out 'cron' is a very useful tool and can be used to automate processes or jobs that need to be executed at certain intervals such as performing a file system integrity check or checking for package updates. IRC bots can also be a useful tool to utilize as I found out. Following the instruction from the case study I was able to download, configure and launch the 'phenny' bot. Configuration was pretty straight forward and simple. All that needed to be done was edit the default configuration file and enter the IRC server and owner details. After that it was as simple as launching the bot and let it connect to the IRC server. Bots also have a very useful purpose as they can be configured with extra modules to make them perform different tasks such as checking the weather in a specified location, getting the current time from an Internet time server, etc. Both of these things can be very useful when utilized properly.

Entry 6: March 17, 2012

This past week has by far been the toughest yet in my C/C++ class. I began work on project 2 earlier in the week and I have been banging my head ever since. I don't know if it's because I am not “absorbing” what I am learning in class, or if it's just the way I am trying to write the my program. I just seem to be having a really hard time actually figuring out what needs to be done in my code to accomplish the task. I have been in the class IRC today for almost 12 hours straight and while it definitely helped a lot, I feel that there is still something that I am either not understanding, or overlooking, or something. Right now I have a partial program with 2 functions that do not properly work and I am at a loss as of right now as to what I can try next. I guess I will sleep on it tonight and start fresh tomorrow and see what I can accomplish.

Entry 7: March 24, 2012

A lot has happened since my last entry. I have been working on project 2 and with help from the IRC and the instructor I finally have the first two modules working properly with the exception that any numbers used must be padded with zeros. I am now working on the multiplication and division functions but I am finding them difficult also. I know what has to be done in the multiplication function but when I implement the problem in code it doesn't work. I think my logic is flawed and will have to continue working on and to find the problems. Switching gears we have been talking about classes and inheritance. I class this past week we created a small program that uses classes. The program taught me how to write functions into reusable files and how to compile multi file programs into executable code. Also out instructor has saved us once again and combined project 2 and project 3 together so now I have more time to figure out the problems with my code. Well thats all for now, back to work on the project.

Entry 8: March 31, 2012

Well its the last day of March and getting closer to spring break. Still working on project 2/3 and while I am making progress I am still having issues with the actual math functions. This past week the instructor gave us class time to work on our programs along with time to work on things we were having problems with in class. Unfortunately I have decided to drop my Unix class so I am able to put forth more effort in the C/C++ class along with my other classes. Well thats it for now, I know its short but I have other things to attend to (the project mainly). Will make an update later as to what happened with it.

Keywords

cprog Keywords

typedef, enum, union

Definition

Typedef allows a user to define there own identifiers. These new identifiers can be used in place of type specifiers such as int, float, and double. A typedef declaration doesn't allocate any additional storage and the names defined using typedef are not new data types rather they are merely synonyms for the data types they represent. When an object is defined using a typedef identifier, the properties of the defined object are exactly the same as the original data type they represent.

Enum short for “enumerated data”. enums allow a user to define a fixed set of words that a variable of type enum can use as its value. The words are assigned integer values by the compiler so enum values can be compared.

A union is comprised of a collection of variables of different types, just like a structure. However, with unions, you can only store information in one field at a time. Once a new value is assigned to a field, any existing data is overwritten with new data. The use of unions can save memory if you have a grouping of data and only one of the types is used at a time. The size of a union is dependent on the size of it's largest data member.

Type Casting

Definition

Type casting also known as type conversion is the concept of converting one data type to another data type. For example you might have a float data type that needs to be an int data type for use in some part of a code.

Demonstration

Below is an example of Type Casting in C.

#include <stdio.h> 
 
int main()       
{
  /* The (char) is a typecast. Its telling the computer to interpret the 32 as a
     character, not as a number.  The output of will be the ASCII 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)32 );
  getchar();
}

Scope

Definition

Scope refers to the way data is declared and accessed within a program.

Global scope, found in C++, occurs when a name is declared outside of all blocks, namespaces, and classes. The name is accessible anywhere after its declaration.

Local scope also know as Block Scope, occurs when a name is declared within a block. The name can be used within the block that it was created in and any child blocks that are enclosed within the parent block.

File scope, found in C, occurs when a name is declared outside all blocks or classes. The name is accessible anywhere after it is declaration.

Demonstration

Below is a demonstration of Scope.

/*
 * Sample code block
 */
#include <stdio.h>
 
void test{int} //This function prototype has file scope because it is defined outside any block, namespace, or class.
 
int main()
{
   int z=0; //This variable has been declared within a block of code this giving this block scope.
 
   return(0);
}

Selection Structures

Definition

Selection structures also known as control structures are special structures found in the C and C++ programming language. These structures allow for one of multiple possible scenarios to occur based on the value of a variable.

Demonstration

Below is an example of an If structure.

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    int a;
    int b;
    int c;
 
    if (a > b)
    {
        c = a * b;
    }
    else
    {
        a = b * c;
    }
 
    return(0);
}

Below is an example of a case/switch structure.

/*
 * Sample code block
 */
#include <stdio.h>

int main()
{
    char a;
    char b;
    int c;
    int d;
    
    switch(d)
        {
        
            case 1:
            
                statement;
            
                break;
            
            case 2:
        
                statement;
            
                break;
            
            case 3:
        
                statement;
            
                break;      
                
        }
        
    return(0)
}

Logic and Operators

Definition

Logic can be defined as the non-arithmetic operations performed by a computer, such as sorting, comparing, and matching, that involve true-false decisions.

Operators can be defined as symbols that are used to perform operations. There are 8 logic operators available in the C and C++ programming language and those are !, &&, ||, ^, !=, &=, |=, ^=.

The “!” notates logical “NOT”

The “&&” notates logical “AND”

The “||” notates logical “OR”

The “^” notates logical “XOR”

The “!=” notates logical “NOT_EQ”

The “&=” notates logical “AND_EQ”

The “|=” notates logical “OR_EQ”

The “^=” notates logical “XOR_EQ”

Arithmetic

Definition

Arithmetic is the portion of mathematics that deals usually with the non-negative real numbers including sometimes the transfinite cardinals and with the application of the operations of addition, subtraction, multiplication, and division to them

Operators can be defined as symbols that are used to perform arithmetic operations.

Demonstration

Below is an example of arithmetic in C along with some of the basic mathematical operators available in the C language.

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    int a=20;
    int b=5;
    int c=0;
 
    a + b = c; //Add
 
    a - b = c; //Subtract
 
    a * b = c; //Multiply
 
    a / b = c; //Divide
 
    a % b = c; //Modulo(Remainder)
 
    return(0);
}

Structures

Definition

A structure can be defined as a collection of variables that can be accessed under one variable name thus providing a way to keep related information grouped together.

Demonstration

Below is an example of structures found in the C language.

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    int t;
 
    struct //This keyword tells the system a structure is being declared.
    {
        char name[30];
        char street[40];
        char city[20];
        char state[3];
        unsigned long int zip;
    } addr_info;
 
    addr_info.zip = 14830; //Here the zip element is accessed and the zip is written to it.
 
    gets(addr_info.name); //This statement passes a character pointer to the beginning of name.
 
    for(t=0; addr_info.name[t]; ++t)
 
    putchar(addr_info.name[t]);
 
    return(0);
}

Namespaces

Definition

Namespaces are an optionally named scope. Names can be declared inside a namespace just as you would for a class or an enumeration. You can access names declared inside a namespace in the same manner you access a nested class name by using the scope resolution (::) operator. Namespaces however, do not have the additional features that classes or enumerations possess. The main purpose of namespaces are to add an additional identifier (the name of the namespace) to a name.

Demonstration

Below is an example of namespaces as found in the C++ language.

/*
 * Sample code block
 */
#include <iostream>
using namespace std;
 
namespace primary
{
  int var = 5;
}
 
namespace secondary
{
  double var = 3.1416;
}
 
int main () 
{
 
    cout << primary::var << endl;
 
    cout << secondary::var << endl;
 
    return 0;
}

cprog Objective

Experiments

Experiment 4

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 5

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 2

Perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Provide 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

Entry 9: April 22, 2012

Wow, its been a long time since I have posted anything. Still working on the projects required for my C/C++ class. Its getting down towards the end of the semester, only 2 weeks left. I am swamped from all my other classes. I wanted to do much better then I have on this opus but have found it incredibly difficult to keep up with between juggling my other classes, work, and life in general. I just hope I have learned enough to pass the class. I have to admit, this class has been a struggle. It seemed pretty easy starting out, but as things progressed I started finding the course difficult to grasp. I'm still having a hard time with the concept of modules and classes which is why project 3 has yet to be completed. I just hope the instructor has some mercy when it comes to grading because I have tried my hardest and stuck it out the entire semester not missing a single class. Well I guess that's all for right now. Back to work on other matters at hand.

Entry 10: April 26, 2012

Not much has changed. Still working away on getting project 3 done. I am getting closer to the end of it but still have to figure out the exponent and modulus functions. The exponent function so far has been giving me problems and I think it due to the way my multiplication and addition functions are written. Hopefully I can get this finished up soon so I can start on project 4. Well that all for now. I will post again once I have made progress on my current project.

Entry 11: May 1, 2012

Well I have figured out that the problems I was having with project 3 were indeed due to the way the multiplication and addition functions were written. I am now in the process of writing an entirely new exponent module from scratch and abandoning the possibility of calling the other 2 functions from within the exponent function. I have also been reading up on the pow function what will do what I want but it has its drawbacks. The major one is the fact that pow relies on integer data to perform its operation. I will keep working on it and only use pow as a last ditch effort to get the function working. Well back to work, the end is drawing near and I still have a ton of work to do.

Entry 12: May 3, 2012

Well its the last official day of class, next week is finals week and then its all over. I can end the week on a good note. I now have functioning exponent and modulus functions in my project 3. I ended up using pow for the exponent function which was not the best thing but at least it works. The modulus function on the other hand does utilize previously created functions and does work as expected so modulus does not have the limitations that exponent does. I wish I had the time to do all the experiments that were wanted for the C/C++ class but I put forth so much time and effort on the projects for this class and my other classes that I just never had the time to do them. I have to sit back though and think that all the trial and error that I went through to complete the projects would make up for the experiments that were not done because this class as a whole is based on experimentation. I had to experiment with many different things to figure out what worked and what didn't and the results of those experiments are the projects that were produced. Well I guess that is it, now to work on the end of course experience and hopefully graduate in a couple of weeks. Its been a long and challenging path but it has been a rewarding one and I can safely say that I can come away from this semester with knowledge that I didn't have when it all started. If time permits I will hopefully make one more post when everything is done and I can finally sit back and breath a sigh of relief.

cprog Keywords

Compiler, Preprocessor, Flags, Assembler, Linker, Milti-file Programs
Definition

Compiler - A compiler is a program that can assemble a human readable source code into machine code that a system can execute.

PreProcessor - A preprocessor is a program that performs some sort of preliminary processing on an input before being processed by the main program.

Flags - A flag is a variable or memory location that stores a true-or-false value, normally either recording the fact that an event had occured or a request for a certain action to take place.

Assembler - An assembler is a program that is used to convert instructions written in a low level code into maching code.

Linker - A computer program that adjusts two or more machine language program segiments so they can be loaded simultaneously and executed as one unit.

Multi-file Programs - Multi-file programs are programs that have been broken up into easier to manage blocks of code. Normally functions have there own file and each function has its own header file. This is done to keep code modular and organized. Keeping code modular like this allows for code to be reused elsewhere.

Demonstration

Below is a link to a Mulit-file program I have created. Once you click on the link simply scroll down to the code section of the page. Note how all the functions have there own seperate file.

http://www/user/brobbin4/portfolio/cprogproject3

I/O Streams
Definition

I/O streams are channels in which data can flow to or from any I/O device. I/O device is a device such as a keyboard, mouse, disk drive, basically anything that can either send input to a system or recieve output from a system.

In C++ an I/O stream can be refered to any data stream that sends data into a program or recieves data from a program.

C++ does not have I/O streams built into the language and instead use the iostream library to provide the necessary information to handel I/O streams. C++ has some basic I/O streams available to it which are cin, cout, cerr.

cin - the C++ standard input cout - the C++ standard output cerr - the C++ standard error handler. This is used when a program ancounters an error and needs a place to send that error information.

Stream operators can be defined as an operator that has an influence on how the data from I/O Streams are handeled.

Type Casting Operators, Const-Volatility Specifiers
Definition

Type casting operators are operators that are used to change one data type to another data type. The most general cast operator supported by most C++ compilers is “(type) expression” where type is the desired data type.

Const short for constant means something is not modifiable, so data objects that are declared with const as a part their type specifications must not be assigned to in any way during execution of a program. Most of the time the definitions of the objects will contain an initializer because you cannot assign it and if they didn't contain an initializer you would never get a value.

Volatile means something can me modified and we have this type specifier mainly for problems that are encountered in real-time or embedded systems programming using C++. For example you are creating code that will control a hardware device by placing values in hardware registers at known absolute addresses. Because this is happening in real time we need a way to change these values on the fly but most C compilers have not been able to handle this in the past. To correct this issue and other issues that have to do with when to write to where a pointer points the volatile keyword was introduced. This tells a compiler that an object is subject to sudden change for reasons which cannot be predicted from a study of the program itself and this forces every reference to such objects to be a genuine references.

Classes
Definition

A class is an expanded concept of a data structure. A class is the definition of an object and thus a class can hold not only data but it can hold functions too. Classes resemble structs with one difference, all struct members are public by default where all class members are all private by default.

Objects - objects are components of a program that know how to perform certain actions. Objects also know how to interact with others pieces of a program.

Constructor - A constructor is a member function with the same name as its class. Constructors are called as such because they construct the values of data members of the class. A constructor resembles an instants method but differs from a method because a constructor never has an explicit return type.

Destructor - A destructor is like a constructor is the fact that it is a member function with the same name as its class and that it resembles ans instants method but never has an explicit return value. A destructor is used to deallocate memory and do other cleanup tasks for a class object and its class members when an object is destroyed.

Access Control - C++ employs access control to limit access to certain data within a class. below are the ways that this is accomplished.

Public - members specified within the public section of a class are accessible from any function.

Protected - members specified within the protected section of a class are accessible only by the functions of the class that original declared the members, friends of the class that originally declared the members, classes derived with public or protected access from the class that originally declared the members, and direct privately derived classes that also have private access to protected members.

Private - members specified within the private section of a class are accessible only from member functions and friends of the class.

Friend - A friend allows a function or class to gain access to to the private and protected members of a class in which they are not a member of.

“This” Pointer - “this” pointer is a pointer that is accessible only within the non-static member functions of a class, struct, or union. It points to the member function for which the member function is called.

Inheritance
Definition

Inheritance is the mechanism of reusing and extending existing classes without modifying them. Inheritance is kinda like embedding an object into a class. For example, you declare object c of class M in the class definition of R. The result is class R will have access to the public data members and member functions of class M, however in class R you will have to access the data members and member functions of class M through object c. In single inheritance classes have only one base class while in multiple inheritance classes may have multiple base classes.

Polymorphism/Virtual Functions - A key feature of derived classes is that a pointer to a derived class is type-compatible with a pointer to its base class. Polymorphism means that a call to a member function will cause a different function to be executed dependent on the type of object that invokes the function. A virtual function is a function in a base class that is declared using the keyword virtual.

Abstract Base Class - An abstract base class is a base class that contains at least one pure virtual function. A pure virtual function is declared by using a pure specifier in the declaration of a virtual member function in the class declaration.

Overloading
Definition

Overloading is the practice of supplying two or more definitions for a given function name in the same scope. The compiler is left to pick the appropriate version of the function or operator based on the arguments with which it is called.

Functions - Function overloading is the act of declaring more then one function with the same function name in the same scope. The declarations of each function must differ from each other by the types and/or the number of arguments in the argument list. When an overloaded function is called the the correct function is selected through comparison of the argument list of the of the function call with the parameter list of each of the overloaded candidate functions with the same name.

Operators - The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or “overloads” it. The compiler distinguishes between the different meanings of an operator by examining the types of its operands.

Exception Handing
Definition

Exceptions are run-time anomalies, such as divide by zero, that require immediate handling when encountered. The C++ language provides built-in support for raising and handling exceptions. With C++ exception handling, a program can communicate unexpected events to a higher execution context that is better able to recover from such abnormal events. These exceptions are handled by code that is outside the normal flow of control.

Throw, Try, Catch - these three keyword are the basis of error handling in the C++ language and are defined below.

Throw - A program throws an exception when a problem shows up. This is done using a throw keyword.

Try - A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.

Catch - A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.

Templates, STL
Definition

Templates are mechanisms for generating functions and classes based on type parameters. Through the use of templates, you can design a single class or function that operates on data of many types, instead of having to create a separate class for each type.

STL - The STL or Standard Template Library is a collection of C++ libraries that allow the use of several well known kinds of data structures without having to program them. The templates are designed to efficiently run code. The compiler does most of the work of generating the efficient implementations of the templates.

cprog Objective

Experiments

Experiment 7

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 8

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 3

Perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Provide 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).