User Tools

Site Tools


opus:spring2012:cforman:part1

Part 1

Entries

Entry 1: January Day, 2012

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Entry 2: January 31, 2012

Today I was working on a program that could pop pictures up on all the screens in the room. The program didn't work but instead it pushed the processing use over 4,600% it was epic. I will not be using it again. We also learned about pointers and pointers that point to pointers.

Entry 3: February 14, 2012

Today we learned about arrays. when we run a program the data is stored in an array. the first part is the programs name. the parts that follow are the arguments that affect the command. Arrays can be accessed and specific information can be retrieved from them. These are really helpful because they allow the user to store information easily and retrieve specific data easily.

Entry 4: February 23, 2012

We talked a lot about project one which is a cipher decipher program. We talked about how everything to the computer is technical a number and with that being true numbers can be manipulated. This is a great concept because it allows for so really cool programming tricks. Considering that all letters are numbers then you can better use letters in you program. For example of a letter being a number …. z is the same as 122 and a is the same as 97.

Keywords

cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)

Definition

Standard input and output is simple but complicated. The most obvious of what it can do is simple. Receive data and output data. Even that can be put onto a new level depending on your knowledge of Standard I/O. For now just the basics. The computer can receive input from some source(keyboard, other programs, and files). standard output is also just where a program sends its data. “fscanf” is used to grab infromation from the user input using the keyboard. “fprintf” is used to output data onto (well usually) the screen. STDERR is also like STDOUT but instead of outputting user generated data it tends to output when the program fails in some way. Segmentation faults and compilation problems tend to be standard errors.

Demonstration
#include <stdio.h>
#include <stdlib.h>
int main()
{
        FILE *in,*out;
        int value=0;
        in=fopen("file.txt","r");
        out=fopen("out.txt","w");
        if(in==NULL)
        {
                printf("ERROR!\n");
                exit(1);
        }
        fscanf(in,"%d",&value);
        while(value!=-1)
        {
                value *= 2;
                fprintf(out,"%d\n",value);
                fscanf(in,"%d",&value);
        }
        fclose(in);
        fclose(out);
        return(0);
}

What this code does is creates a seemingly random number then has the user input their guess. the guess is compared to the actually number and then the program outputs the results. As seen in the program the terms “fscanf” and “fprintf” are used. Not only that but the terms in and out are used along with the proper “fscanf” with in and the other with “fprintf”

Header Files (Local and System), C Standard Library (Libc), Libraries

Definition

Header files are used in a program to give the user the ability to use certain commands in his program. There are two types. The first is “local header files” these files are programs you have created or data compilations you wish to use in your current program. The other type of header file is the “system header files.” These are instituted into the program using the command “#include <blah blah>” the blah blah is the header file you wish to use.

The C Standard Library is a compilation of both header files and all the possible commands one can use in their programs. It is the programming language of C.

Libraries are simply other compilations of commands which make up other languages for programming.

arithmetic (equations, operators)

Definition

Essentially these are the different mathematical symbols and how they function within the program. This is easier to show then explain. This table is grabbed from http://www.tutorialspoint.com/ansi_c/c_operator_types.htm

Demonstration
Operator	Description	Example
+	Adds two operands	 A + B will give 30
-	Subtracts second operand from the first	 A - B will give -10
*	Multiply both operands	 A * B will give 200
/	Divide numerator by denumerator	 B / A will give 2
%	Modulus Operator and remainder of after an integer division	 B % A will give 0
++	Increment operator, increases integer value by one	 A++ will give 11
--	Decrement operator, decreases integer value by one	 A-- will give 9

Operator	Description	Example
==	 Checks if the value of two operands is equal or not, if yes then condition becomes true.	 (A == B) is not true.
!=	 Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.	 (A != B) is true.
>	 Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.	 (A > B) is not true.
<	 Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.	 (A < B) is true.
>=	 Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.	 (A >= B) is not true.
<=	 Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.	 (A <= B) is true.
&&	 Called Logical AND operator. If both the operands are non zero then then condition becomes true.	 (A && B) is true.
||	Called Logical OR Operator. If any of the two operands is non zero then then condition becomes true.	 (A || B) is true.
!	Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.	 !(A && B) is false.

logic and operators (and, or, not, xor)

Definition

logic operators can be used to define exactly what you want you program to respond to and not to respond to. They can be used to make sure if statements only act when certain requirements are met. exp. if( (i =2)&&(x=2) ); the program will only run said if statement if both x and i are equal to 2.

 and is &&
 or  is ||
 not is !
 xor is ^ or ^^ i am not sure

Variables (types, ranges, sizes)

Definition

Variables in this case are just different data types. Each data type has a purpose. Char is made for characters. Int is used for small numbers. and long long int is used for very long numbers. The following are results from a program that takes the range and size of each datatype.

Demonstration
an unsigned char is 1 bytes
The range of an unsigned char is 0 to 255
An unsigned char can store 256 unique values

A signed char is 1 bytes
The range of a signed char is -128 to 127
A signed char can store 256 unique values

an unsigned short int is 2 bytes
The range of an unsigned short int is 0 to 65535
An unsigned short int can store 65536 unique values

A signed short int is 2 bytes
The range of a signed short int is -32768 to 32767
A signed short int can store 65536 unique values

an unsigned int is 4 bytes
The range of an unsigned int is 0 to 4294967295
An unsigned int can store 4294967295 unique values

A signed int is 4 bytes
The range of a signed int is -2147483648 to 2147483647
A signed int can store 4294967296 unique values

an unsigned long int is 8 bytes
The range of an unsigned long int is 0 to 18446744073709551615
An unsigned long int can store 18446744073709551615 unique values

A signed long int is 8 bytes
The range of a signed long int is -9223372036854775807 to 9223372036854775806
A signed long int can store 18446744073709551615 unique values

an unsigned long long int is 8 bytes
The range of an unsigned long long int is 0 to 18446744073709551615
An unsigned long long int can store 18446744073709551615 unique values

A signed long long int is 8 bytes
The range of a signed long long int is -9223372036854775807 to 9223372036854775806
A signed long long int can store 18446744073709551615 unique values

Scope (Block, Local, Global, File)

Definition

A scope is something that is only functional within its area. Block scope are pieces of code that fall between these {}. They are main blocks of code and there can be many of these in a single function. Local Scope is when you have a code block but inside you have another and there is a variable in it that was created and is only usable within the separate code block inside the original.if { blah blah blah){ int i} if this is in a block of code then the int i is part of a local scope. File block is anything declared outside of normal blocks of code. These are accessible anywhere. The final Scope is Global. These are things declared outside of code and can be used in your code. Usualy called upon before you begin you code ( before you input int main() )

type casting

Definition

Type Casting is when you convert one type of variable to another within your program. Like when you divide two whole integers and want a float result you change it into a float.

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:

float avg(int m1, int m2, int m3, int m4)
{
        float average=0;
        int total=0;
        total=m1+m2+m3+m4;
        average=(float)total/4;  // this causes the division to recognize the float
        return(average);
}

Here you can see i have an integer “total” and a float “average” in order to devide by 4 the total i first had to type cast he integer so the computer will recognize it not as a integer now but a float.

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

Definition

These are different types of loops. A loop is used when you want to repeat a process more then once based on a variable or a predetermined set of boundaries

Demonstration
 while(*pick != -1)
        {
                *pick=rand()%99+1;
                printf("guess the computers pick: ");
                scanf("%d", input);
                if(*input == *pick)
                {
                        printf("you are correct!\n");
                }
                else if(*input > *pick)
                {
                        printf("HAHA FAIL you are too high\n");
                }
                else
                {
                        printf("GOLDEN GUESS jk you were wrong that is too low\n");
                }
                printf("the computers pick was %d\n",*pick);
 
                }
                printf("the computers pick was %d\n",*pick);
                printf("to go again enter in 0, to quit -1: ");
                scanf("%d", pick);
        }
 
 
for(pos=0;pos<len;pos++)
        {
                fprintf(stdout,"%c",*(word+pos)-32);
        }

Do whiles are essentially just like the while loop but with a different way of writing it.

cprog Objective

cprog Objective

CAN I READ IT?

Definition

This entails me looking at one of our harder functions and explaining what each part is doing and how all the parts work together.

Method

I will look at the program called

Measurement

The information in the

#include <stdlib.h>
int sum(int, int, int, int); //function prototype
float avg(int, int, int, int);
int high(int, int, int, int);   //[these four blocks are function protoypes.... this means that they dont actually exist yet
int low(int, int, int, int);    // but are in place so that we can define them later. They will all receive] 
int main()
{
        int a,b,c,d;
        a=b=c=d=0;
        printf("enter first value: ");
        fscanf(stdin, "%d", &a);
        printf("enter second value: ");     // this zone is the initial area where we ask the user for his numbers
        fscanf(stdin, "%d", &b);            // and scan there output into a variable.
        printf("enter third value: ");
        fscanf(stdin, "%d", &c);
        printf("enter fourth and final value: ");
        fscanf(stdin, "%d", &d);

        fprintf(stdout, "the sum of %d, %d, %d, and %d is: %d\n", a,b,c,d, sum(a,b,c,d));    //these lines output different
        fprintf(stdout, "the avg of %d, %d, %d, and %d is : %0.5f\n",a,b,c,d,avg(a,b,c,d)); // results based on the numbers
                                        // one is sum, average, and lowest and greatest numbers. each calls a different function
  fprintf(stdout, "the greatest value is %d, and the lowest value entered is %d\n",high(a,b,c,d),low(a,b,c,d));
        return(0);
}

// sum(a,b,c,d) is sending copies to v that function.not changing the value or cant change the value of a b c or d
int sum(int n1, int n2, int n3, int n4)
{
        int total=0;         // this zone basically adds the numbers together and returns total so that when the 
        total=n1+n2+n3+n4;   // function main uses it it will see only the return of this function. 
        return(total);
}
float avg(int m1, int m2, int m3, int m4)
{
        float average=0;    // here we take the same numbers , re add them , then convert them to a float.
        int total=0;        // this is so that we can now divide by 4 and get decimals. Once again returns a single result.
        total=m1+m2+m3+m4;
        average=(float)total/4;  // this causes the division to recognize the float
        return(average);
}

int high(int b1, int b2, int b3, int b4)
{
        int greatest=0;
        if( (b1>b2) && (b1>b3) && (b1>b4))
        {
                greatest=b1;
        }

        if( (b2>b1) && (b2>b3) && (b2>b4))      // this uses many ifs to check and find which variable is the largest by
        {
                greatest=b2;                   // comparing to the others. 
        }
        if( (b3>b1) && (b3>b2) && (b3>b4))
        {
                greatest=b3;
        }

        if( (b4>b1) && (b4>b3) && (b4>b2))
        {
                greatest=b4;
        }
}

int low(int b1, int b2, int b3, int b4)
{
        int lowest=0;

        if( (b1<b2) && (b1<b3) && (b1<b4))
        {
                lowest=b1;
        }
        if( (b2<b1) && (b2<b3) && (b2<b4))  // same as greatest but tries to find the least greatest variable. 
        {
                lowest=b2;
        }
        if( (b3<b2) && (b3<b1) && (b3<b4))
        {
                lowest=b3;
        }
        if( (b4<b2) && (b4<b3) && (b4<b1))
        {
                lowest=b4;
        }
        return(lowest);
}
Analysis

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

  • How did you do?
    • well enough i was able to recognize the different parts and how they flowed together even though its been a while
  • Is there room for improvement?
    • probably i really had to think about it sometimes it is not intuitive yet.
  • Could the measurement process be enhanced to be more effective?
    • possibly have found a harder program
  • Do you think this enhancement would be efficient to employ?
    • yes a more difficult test would result in more accurate results.
  • Could the course objective be altered to be more applicable? How would you alter it?
    • not really this is quite applicable when dealing with programming.

Experiments

Experiment 1

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 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.

opus/spring2012/cforman/part1.txt · Last modified: 2012/03/03 08:39 by cforman