Table of Contents

Part 2

Entries

Entry 1: October 10, 2012 DATA

What action or concept of significance, as related to the course, did you experience on this date?

Learned about stacks and the importance of using such concept. A stack is an area of memory that holds all local variables and parameters used by any function, and remembers the order in which functions are called so that function returns occur correctly.

Why was this significant?

The significance of this is that I now know about how to use stacks, somewhat, but I still have some troubles with implementation.

What concepts are you dealing with that may not make perfect sense?

The implementation, via code, of writing a working stack program.

What challenges are you facing with respect to the course?

How to use stacks whenever needed in a situation.

Entry 2: October 11, 2012 DISCRETE

* What action or concept of significance, as related to the course, did you experience on this date?

Learned about functions on this date. A function is art of source code within a larger computer program that performs a specific task and is relatively independent of the remaining code.

* Why was this significant?

This is significant because I now know how to implement the use of functions, making my code much cleaner looking.

* What concepts are you dealing with that may not make perfect sense?

The limitations that are held when using a function call.

* What challenges are you facing with respect to the course?

Passing by reference within a function.

Entry 3: October 18, 2012 DATA

What action or concept of significance, as related to the course, did you experience on this date?

On this day we learned about recursion. Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem.

Why was this significant?

The significance of this is that it is another way of solving a problem and thinking about a program.

What concepts are you dealing with that may not make perfect sense?

The formatting a using a successful recursion sorting program.

What challenges are you facing with respect to the course?

Using recursion in certain situations over other ways of solving a problem.
#include<stdio.h>
 
int itfact(int, int);           // int factorial
int rfact(int, int);            // recursion factorial
 
int main()
{
        int (*fact)(int, int);
 
        int product = 1;
        int n = 4;
        fact = &rfact;
 
//      product = itfact(product, n);                   //INTEGER
//      fprintf(stdout, "%d! = %d\n", n, product);
 
        product = fact(product, n);                     //RECURSION
        fprintf(stdout, "%d! = %d\n", n, product);
 
        return (0);
}
 
int itfact(int p, int n)        // Function Call
{
        int i;
 
        for (i = n; i > 1; i--)
                p = p * i;
        return (p);
}
 
int rfact(int p, int n) // Function Call
{
 
        if (n > 1)
        {
                p = p * n;
                p = rfact(p, (n - 1));
        }
        return (p);
}

Entry 4: October 31, 2012 DATA

What action or concept of significance, as related to the course, did you experience on this date?

Learned about binary trees on this day. a tree data structure in which each node has at most two child nodes, usually distinguished as “left” and “right”.

Why was this significant?

Binary trees can be used to classify and organize information. Easy way to sort information.

What concepts are you dealing with that may not make perfect sense?

How to implement a program using the idea of a binary tree.

What challenges are you facing with respect to the course?

Writing a program using the idea of recursion.

Keywords

data Keyword 2

Queue Dequeuing Operation

Definition

Removes and returns the object at the beginning of the Queue (Represents a first-in, first-out collection of objects). Often referred to as a head-tail linked list.

References

stack data structure Phase 2

Definition

A stack is a very important part in computer science, especially in the programming field. This could be helpful in many functions even like a simple yet probably not widely used function, reversing a string. Its simple but if we didn't use a stack, it would seem mildly difficult. A stack is like a deck of playing cards, you place one card down and continue stacking cards on top. Then when you are ready, you take the top card off and continue on down. Thats how a stack works, push stuff in and pop stuff off, LIFO (Last in, First out).

References

Demonstration

* NOT FINISHED, PARTIALLY WORKING CODE *

#include <stdio.h>
#include <stdlib.h>
 
int size(int a[]);
int push(int a[]);
int pop(int a[]);
 
int a[999];
 
int main()
{
 
	int input, num;
 
	printf("\nStack Operations\n");
	printf("----------------------\n");
	printf("0. Set Size\n");
	printf("1. Push\n");
	printf("2. Pop\n");
	printf("9. Quit\n");
	printf("Your Selection: ");
	scanf("%d", &input);
 
	while (input != 9)
	{
 
		if (input == 0)
		{
			size(a);
		}
 
		else if (input == 1)
		{
			push(a);
		}
 
		else if (input == 2)
		{
			pop(a);
		}
 
		else if (input == 9)
		{
			return (1);
		}
		printf("\nStack Operations\n");
		printf("----------------------\n");
		printf("0. Set Size\n");
		printf("1. Push\n");
		printf("2. Pop\n");
		printf("9. Quit\n");
		printf("Your Selection: ");
		scanf("%d", &input);
 
	}
	return (0);
}
 
int size(int a[])
{
	int i = 0;
	int size;
 
	printf("\nEnter Stack Size (0 for unlimited): ");	// Sizing array
	scanf("%d", &size);
	if (size > 0)
	{
		printf("Stack Size Set to: %d\n", size);
		return (0);
	}
	else
	{
		printf("Please Enter Appropriate Stack Size\n");
		return;
	}
 
}
 
int push(int a[])
{
	int i = 0, num;
	int size;
 
	if (i >= size)
	{
		printf("*STACK OVERFLOW*\n");
		return;
	}
 
	else
	{
		if (i <= size)
		{
			printf("Enter Value To Push Onto Stack: ");
			scanf("%d", &num);
			a[i++] = num;
			printf("A %hhd Has Been Pushed Onto The Stack\n", num);
		}
	}
}
 
int pop(int a[])
{
	int i = 0, num;
	int size;
 
	if (i > 0)
	{
		printf("A %hhd Has Been Popped Off Of The Stack\n", a[i]);
		i--;
	}
	else
	{
		printf("*STACK UNDERFLOW*\n");
	}
 
}

discrete Keyword 2

Intersection

Definition

Two sets A and B is the set that contains all elements of A that also belong to B (or equivalently, all elements of B that also belong to A), but no other elements.

Example:

  The intersection of the sets {1, 2, 3} and {2, 3, 4} is {2, 3}.

References

discrete Keyword 2 Phase 2

cartesian product

Definition

Cartesian Product is making one set that takes one from a set and pairs it with one value from another set. This is done for each of the values in each set. Example:

  • {1, 2} * {up, down} = {(1, up), (1, down), (2, up), (2, down)}
  • {1, 2, left} * {left, right, up, down} = {(1, left), (1, right), (1, up), (1, down), (2, left), (2, right), (2, up), (2, down), (left, left), (left, right), (left, up), (left, down)}

References

Demonstration

lab46:~$ ./cartesian

Enter Array Size For Array A: 3
Enter Array A Elements:
1
2
4

Enter Array Size For Array B: 3
Enter Array B Elements:
5
7
9

Cartesian Product Of Array A & B:
A = {1,2,4}  &  B = {5,7,9}
A x B = {1,2} x {2,7}  x {4,9} = {(1,5), (1,7), (1,9), (2,5), (2,7), (2,9), (4,5), (4,7), (4,9)}
B x A = {4,9} x {2,7} x {1,2} = {(4,9), (4,7), (4,5), (2,9), (2,7), (2,5), (1,9), (1,7), (1,5)}

Experiment 2

Question

Is it possible to set person options for your own terminal?

Resources

  1. Pgs 151-153, Chapter 7 - Using the Keyboard with Unix. Harley Hahn's Guide to Unix and Linux.

Hypothesis

What I hope will happen is that if there is such a way to edit person option within my terminal then I will be able to create personal changes to commands.

Experiment

I will be testing my hypothesis by running the stty command in order to change some options within my terminal. The structure of my experiment is a command and hope it works.

Data

stty [-a] [-g] [modes]

-a: Write to standard output all of the option set tings for the terminal.

-g: Report current settings in a form that can be used as an argument to another stty command. Emits termios-type output if the underlying driver sup ports it; otherwise, it emits termio-type output.

lab46:~$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixo
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

* Now for the change * LOOK AT ERASE FUNCTION

lab46:~$ stty erase \^h
lab46:~$ stty -a
speed 38400 baud; rows 45; columns 76; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon
-ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

Analysis

Was your hypothesis correct?

My hypothesis was correct.

Was your hypothesis not applicable?

My hypothesis was applicable.

Is there more going on than you originally thought? (shortcomings in hypothesis)

No shortcomings in hypothesis, or more going on than I originally thought. Ran, and completed as I thought it would happen.

What shortcomings might there be in your experiment?

Only changed one instance in my options. Didn't want to mess up a whole lot and regret it.

What shortcomings might there be in your data?

Not enough changes happen for sufficient data.

Conclusions

This command can be very useful if you do not like the standard settings being used. You can change them to whatever feels more comfortable to you.