User Tools

Site Tools


opus:spring2012:sswimle1:part1

Part 1

Entries

Entry 1: February 07, 2012

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?

In the first days of class concepts of significance that I have taken away from said learning are:

svn add and svn commit actions.

pointers, using pointers in C programming code.

integers, chars, using integers and chars as pointers, using integers and chars in C programming code.

include action, using include actions in C programming to use libraries.

  • Why was this significant?

The svn commands are great for saving information to your directories and committing changes.

The pointers are used to have something exist in memory but no be contained in a certain place.

The integers and chars can be used to declare variables.

The include action is used to reference pre-existing libraries contained in the C programming language.

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

Something that does not make perfect sense to me at this point in the class so far is the “%u\n” “%d\n” portions of code.

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

My challenge with a C programming course is that I have no previous experience with a programming language, a lot of new information to grasp.

Entry 2: February 16, 2012

With this in class example we used pointers, malloc, a while loop, if condition, else and else if condition, srand, time, NULL,

malloc was a call for an allocation of memory.

While loop with conditions was our implementation to keep the program running for more than one instance.

srand was our pseudo random number generator.

time was our value system of numbers that srand used to return random numbers? I think.

If I remember correctly when you NULL something you are acknowledging that it exists without physically or logically assigning it a specific value, out it's were the integer pointers input and pick.

We also talked about how it was difficult for a computer to be random without eventually becoming predictable in some way, due to the facts of the way a computer operates always following instructions, and not having the distinct ability to make a decision on it's own accord.

#include<stdio.h>

#include<stdlib.h>

int main()

{

int *input, *pick; input=pick=NULL;
input=(int *)malloc(sizeof(int)*1);
pick=(int *)malloc(sizeof(int)*1);
*input=0;
*pick=0;
while(*pick !=-1)
{
	srand(time(NULL));
	*pick=rand()%99+1;
	printf("Guess the computer's pick: ");
	scanf("%d", input);
	if(*input==*pick)
	{
		printf("Congratulations you have won\n");
	}
	else if(*input > *pick)
	{
		printf("Your guess was high\n");
	}
	else
	{
		printf("Your guess was low\n");
	}
	printf("Computer had %d\n", *pick);
	printf("0 to play again, -1 to quit\n");
	scanf("%d", pick);
}
return(0);

}

Entry 3: February 16, 2012

With this class example we used new C/C++ components argc and argv

argc in C/C++ is the argument count within a programs pseudo code, we used the argument counter in this program to say that if the argument count was less than 2 the program would print a string message to the user telling them that need more arguments and how many arguments they actually provided.

argv is an abbreviation for an argument vector, we used argv as a double pointer character, that is really the best I can explain what this is doing at this point.

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
 
{
	unsigned char i;
	if(argc<2)
	{
		printf("%8s must be run with 1 or more arguments, you only provided %hhu\n",(argc-1));
		exit(1);
	}
	printf("You ran this program with %hhu arguments, they are:\n",(argc-1));
	for(i=1;i<argc;i++)
	{
		printf("argv[%hhu]: %s\n",i,*(argv+i));
	}
	return(0);
}

Entry 4: February 20, 2012

I am adding all of the coded examples that we have done in class so far as my 4th opus entry. Probably add some textual content about what each program was focusing on once I get the format of the entry all setup with the all the examples included.

Example 1

#include
<stdio.h>
int main()
 
{
	printf("an int is %u bytes\n", sizeof(int));
	return(0);
}

Example 2

#include
<stdio.h>
int main()
{
	int a;
	a=0;
	printf("a contains %u\n", a);
	printf("a's address is 0x%x\n", &a);
	return(0);
}
Addition to var2.c
#include<stdio.h>
int main()
{
	int a=0;
	int *b;
	b=&a;
	*b=12;
	printf("a contains %u\n", a);
	printf("a's address is 0x%x\n", &a);
	printf("b contains %u\n, *b);
	printf("b points to 0x%x\n, b);
	printf("b's address is 0x%x\n",&b);
	return(0);
}	

Example 3

#include<stdio.h>
int main()
{
	int v=17;  //setting the integer v equal to the number 17
	int *p1=NULL; //setting the pointer p1 to NULL, NULL is allowing p1 to exist without 				assigning an exact value
	printf(“v is %u\n”, v);  //having the computer display or “print out” the value of v
	p1=&v;
	printf(*p1 is %u\n”, *p1);
	*p1=53;
	printf(“v is %u\n”, v);
	printf(*p1 is %u\n”, *p1);
	v=7;
	printf(“v is %u\n”, v);
	printf(*p1 is %u\n”, *p1);
	return(0);
}

Example 4

#include<stdio.h>
int main()
{
	int num=0;
	printf(“Please enter an integer value:);
	scanf(%d”,&num);
	printf(“You just input %d\n”,num);
	if((num % 2) == 0)
	{
		printf(“It is even.\n”);
	}
	else
	{
		printf(“It is odd.\n”);
	}
	return(0);
}

Example 5

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int *p1,*p2,**p4;
	p1=(int *)malloc(sizeof(int)*1);
	*p1=26;
	printf("*p1 is %u\n",*p1);
	p2=p1;
	p4=&p1;
	printf("**p4 is %u\n",**p4);
	printf("*p2 is %u\n",*p2);
	*p2=61;
	printf("*p1 is %u\n",*p1);
	printf("**p4 is %u\n",**p4);
	printf("*p2 is %u\n",*p2);
	**p4=16384;
	printf("*p1 is %u\n",*p1);
	printf("**p4 is %u\n",**p4);
	printf("*p2 is %u\n",*p2);
	return(0);
}

Example 6

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int *input, *pick; input=pick=NULL;
	input=(int *)malloc(sizeof(int)*1);
	pick=(int *)malloc(sizeof(int)*1);
	*input=0;
	*pick=0;
	while(*pick !=-1)
	{
		srand(time(NULL));
		*pick=rand()%99+1;
		printf("Guess the computer's pick: ");
		scanf("%d", input);
		if(*input==*pick)
		{
			printf("Congratulations you have won\n");
		}
		else if(*input > *pick)
		{
			printf("Your guess was high\n");
		}
		else
		{
			printf("Your guess was low\n");
		}
		printf("Computer had %d\n", *pick);
		printf("0 to play again, -1 to quit\n");
		scanf("%d", pick);
	}
	return(0);
}

Example 7

#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        char *value,i;
        value=(char *)malloc(sizeof(char)*4);
        *(value+0)=0;
        *(value+1)=1;
        fprintf(stdout, "please enter a value (-128-+127):");
        fscanf(stdin,"%hhd",&i);
        *(value+2)=i;
        *(value+3)=(2*i)+3;
        for(i=3;i>=0;i--) //(i=0;i<=3;i++)
        {
                printf("%hhd\n",*(value+i));
        }
        return(0);
}

Example Sample

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv) //parameters are in the ( ), first parameter of main must be an integer
{
        unsigned char i;
 
        if(argc<2)
        {
                printf("%8s must be run with 1 or\
 more arguments, you only provided %hhu\n",*(argv+0),(argc-1));
                exit(1); // \ followed by enter allows you to continue code on new line
        }
        printf("You ran this program with %hhu arguments, they are:\n",(argc-1));
        for(i=1;i<argc;i++)
        {
                printf("argv[%hhu]: %s\n",i,*(argv+i));
        }
        return(0);
}

Example FileFun

#include<stdio.h>
#include<stdlib.h>

int main()
{
        FILE *in,*out;
        char value=0;
        in=fopen("file.txt","r");
        out=fopen("out.txt","w");
        if(in==NULL)
        {
                printf("ERROR!\n");
                exit(1);
        }
        fscanf(in,"%hhd",&value);
        while(value != -1)
        {
                value*=2;
                fprintf(out,"%hhd\n",value);
                fscanf(in,"%hhd",&value);
        }
        fclose(in);
        fclose(out);
        return(0);
}

Project 0 or as I like to call it range.c

#include <stdio.h>
#include <math.h>
int main()
{
    // Variables
    unsigned long long int quantity = 0;
    unsigned char uc = 0;
    signed char sc = 0;
    unsigned short int usi = 0;
    signed short int ssi = 0;
    unsigned int ui = 0;
    signed int si = 0;
    unsigned long int uli = 0;
    signed long int sli = 0;
    unsigned long long int ulli = 0;
    signed long long int slli = 0;
    // Display information for unsigned char data type
    printf("An unsigned char is %d bytes\n", sizeof(uc));
    printf("The range of an unsigned char is %hhu to %hhu\n", uc, (uc-1));
    quantity = (unsigned char)(uc-1) + 1;    // What does this line do?
    printf("An unsigned char can store %llu unique values\n\n", quantity);
    // Display information for signed char data type
    printf("A signed char is %d bytes\n", sizeof(sc));
    quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); // What is happening?
    printf("The range of a signed char is %hhd to %hhd\n", (sc-(quantity/2)), (sc+(quantity/2)-1));
    printf("A signed char can store %llu unique values\n\n", quantity);
    // Display information for unsigned short int data type
    printf("An unsigned short int is %d bytes\n", sizeof(usi));
    printf("The range of an unsigned short int is %hhu to %hhu\n", usi, (usi-1));
    quantity = (unsigned short int)(usi-1) + 1;    // What does this line do?
    printf("An unsigned short int can store %llu unique values\n\n", quantity);
    // Display information for signed short int data type
    printf("A signed short int is %d bytes\n", sizeof(ssi));
    quantity = (unsigned long long int)pow(2, (sizeof(ssi)*8)); // What is happening?
    printf("The range of a signed short int is %hhd to %hhd\n", (ssi-(quantity/2)), (ssi+(quantity/2)-1));
    printf("A signed short int can store %llu unique values\n\n", quantity);
    // Display information for unsigned int data type
    printf("An unsigned int is %d bytes\n", sizeof(ui));
    printf("The range of an unsigned int is %hhu to %hhu\n", ui, (ui-1));
    quantity = (unsigned int)(ui-1) + 1;    // What does this line do?
    printf("An unsigned int can store %llu unique values\n\n", quantity);
    // Display information for signed int data type
    printf("A signed int is %d bytes\n", sizeof(si));
    quantity = (unsigned long long int)pow(2, (sizeof(si)*8)); // What is happening?
    printf("The range of a signed int is %hhd to %hhd\n", (si-(quantity/2)), (si+(quantity/2)-1));
    printf("A signed int can store %llu unique values\n\n", quantity);
    // Display information for unsigned long int data type
    printf("An unsigned long int is %d bytes\n", sizeof(uli));
    printf("The range of an unsigned long int is %hhu to %hhu\n", uli, (uli-1));
    quantity = (unsigned long int)(uli-1) + 1;    // What does this line do?
    printf("An unsigned long int can store %llu unique values\n\n", quantity);
    // Display information for signed long int data type
    printf("A signed long int is %d bytes\n", sizeof(sli));
    quantity = (unsigned long long int)pow(2, (sizeof(sli)*8)); // What is happening?
    printf("The range of a signed long int is %hhd to %hhd\n", (sli-(quantity/2)), (sli+(quantity/2)-1));
    printf("A signed long int can store %llu unique values\n\n", quantity);
    // Display information for unsigned long long int data type
    printf("An unsigned long long int is %d bytes\n", sizeof(ulli));
    printf("The range of an unsigned long long int is %hhu to %hhu\n", ulli, (ulli-1));
    quantity = (unsigned long long int)(ulli-1) + 1;    // What does this line do?
    printf("An unsigned long long int can store %llu unique values\n\n", quantity);
    // Display information for signed long long int data type
    printf("A signed long long int is %d bytes\n", sizeof(slli));
    quantity = (unsigned long long int)pow(2, (sizeof(slli)*8)); // What is happening?
    printf("The range of a signed long long int is %hhd to %hhd\n", (slli-(quantity/2)), (slli+(quantity/2)-1));
    printf("A signed long long int can store %llu unique values\n\n", quantity);
    return(0);
}

Project 1 or as I like to call it Project2.c and Project2.1.c

#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        FILE *message, *key, *cipher;
        char c, fname[] = "message.txt";
        char code[] = "key.txt";
        int keyvalue;
 
        message = fopen(fname, "r");
        key = fopen(code, "r");
        cipher = fopen("cipher.txt", "w");
 
        c = fgetc(message);
        fscanf(key,"%d",&keyvalue);
 
        printf("Message is: ");
 
        while(c != EOF)
        {
                fprintf(stdout, "%c", c);
                c = fgetc(message);
        }
 
        fclose(message);
        message = fopen(fname, "r");
        c = fgetc(message);
 
        printf("Cipher is: ");
 
        while(c != EOF)
        {
                if((c >= 65) && (c <= 'Z'))
                        c = c + keyvalue;
                else if((c >= 'a') && (c <= 'z'))
                        c = c + keyvalue;
 
                fprintf(stdout, "%c", c);
                fprintf(cipher, "%c", c);
                c = fgetc(message);
        }
        fclose(message);
        fclose(key);
        return(0);
}
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        FILE *cipher, *key, *decipher;
        char c, fname[] = "cipher.txt";
        char code[] = "key.txt";
        int keyvalue;
 
        cipher = fopen(fname, "r");
        key = fopen(code, "r");
        decipher = fopen("decipher.txt", "w");
 
        c = fgetc(cipher);
        fscanf(key,"%d",&keyvalue);
 
        printf("Cipher is: ");
 
        while(c != EOF)
        {
                fprintf(stdout, "%c", c);
                c = fgetc(cipher);
        }
 
        fclose(cipher);
        cipher = fopen(fname, "r");
        c = fgetc(cipher);
 
        printf("Decipher is: ");
 
        while(c != EOF)
        {
                if((c >= 65) && (c <= 'Z'))
                        c = c - keyvalue;
                else if((c >= 'a') && (c <= 'z'))
                        c = c - keyvalue;
 
                fprintf(stdout, "%c", c);
                fprintf(decipher, "%c", c);
                c = fgetc(cipher);
        }
        fclose(cipher);
        fclose(key);
        return(0);
}

Keywords

cprog Keywords

cprog Keyword 1

Standard I/O (STDIO, STDOUT, STDERR).

Definition

Standard I/O stands for the Standard Input and Output, standard input devices are commonly keyboards or mice, etc… standard outputs are monitors, printers, etc…

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:

/*
 * Sample code block
 */
while(c != EOF)
        {
                if((c >= 65) && (c <= 'Z'))
                        c = c - keyvalue;
                else if((c >= 'a') && (c <= 'z'))
                        c = c - keyvalue;
 
                fprintf(stdout, "%c", c);

cprog Keyword 2

Pointers (address of, assignment, dereferencing)

Definition

Pointers are used to reference information, you would use a pointer to not directly place something but to reference multiple “things” to that location via a pointer.

Pointers are indicated with * symbol, pointers can contain more than one * as in ,*, and so on….

The * in a pointer is usually followed by a defining word or phrase or character, in my example listed I have *cipher, *key, and *decipher

The *cipher is a pointer to cipher and not actually cipher.

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:

/*
 * Sample code block
 */
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        FILE *cipher, *key, *decipher;

cprog Keyword 3

Arithmetic (equations, operators)

Definition

Mathematical logic that is used in pseudo codes syntax (IE: +,-,/,x,>,<,=,==,!=)

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:

 while(c != EOF)
        {
                if((c >= 65) && (c <= 'Z'))
                        c = c + keyvalue;
                else if((c >= 'a') && (c <= 'z'))
                        c = c + keyvalue;

cprog Keyword 4

Arrays (standard notation, pointer arithmetic, single-dimensional, multi-dimensional)

Definition

series list of memory values linked by a common name and data type.

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:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
num someVals[3]=25,44,22
 
    return(0);
}

cprog Keyword 5

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

Definition

Collection of predefined functions and syntax that can loaded as a library header file.

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:

/*
 * Sample code block
 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    return(0);
}

cprog Keyword 6

File Access (Read, Write, Append)

Definition

The File Access of a File determines the privileges the user has with the file upon opening said file, whether it be just being able to read, or read and write a new file, or append and add to an existing file(s)

Demonstration

Demonstration of the chosen keyword.

I believe that when you are trying to add or deny file access you would as follows

+r to allow reading, -r to not allow read

+w to write, -w to not allow writing

+a to allow appending, and -a to not…

cprog Keyword 7

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

Definition

logic operators like and, or, not, xor compare expressions, Boolean expressions in particular, they are also used to compare two expressions or sentences.

Demonstration

Demonstration of the chosen keyword.

x = Not 23 > 12   ' x equals False.
x = Not 23 > 67   ' x equals True.

cprog Keyword 8

Variables (types, ranges, sizes)

Definition

variables are identifiers that create a permanent “existence” the variable could be named anything from the letter x to the name Shane.

their are different types of variables that are pre-determined the c language for size allocation purposes; like:( char, int, long int…so on)

Demonstration

Demonstration of the chosen keyword.

    unsigned long long int quantity = 0;
    unsigned char uc = 0;
    signed char sc = 0;
    unsigned short int usi = 0;
    signed short int ssi = 0;
    unsigned int ui = 0;
    signed int si = 0;
    unsigned long int uli = 0;
    signed long int sli = 0;
    unsigned long long int ulli = 0;
    signed long long int slli = 0;

cprog Objective

cprog Objective

To learn the programming languages c and c++?

Definition

variables, pointers, classes, code, arrays, logic operators, math, header files…

Method

I will try my best and reflect that effort on a grade based system administered from professors.

Measurement

I don't really know much about this coming into this class but I know much more then I did, I can't really say that amounts to anything impressive to someone that does this for a living but I could probably hold a common conversation on the topic now.

Analysis
  • How did you do?

I probably could have learned more if I wasn't taking 4 other classes that were all full of brand new information at the same time, but ya know.

  • Is there room for improvement?

yes.

  • Could the measurement process be enhanced to be more effective?

sure?

  • Do you think this enhancement would be efficient to employ?

again sure?

  • Could the course objective be altered to be more applicable? How would you alter it?

I would try some simpler things for people that have no idea what is going on, and have been looking at this subject of study for the first time with this class.

Experiments

Experiment 1

Question

What will happen if I take the ; off the end of a statement and try to compile the program.

Resources

lab46

Hypothesis

Based on what I have learned thus far about c programming I think there would be an error in trying to compile the program.

I believe it would be considered a syntax error and the would be the reason there would be an error in trying to compile.

Experiment

I am going to experiment on a hello world program we wrote in class this semester on lab46

Data

lab46:~$ nano hello.c
lab46:~$ gcc -o hello hello.c
hello.c: In function 'main':
hello.c:5: error: expected ';' before 'return'
lab46:~$

Analysis

Based on the data collected:

  • Was your hypothesis correct?

yeah I am pretty good.

  • Was your hypothesis not applicable?

it was applicable

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

no sir.

  • What shortcomings might there be in your experiment?

intelligence.

  • What shortcomings might there be in your data?

data is good.

Conclusions

make sure you put ; at the end of applicable statements.

Experiment 2

Question

What happens if you do not include a return; at the end of your program/function.

Resources

lab46

Hypothesis

I am not entirely sure I am assuming I will get some sort of syntax error but to be sure I will have to run it to find out.

Experiment

I am going to use my hello world! program once again that is deployed on lab46

Data

lab46:~$ nano hello.c
lab46:~$ gcc -o hello hello.c
lab46:~$ nano hello.c
lab46:~$ ./hello
Hello, World!

Analysis

Based on the data collected:

  • Was your hypothesis correct?

No sadly I was wrong the program still ran and now I feel foolish.

  • Was your hypothesis not applicable?

it was.

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

apparently :O

  • What shortcomings might there be in your experiment?

intelligence.

  • What shortcomings might there be in your data?

none.

Conclusions

The program still ran and complied with the return; statement line removed.

Experiment 3

Question

I am going to attempt to add the multiplication portion of project 2 into project 2.

Resources

I used the other functions addition and subtraction that I had help writing, more so addition because I figured add and multiply are alike in common sense than subtraction.

Hypothesis

The goal is that it will work in the program just the way the other functions do and multiply my 4 digit numbers correctly. oh yeah and compile. hopefully.

Experiment

I wrote the code (at least it seems like working code to me) into the program and I will attempt to compile it and run it on lab46

Data

lab46:~/src/cprog$ nano bignum.c
lab46:~/src/cprog$ gcc -o bignum bignum.c
lab46:~/src/cprog$ ./bignum
How many digits are in your largest number?
4
Please enter 1 to Add, 2 to Subtract, 3 to Multiply, 4 to Divide
3
Enter your first number
0010
Please enter your second number
0010
01870
lab46:~/src/cprog$

Analysis

Based on the data collected:

  • Was your hypothesis correct?

no it was not my program told me 10×10 = 1870

  • Was your hypothesis not applicable?

it was.

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

i have no idea.

  • What shortcomings might there be in your experiment?

knowledge of how to program

  • What shortcomings might there be in your data?

the intended answer.

Conclusions

I did not get the correct answer, I will have to figure it again a better way that produces the intended answer.

opus/spring2012/sswimle1/part1.txt · Last modified: 2012/05/04 16:14 by sswimle1