User Tools

Site Tools


opus:fall2012:jcavalu3:part1

Part 1

Entries

Entry 1: August 30, 2012

Mercurial/hg/Repository

  • On this date, the class was first taught how to use Mercurial through linux, which will be used as revision control.
  • This will allow the class to create and upload files into a database that can be updated at any time. It also allows the class to revisit a previously saved version of a file, and retrieve that file.
  • I used revision control in a class before (Structured and Object Oriented Problem Solving) with Joe, but he used www.bitbucket.org, which wasn't the easiest thing to mess with.
  • I find that using Mercurial through linux is much easier than in Windows and that unforgiving website, but, overall, revision control is a huge part of programming and is very, very important!

Entry 2: September 4, 2012

Truth Table

  • On this day, we learned about the Truth Table.
  • This showed me what each of the possibilities are and what they are represented by.
  • I learned about this a little in SOOPS and Computer Essentials, but the new names for each of the different combinations is a first for me.
  • I still need to understand what each of those new terms mean and what they represent, as well as memorize most to all of the Truth Table.

Entry 3: September 12, 2012

  • We learned how to use VI/VIM in UNIX/Linux.
  • VI (Visual) and VIM (Visual Improved) are both text editors available on UNIX.
  • They are very useful because they have many different settings for modifying a file without actually typing in words. The possibilities are ENDLESS!
  • With all of the different commands to edit the files through VI/VIM, I am having a difficult time learning and remembering all of the commands and their purposes. I need to practice it more, sometimes I have to resort to using nano, which works for the time being, but VI is so much better!

Entry 4: September 19, 2012

  • In data, I first grasped the concept of Linked Nodes and the program created the previous class.
  • The Linked Nodes concept is very similar to the concept of arrays. It takes multiple values and stores them in the order they were input. Linked Nodes just take more to program and make one think more about it. It requires structs, renaming of variables, all sorts of things I wasn't very familiar with before.
  • By working on this, I have become more familiar with structs, renaming of variables, and the way that Linked Nodes works in general.
  • The nodes themselves can have both a “name” and value or just a value. They could just have a “name”, but what is the point of that when inserting a value and that value actually having meaning? Know what I mean? Anyway, the big understanding I had with the Linked Node program was appending and removing nodes from the list.

Keywords

data Keyword 1

passing by address (function parameter passing)

Definition

Passing by address is just one of the ways that you pass a variable into a function. This is done not by passing the variable itself, but by passing the variable address. The only uses for this type of variable passing that I have encountered are arrays.

References

Phase 2

pointer assignment

Definition

The pointer assignment statement causes a pointer to become associated with a target or causes the pointer's association status to become disassociated or undefined. this means that a pointer or (*) can force a pointer or word or number to be paired with another or not depending on how it is used.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

  • google.com

Demonstration

Demonstration of the indicated keyword.

The following is the demonstration of pointer assignment by using the code and the resulting output:

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 
  4 int main()
  5 {
  6     char *array1, *array2;
  7     int i = 0;
  8 
  9     array1 = (char *)malloc( sizeof(char) * 4 );
 10     array2 = (char *)malloc( sizeof(char) * 4 );
 11 
 12     printf("Please input four values for the first array\n");
 13 
 14     for( i; i < 4; i++ )
 15     {
 16         scanf("%hhu", &*(array1 + i));
 17         *(array2 + i) = 0;
 18     }
 19 
 20     printf("Here are the values in both arrays:\nArray1: ");
 21 
 22     for( i = 0; i < 4; i++)
 23     {
 24         printf("%hhu ", *(array1 + i));
 25     }
 26     printf("\nArray2: ");
 27 
 28     for( i = 0; i < 4; i++)
 29     {
 30         printf("%hhu ", *(array2 + i));
 31     }
 32 
 33     array2 = array1; // Example of Pointer Assignment
 34 
 35     printf("\nHere are the results after setting 'array2' = to 'array1':\nArray1: ");
 36 
 37     for( i = 0; i < 4; i++)
 38     {
 39         printf("%hhu ", *(array1 + i));
 40     }
 41     printf("\nArray2: ");
 42 
 43     for( i = 0; i < 4; i++)
 44     {
 45         printf("%hhu ", *(array2 + i));
 46     }
 47 
 48     printf("\n\nThank you for your time.\n\n");
 49     return(0);
 50 }

The code makes two arrays, sets one equal to whatever input the user decides to go with, and the other being equal to 0. The program will then print the arrays, then set the second array equal to the first, which is the example of pointer assignment. The program is assigning the second array to the data in the first array. The result is then this:

lab46:~/src/opus/opus1$ ./pa
Please input four values for the first array
1 2 3 4
Here are the values in both arrays:
Array1: 1 2 3 4 
Array2: 0 0 0 0 
Here are the results after setting 'array2' = to 'array1':
Array1: 1 2 3 4 
Array2: 1 2 3 4 

Thank you for your time.

lab46:~/src/opus/opus1$ 

discrete Keyword 1

Right Complementation

Definition

When given a Truth Table, you see two columns of two different values that are related to each other and show opposite relationships, most of the time they are represented by F for false and T for true. Right Complementation is the opposite of the second column, or the right one. When representing each of the results for a 4 by 2 table, there are 16 possible results, one of them being the right complementation, which is actually represented by negation q.

References

discrete Keyword 1 Phase 2

equivalence/if and only if

Definition

The opposite of an XOR, if something is T and T, then it would be T when applied.

References

Demonstration

Demonstration of the indicated keyword.

The following is the code used to demonstrate if and only if/equivalence and the resulting output when the program is run:

  1 #include <stdio.h>
  2 
  3 char logicor( char, char );
  4 
  5 char logiciff( char a, char b )
  6 {
  7     char x;
  8     if(a == b)
  9         x = 1;
 10     else
 11         x = 0;
 12     return(x);
 13 }
 14 
 15 int main()
 16 {
 17     char p = 1;
 18     char q = 1;
 19 
 20 // Printing the OR Truth Table
 21 
 22     printf("\nTreat 0 as false, and 1 as true.\n\tXOR Truth Table:\n\n");
 23     printf("\t P | Q | X \n");
 24     printf("\t___________\n");
 25 
 26 // Printing the first set of values (values for p, q, and the result of p|q)
 27 
 28     printf("\t %d | %d | %d \n", p, q, logiciff( p, q ));
 29     q = 0;
 30     printf("\t %d | %d | %d \n", p, q, logiciff( p, q ));
 31     p = 0;
 32     q = 1;
 33     printf("\t %d | %d | %d \n", p, q, logiciff( p, q ));
 34     q = 0;
 35     printf("\t %d | %d | %d \n\n", p, q, logiciff( p, q ));
 36 
 37 // Printing PART 3
 38 
 39 /*  printf("\tOR Truth Table comparing X and Q:\n\n");
 40     printf("\t P | Q | X | ( X|Q )\n");
 41     printf("\t____________________\n");
 42 
 43     p = 1;
 44     q = 1;
 45 
 46     printf("\t %d | %d | %d |    %d \n", p, q, logicor( p, q ), logicor( logicor( p, q ), q ));
 47     q = 0;
 48     printf("\t %d | %d | %d |    %d \n", p, q, logicor( p, q ), logicor( logicor( p, q ), q ));
 49     p = 0;
 50     q = 1;
 51     printf("\t %d | %d | %d |    %d \n", p, q, logicor( p, q ), logicor( logicor( p, q ), q ));
 52     q = 0;
 53     printf("\t %d | %d | %d |    %d \n", p, q, logicor( p, q ), logicor( logicor( p, q ), q ));*/
 54     return(0);
 55 }

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~/src/opus/opus1$ ./iff

Treat 0 as false, and 1 as true.
	XOR Truth Table:

	 P | Q | X 
	___________
	 1 | 1 | 1 
	 1 | 0 | 0 
	 0 | 1 | 0 
	 0 | 0 | 1 

lab46:~/src/opus/opus1$ 

unix Keyword 1

Home Directory

Definition

The Home Directory is basically the place that all of a user's files and folders are stored. From the home directory, one may be able to access all of their files, or just access specifically places files. The user is able to completely customize their home directory. When files and folders are in a home directory (including readable, writable, and executable files), they are only able to be accessed by the user or any other administrator on the system. That can be changed at any point, however.

References

unix Keyword 1 Phase 2

file ownership(access control)

Definition

Allowing others to view or change a files

References

Demonstration

Demonstration of the indicated keyword.

File ownership (access control), like previously stated, determines who can either read, write, or execute a file or directory.

First, by entering 'ls' into the terminal, you can see what files are in that directory, but if you add a '-l', you can see who has access to the files. The order displayed is Owner, Group, World. For Example

lab46:~/src/unix$ ls -l
total 16
-rwxrwxrwx 1 jcavalu3 lab46 115 Sep 19 16:44 logincnt.sh
 _O__G__W_   O - Owner/G - Group/W - World
drwxr-xr-x 6 jcavalu3 lab46  66 Sep 27 23:59 projects
-rwx------ 1 jcavalu3 lab46 147 Sep 28 15:36 script2.sh
-rwx------ 1 jcavalu3 lab46 574 Sep 28 16:52 script3.sh
drwxr-xr-x 3 jcavalu3 lab46  16 Sep 26 11:39 submit
-rw-r--r-- 1 jcavalu3 lab46 195 Sep  7 15:45 unixstuffs
lab46:~/src/unix$ 

To edit a file and who can access it, simply input the command 'chmod 744* script2.sh'.

chmod stands for change mode, which is the program that allows you to modify who can access the file Followed by the change in access Lastly, the file should follow behind the change in access

* Each number represents one of the three types of access (OGW). The number for each type or access is 4(read - r), 2(write - w), 1(execute - x). The size of the number input depends on what type of access the modifier would like each “group” to access. 744 means that the Owner can read, write and execute, the Group can read and execute, and the World can read and execute.

Example:

lab46:~/src/unix$ ls -l
total 16
-rwxrwxrwx 1 jcavalu3 lab46 115 Sep 19 16:44 logincnt.sh
drwxr-xr-x 6 jcavalu3 lab46  66 Sep 27 23:59 projects
-rwx------ 1 jcavalu3 lab46 147 Sep 28 15:36 script2.sh
  ^  ^  ^
-rwx------ 1 jcavalu3 lab46 574 Sep 28 16:52 script3.sh
drwxr-xr-x 3 jcavalu3 lab46  16 Sep 26 11:39 submit
-rw-r--r-- 1 jcavalu3 lab46 195 Sep  7 15:45 unixstuffs
lab46:~/src/unix$ chmod 744 script2.sh 
lab46:~/src/unix$ ls -l
total 16
-rwxrwxrwx 1 jcavalu3 lab46 115 Sep 19 16:44 logincnt.sh
drwxr-xr-x 6 jcavalu3 lab46  66 Sep 27 23:59 projects
-rwxr--r-- 1 jcavalu3 lab46 147 Sep 28 15:36 script2.sh
  ^  ^  ^
-rwx------ 1 jcavalu3 lab46 574 Sep 28 16:52 script3.sh
drwxr-xr-x 3 jcavalu3 lab46  16 Sep 26 11:39 submit
-rw-r--r-- 1 jcavalu3 lab46 195 Sep  7 15:45 unixstuffs
lab46:~/src/unix$ 

Experiment 1

Question

Arrays in Shell Script: Fact or Fiction? (Are they different from arrays in C/C++?)

Resources

  • According to http://www.tldp.org/LDP/abs/html/arrays.html, arrays are created in the same way that they are created in C/C++ programming: array[##]
  • It also tells me that it can first introduce an array by the declare -a variable statement.
  • To dereference an array, just use curly brackets: ${array[##]}
  • Left in the comments were a few pointers (see what I did there?) about arrays: 1) The members of arrays don't need to be consecutive or contiguous. 2) Not all of the members of an array need to be initialized. 3) It is alright to leave gaps in the array (spaces of memory without values).

Hypothesis

From the information I have collected, arrays are possible and very similar to arrays in C/C++.

Experiment

I will create a shell script that will basically perform the same process as the Pointer Assignment Demonstration (http://lab46.corning-cc.edu/opus/fall2012/jcavalu3/part1?#phase_2), and compare the two. This will, hopefully, confirm my hypothesis and allow me to know and understand how arrays work in shell script as well as C/C++ (Nothing wrong with more refreshers!).

Data

The following is the shell script program I created and the results:

  1 #!/bin/bash
  2 #
  3 # You know, just a shell script file for my experiment in opus1
  4 #
  5 # I will create an identical file as the one I used in the pointer
  6 # assignment and check to see if I get the same result.
  7 #
  8 # ONWARD!
  9 
 10 for((i=0;i<4;i++)); do
 11 echo -n "Enter a value (0-9): "
 12 read array1[i]
 13 echo -n "Enter a zero: "
 14 read array2[i]
 15 done
 16 echo "Array1:"
 17 for((i=0;i<4;i++)); do
 18 echo "${array1[i]}"
 19 done
 20 echo "Array2: "
 21 for((i=0;i<4;i++)); do
 22 echo "${array2[i]}"
 23 done
 24 for((i=0;i<4;i++)); do
 25 array2[i]=${array1[i]}
 26 done
 27 echo "Array1:"
 28 for((i=0;i<4;i++)); do
 29 echo "${array1[i]}"
 30 done
 31 echo "Array2: "
 32 for((i=0;i<4;i++)); do
 33 echo "${array2[i]}"
 34 done
 35 echo "Thank you for your time."
 36 exit 0
lab46:~/src/opus/opus1/experiment$ ./array.sh
Enter a value (0-9): 1
Enter a zero: 0
Enter a value (0-9): 2
Enter a zero: 0
Enter a value (0-9): 3
Enter a zero: 0
Enter a value (0-9): 4
Enter a zero: 0
Array1:
1
2
3
4
Array2: 
0
0
0
0
Array1:
1
2
3
4
Array2: 
1
2
3
4
Thank you for your time.

Now, the results from the Pointer Assignment Demonstration:

lab46:~/src/opus/opus1$ ./pa
Please input four values for the first array
1 2 3 4
Here are the values in both arrays:
Array1: 1 2 3 4 
Array2: 0 0 0 0 
Here are the results after setting 'array2' = to 'array1':
Array1: 1 2 3 4 
Array2: 1 2 3 4 

Thank you for your time.

lab46:~/src/opus/opus1$ 

Analysis

Based on the data collected:

  • My hypothesis was correct, I was able to create a program in shell script that performed the same operations that the original Pointer Assignment program did.
  • The hypothesis was, indeed, applicable.
  • The hypothesis was basically straightforward. Of course, it usually isn't the idea or concept that is different, it is the implementation that is different.
  • In the experiment, the shell script was much more difficult to create the same output as the original program created. I was unsure of how to actually have it print each value out in a row, to make it look like it was one large number, as I did in the original. Also, I couldn't just point one array to another and say “You hold the same values as this array now!” I had to dereference the first array to allow the second to take the value that the specific space of memory was holding. If I didn't do that, it would just say “array2[i] = array1[i].” That just isn't what I wanted!
  • Shortcomings… are non-existent… in this experiment… Everything went well! I now understand how to declare arrays in shell script, how to dereference them, and how to use pointer assignments in shell script. SUCCESS!

http://beastkong.com/wp-content/uploads/2012/05/success-baby.jpg

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.

opus/fall2012/jcavalu3/part1.txt · Last modified: 2012/09/30 22:00 by jcavalu3