======Part 1======
=====Entries=====
====September 16th, 2011====
These last few weeks of class have been crazy. Over the summer my programming was lacking in quantity so it was that much harder to transition into this semester. But i was able to catch up and even learn about these few things already!
* The use of malloc to allocate the size of a pointer array
* The use of argv and argc in my main functions
-This was useful because i can now accept command line arguments!!!
Some topics that i am having a lot of trouble understanding are:
* Linked lists
There is not much to linked lists, i understand the concept of tmp -> next = start or a line like such. But when to put which line, and the order of the commands is quite confusing to me!!!!!
====September 19th 2011====
I am pretty sure that the linked lists light buld just clicked! For my class project in data structures i am creating a linked list implementation using characters. It will have several different functions that will be in several different files, all used as a library.
* I was alluded by how i was to pass a list into a function to modify it, and then i realized(with a little help) that that was not the case!
* I am still trying to grasp it all, and i have a few things to sort out, but i believe my linked list project will go quite smoothly from here on out!
* Whereas linked lists do not yet seem like a good thing to me, i am sure they have their uses. Right now they seem like a waste of time, and way too much of a hassle.
*
====September 22nd, 2011====
I have to say that at first i was skeptical, but as i progressed the deffinitions started to help. Every deffinition I have done so far has helped me learn something. Whether it is a small syntax issue, or a major use issue where i didn't even know that certain function/use existed! So far i have done:
*Pointers
*arrays
*version control
*etc...
One thing that puzzles me now is still linked lists!!! I now have to remove a whole list, and deallocate the memory it was using, kinda hard for me.
an example of what i am trying is below:
deletelist(Node *thing, Node *stop) //function must be passed the first and last node in the list
{
if(thing = stop)
{
free(thing);
}
else
{
Node *test;
test = (Node *) malloc (sizeof(Node));
while(thing != stop)
{
test = thing -> next;
thing -> next -> prev = NULL;
thing -> next = test;
free(thing);
thing = next;
}
free(stop);
free(test);
free(thing):
}
}
====September 25th, 2011====
And i used to think that a library was that place down the street where nerds banded together to feel safe... But they are so much more!!! We have been working with librarys in not just Data Structures, but discrete structures aswell, and i am so glad we have! There are a lot of lessons to learn from library building. Like for instance:
-Making sure all of your files are labeled clearly since libraries can be very large.
-Making sure no header files are double listed.
-making sure to always update, compile, and save every file as you work on it.
=====DATA Topics=====
====Pointers====
A pointer is a variant of a data type that deals with location. A pointer "points to" a storage address. So if you reference a storage address, call it address A, and that address contains another storage address, say address F, address A is then a pointer to address F.
in the program below, c is a pointer to a.
#include
int main()
{
int a=5;
int b=7;
int c;
int d;
c=a;
d=b*c;
printf("%d\n", d);
return(0);
}
====Allocation====
-Static vs. Dynamic
===Static===
Not all variables are automatically allocated. The following kinds of variables are statically allocated:
*all global variables, regardless of whether or not they have been declared as static;
*local variables explicitly declared to be static.
Statically allocated variables have their storage allocated and initialized before main starts running and are not deallocated until main has terminated.
String constants (except those used as initializers for variables of type array of char) are statically allocated. In most expressions a string constant generates a pointer to the first char in the string.
#include
int main(void)
{
char s[] = "dog";
char *e = "food";
printf("A %s eats %s\n", s, e);
return 0;
}
===Dynamic===
The problem with static allocations is that the programmer must know before hand how much data the program will need to handle. So he or she must make a guess at the largest possible amount of data that could be used. Dynamic allocation is the automatic allocation of memory in C/C++, Unlike declarations, which load data onto the programs data segment, dynamic allocation creates new usable space on the programs STACK.
{
#include
int main()
int *array;
array=(int *) malloc(size*sizeof(int));
return 0;
}
====Version Control====
Version control is simply the management of changes to files, documents, programs many other types of information stored as computer files. This is widely used by large programming teams where many people edit the same file. Bugs or features of the software are often only present in certain versions because of the fixing of some problems and the introduction of others as the program develops. Therefore, for the purposes of fixing bugs, it is very important to be able to retrieve and run different versions of the software to determine in which version(s) the problem occurs.
A few functional uses of version control are:
-Commit
*Commiting changes made to a working file back into the repository
-Check-out
*Check out a working copy of the file from the repository
-Update
*merges changes made in the repository (by other people, for example) into the local working copy.
====Arrays, Pointer arithmetic====
===ARRAY===
An array is a is a data type that can be indexed. It is described as a collection of elements, or information segments. An array is storage of any data type.
arrays can contain integers, pointers and characters, and in that sence, can contain strings. For this example we will focus on integers.
Notice the below array is defined as data type "int" then a name with an array symbol after it "[]" containing the word size which is equal to an integer. This creates an array with 20 "sections" or "segments" for information to be stored. As i said above, arrays can be indexed, meaning they are in an order, and you can move about that array to store/retrieve data. you do this by use of the array symbol "[]".
An array starts at the numeric index of 0, meaning it contains the sections 0-19. If you want to access the 4rth item of data, or fourth integer stored in the array, you would use list[3] because location 3 is the fourth space when you start at 0.
int size = 20;
int list[size];
size[3] = 46;
printf("%d", size[3]);
This example will save 46 in the array position 4 and then print out the contents of array position 4, which will be 46.
===Pointer Arithmetic===
Pointer arithmetic is like moving about an array. An array can be defined in another way than by use of the array symbol []. It can be defined in another way, like this:
int *list;
list = malloc(sizeof(char)*50);
*This array is an array of pointers to memory locations.
*Pointer arithmetic refers to incrementing/decrementing pointer arrays.
int *array;
*(list+1) = 34;
*(list+5) = 4;
for(i=5;i<0;i--)
{
*(list+i) = 3+i
}
printf("%d", *(list+1));
This will save 34 into the array, allong with many other pointer arithmetic operations, and then print out the contents of that array position. Moving about an array in this manner is called "Pointer Arithmetic".
====Variables====
Numeric and character.
Variables are memory locations that are given names and can be assigned values. Variables are used to store different types of data in memory for future use.
Numeric types have several subtypes like integers or real values.
characters are letters and ASCII symbols.
Here is a list of data types and their range. (this list assumes signed integers)
-short Numeric - Integer signed: -32768 to 32767 unsigned: 0 to 4294967295
-int Numeric - Integer signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
-long Numeric - Integer signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
-float Numeric - Real signed: 1.2 X 10-38 to 3.4 X 1038 no unsigned
-double Numeric - Real signed: 2.2 X 10-308 to 1.8 X 10308 no unsigned
-char Character signed: -128 to 127 unsigned: 0 to 255
These values are all relative to the operating system, as is the same for the size. A char is typically one byte but may not always be. Programmers should always use the sizeof() function to determine the size of the variable type they wish to use.
example:
int main()
{
int a = sizeof(int);
int b = sizeof(short);
int c = sizeof(char):
printf("%d\n", a);
printf("%d\n", b);
printf("%d\n", c);
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$
====memory deallocation====
When you dynamically allocate memory in a program you have to deallocate it once you are done.
by use of C
free(num);
free(ch)
free(db);
by use of C++
delete number;
delete ch;
delete db;
If you allocate memory and do not deallocate it, you can cause memory leaks.
====Function Pointers====
CProgramming.com states: //A function pointer is a variable that stores the address of a function that can later be called through that function pointer. This is useful because functions encapsulate behavior. For instance, every time you need a particular behavior such as drawing a line, instead of writing out a bunch of code, all you need to do is call the function.//
====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
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$
=====SYSPROG Topics=====
====Reading a file====
Gets or extracts data from a file opened by an executing program. The information is stored in the buffer and used by the program, then the next read continues from where the last stopped. This continues to the Eod Of File flag or untill the file is closed.
====Openning a file====
In order for the system or a program to access or affect nother program during execution first the file must be opened by the program being executed.
====Closing a file====
After an executing program has finished with a file, and before run completion, any file which was opened by the program needs to be closed. This is done with the file close command.
====File Accessing====
File access can be dictated and restricted on an individual, group, and global scope. The abilities to read, write, and execute a file can each be set at each of these levels.
====Writing a file====
File Write puts data into a file. It can create a file if it doesn't already exist, and can append to or replace an existing file.
====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
int main()
{
return(0);
}
====Unix domain sockets====
Also called an IPC socket, a Unix domain socket is an endpoint for data communications that allows processes operating in the same system to exchange data. The APL for these sockets is similar to an internet socket, meaning the processes don't have to have the same ancestry.
These sockets are usually found on POSIX operating systems.
====Coroutines====
Coroutines are a pretty cool thing. As far as i've read they generalize subroutines like generators do, but are more powerful. They allow lots of entry points for suspending and resuming at different points.
The C programming guide says that Coroutines are best used when implementing components such as iterators, infinite lists, cooperative tasks and pipes.
====Keyword 10====
====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
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$
=====DATA Objectives=====
====Objective 1====
Choose the appropriate data structure for solving a given problem.
===Method===
I will do this by comming up with a simple, but applicable problem in code, and applying a data structure to resolve this prolem.
===Measurement===
This objective took me about 30 minutes to complete, I took not one, but two cases where a data structure needed to be implemented, and in both cases i was able to effectively, efficiently and quickly come up with a data structure/structures to solve each problem.
The actual soving of each problem took seconds to think up, and seconds to minutes to code.
===Analysis===
I believe that based on my ability to quickly and effectively solve these data structure problems, I completed this objective perfectly.
I would also say that this objective could be altered just a little bit to give room for a small example of what we did for the objective, maybe asking for code if applicable, or some other type of example. If not, then this objective was very effective in helping me understand the reasoning behind this course.
====Objective 2====
Discuss the representation and use of primitive data types and built-in data structures
===Method===
I will research primitive data types and built-in-structures to determine their formal definition and a few examples, i will then bring that data before another individual to discuss the use of primitive data types and built-in-structures to help myself and the other individual better learn the uses and need for primitive data types and built-in-structures.
===Measurement===
This objective took me roughly 4-5 hours to complete, I reserched many of these data types and structures, and presented the information before an individual who proceeded to discuss and explain a few of these in depth. I now plan to record the use of these structures as learned in class and review them in a drive to better understand the representation and use of primitive data types and built-in-structures.
===documentation of data===
Primitive data types:
-Boolean
-Char
-Float
-Double
-Int
-String
Built-in-structures:
-Stacks
-Queues
-Linked Lists
-AVL trees
-Binary Search Trees
-Binary Heap
-Red Black Tree
and many others.
===Analysis===
I believe that yet again i achieved a very good understanding of the course objective and put a lot of effort into this objective. I believe it was done effectively and well and since there is much room for improvement with these topics, it is a good thing the class is only 25% done!
====Objective 3====
Describe common applications for each data structure described in class
===Method===
As each data structure appears, i will ask questions and record programs and applications of each data structure that is given in class in an attempt to have each of the structure described to me in an understandable way.
===Measurement===
So far so good, I have had linked lists explained to me in many ways by recording programs and using them to ask multiple questions to ensure that i understand the data structure that was being taught.
===Analysis===
The method used to complete this objective seems to be an effective one. It falls in line with my teachers objectives for the course and for our learning and has so far provided much valid information reguarding the data structures being taught. I believe it will continue to be an effective method of learning that will help not only me, but others to convert to this style aswell.
=====SYSPROG Objectives=====
====Objective 1====
better understand file I/O for efficient data processing
===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===
Can you enter an integer into the command line to be saved as argv[x] when argv[] is defined as data type char? What will happen when you try to print?
===Resources===
-http://www.crasseux.com/books/ctutorial/argc-and-argv.html
-http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html
-http://einstein.drexel.edu/courses/Comp_Phys/General/C_basics/ c programming guide
-http://cm.bell-labs.com/cm/cs/cbook/ c pocket reference
-http://shop.oreilly.com/product/9780596004361.do c++ pocket reference.
-Putty for programming and compiling resources.
===Hypothesis===
I do not think the desired integer will be printed out unless the argv[x] is cast to an integer because argv has been defined as data type char.
===Experiment===
I will test this hypothesis by writing a small program to receive command line arguments. I will then print out a character to show that the program works properly, and then i will receive and print an integer saved under the same data type.
===Data===
===Character Test===
#include
int main(int argc,char **argv)
{
printf("The character argument entered is:%s\n", argv[1]);
return 0;
}
lab46:~/src/DataS/Project1$ ./experiment1 y
The character argument entered is:y
lab46:~/src/DataS/Project1$ ./experiment1 r
The character argument entered is:r
lab46:~/src/DataS/Project1$ ./experiment1 U
The character argument entered is:U
As you can see above, the program receives a character and then prints that character out, with no problems.
===Integer Test===
#include
int main(int argc,char **argv)
{
printf("The character argument entered is:%s\n", argv[1]);
return 0;
}
lab46:~/src/DataS/Project1$ ./experiment1 35
The character argument entered is:35
lab46:~/src/DataS/Project1$ ./experiment1 3
The character argument entered is:3
lab46:~/src/DataS/Project1$ ./experiment1 5
The character argument entered is:5
As you can see above, the program receives an integer and then prints that integer out, with no problems.
===Changes===
#include
int main(int argc,char **argv)
{
int a=5; //new line
int b; // new line
printf("The character argument entered is: %s\n", argv[1]);
b = (a + *argv[1]); // new line
printf("The results of our arithmetic: %d\n", b); // new line
return 0;
}
lab46:~/src/DataS/Project1$ nano experiment1.c
lab46:~/src/DataS/Project1$ gcc -o experiment1 experiment1.c
experiment1.c: In function 'main':
experiment1.c:8: error: invalid operands to binary * (have 'int' and 'char *')
lab46:~/src/DataS/Project1$ nano experiment1.c
lab46:~/src/DataS/Project1$ gcc -o experiment1 experiment1.c
experiment1.c: In function 'main':
experiment1.c:8: warning: assignment makes integer from pointer without a cast
lab46:~/src/DataS/Project1$ nano experiment1.c
lab46:~/src/DataS/Project1$ gcc -o experiment1 experiment1.c
lab46:~/src/DataS/Project1$ ./experiment1 5
The character argument entered is: 5
The results of our arithmetic: 58
Based on the added arithmetic operation: b = 5 + 5, (The first 5 is the value of a, the second 5 is the command line argument), we see that 5 + 5 = 58???.
===Analysis===
Based on the data collected:
* was your hypothesis correct?
-No
* was your hypothesis not applicable?
-No, it just didnt cover all the possibilities
* is there more going on than you originally thought? (shortcomings in hypothesis)
-Appearently, it appears i did not account for the computer just shoving whatever command line arguments it got into the array, and spitting them straight out as they were received.
===Conclusions===
Based on the experiment above, integer values can be saved into a character array, and printed directly from that array, but not manipulated without a cast. The reason for this is:
lab46:~/src/DataS/Project1$ gcc -o experiment1 experiment1.c
experiment1.c: In function 'main':
experiment1.c:8: error: invalid operands to binary * (have 'int' and 'char *')
This compiler error shows that an invalid operands to binary * was going on on line 8. Which when counted, is the line the code: b = (a + argv[1]) (at that point of compiling) was placed. This means that the integer was saved in the array with a binary representation that was not accessable by regular arithmetic means. But, the printing statement could print the integer because the binary given to the array was the same as what was printed out of the array, so the conversions in and out of the array were the same, and the integer could be expressed.
As i now understand, an integer can be saved into a character array via command line arguments, and printed with no errors, but not manipulated, which is wher ei was stuck. I had believe that the integer could not be manipulated or printed.
====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.