Mercurial/hg/Repository
Truth Table
passing by address (function parameter passing)
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.
pointer assignment
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.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
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$
Right Complementation
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.
equivalence/if and only if
The opposite of an XOR, if something is T and T, then it would be T when applied.
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$
Home Directory
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.
file ownership(access control)
Allowing others to view or change a files
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$
Arrays in Shell Script: Fact or Fiction? (Are they different from arrays in C/C++?)
From the information I have collected, arrays are possible and very similar to arrays in C/C++.
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!).
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$
Based on the data collected:
http://beastkong.com/wp-content/uploads/2012/05/success-baby.jpg
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.