======Part 3======
=====Entries=====
====Entry 9: April 25, 2012====
Wanted to revisit structs and unions from a class we had this semester.
When creating a struct you are making a record for a set of labelled objects into a single structured object.
Example:
struct sales {
int month sales;
char *item_name;
char *item_type;
float totals;
};
This is an example of a struct declaration, which is a list of fields that can contain any types (int, char, etc...) and allocates a total amount of storage based on the sum requirements for all of the list types included, along with any internal padding.
A union is nearly the same as a struct except for the way a union allocates memory, each data type in the union starts from the same location in memory instead of having its own location like in a struct.
The concept of a union is to save space the multiple data types inside the union are being condensed into the same memory location.
Example:
union
{
<1st variable name>;
<2nd variable name>;
.
.
.
;
} ;
====Entry 10: May 1, 2012====
Since we talked about inheritance at length this semester I will refresh on that with this journal entry.
Inheritance in programing has to do with the way classes relate to each other, for example there are two main types of classes in respect to programming inheritance parent classes and child/children classes.
Parent classes are the preceding classes that came before their children a lot like it would seem. Parent classes are also sometimes called superclasses, ancestor classes or base classes.
Child classes or subclasses are derived from their parent class and live in a hierarchy based system.
The application of using inheritance in programming is to relate two or more classes together.
====Entry 11: May 8th, 2012====
Figured I would write this opus entry on Header Files since that seems to be one of the thing I do grasp.
There are a few different instances of header files
There is the standard Library of header files which are already made files saved that included commonly used declarations that a program might need, for instance stdio.h which includes common input and output functions used in c programming and stdlib.h which includes standard collection of functions collected into a library file.
There are also header files that you can make on your own for instance if you wrote a function saved it and then included it in another function as a .h file that program will now use all the logic from the other instance your wrote with just the file included at the start of the new file as a .h file.
====Entry 12: May 8th, 2012====
Just going to scribble some things down here for the last entry as I go through some of the programs we accomplished in class this semester.
int main ( ) // anything inside the parenthesis are parameters for main and the first parameter of main must be an integer.
when on a line of code if you type a \ followed by enter the syntax is that the line will continue onto the next line below it but the program will read it as a single line of code even though for your viewing pleasure its broken up into more than one line of text.
int sum(int, int, int, int); // is a function prototype.
and so on...
{{page>cprogpart3&nofooter}}
=====Experiments=====
====Experiment 7====
===Question===
What will happen if i replace a for loop with a while loop in my program. as shown here
#include
#include
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
I am going to replace the for loop in this program with a while loop and see what happens.
===Resources===
lab46
===Hypothesis===
I do not have a clue what it will do. My best guess is break something.
State your rationale.
Seems like something that would break something.
===Experiment===
lab46
===Data===
lab46:~/src/cprog$ nano sample1.c
lab46:~/src/cprog$ gcc -o sample1 sample1.c
sample1.c: In function 'main':
sample1.c:15: error: expected ')' before ';' token
===Analysis===
Based on the data collected:
* Was your hypothesis correct?
Yep it broke
* Was your hypothesis not applicable?
it was
* Is there more going on than you originally thought? (shortcomings in hypothesis)
no I think it just produces a syntax error
* What shortcomings might there be in your experiment?
none
* What shortcomings might there be in your data?
none
===Conclusions===
I broke the program you can not just simply make a for loop a while loop
====Experiment 8====
===Question===
I am going to try and add a simple multiplication function to the file sample2.c where we had 4 int declared and the program calculating a sum and average.
===Resources===
lab46
#include
#include
int sum(int,int,int,int); //function prototype
int average(int,int,int,int);
int main()
{
int a,b,c,d;
int avg;
a=b=c=d=0;
avg=0;
printf("Enter first value: ");
fscanf(stdin, "%d",&a);
printf("Enter second value: ");
fscanf(stdin, "%d",&b);
printf("Enter third value: ");
fscanf(stdin, "%d",&c);
printf("Enter fourth 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));
fprintf(stdout,"the average of %d, %d, %d, and %d is:%d\n",a,b,c,d,average(a,b,c,d));
return(0);
}
int sum(int n1, int n2, int n3, int n4)
{
int total=0;
total=n1+n2+n3+n4;
return(total);
}
int average(int n1, int n2, int n3, int n4)
{
int average=0;
average=(n1+n2+n3+n4)/4;
return(average);
}
===Hypothesis===
I am going to try and follow the code above and add a similar instance for multiplication to see if i can get it to work I assume this will be easier than project 2's concept.
State your rationale.
project 2 was dealing with specific allocated 4 digit numbers and something like that i don't know this just looks like it is going to make more sense to me and maybe work.
===Experiment===
lab46
===Data===
lab46:~/src/cprog$ nano sample2.c
lab46:~/src/cprog$ gcc -o sample2 sample2.c
lab46:~/src/cprog$ ./sample2
Enter first value: 2
Enter second value: 2
Enter third value: 2
Enter fourth value: 2
the sum of 2, 2, 2, and 2 is:8
the average of 2, 2, 2, and 2 is:2
the product of 2, 2, 2, and 2 is:16
lab46:~/src/cprog$
===Analysis===
Based on the data collected:
* Was your hypothesis correct?
Yeah it worked amazingly.
* Was your hypothesis not applicable?
for once yes.
* Is there more going on than you originally thought? (shortcomings in hypothesis)
no
* What shortcomings might there be in your experiment?
no
* What shortcomings might there be in your data?
no
===Conclusions===
It worked I am pretty much pro.
====Retest 3====
Perform the following steps:
===State Experiment===
Whose existing experiment are you going to retest? Provide the URL, note the author, and restate their question.
===Resources===
Evaluate their resources and commentary. Answer the following questions:
* Do you feel the given resources are adequate in providing sufficient background information?
* Are there additional resources you've found that you can add to the resources list?
* Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
* If you find a deviation in opinion, state why you think this might exist.
===Hypothesis===
State their experiment's hypothesis. Answer the following questions:
* Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
* What improvements could you make to their hypothesis, if any?
===Experiment===
Follow the steps given to recreate the original experiment. Answer the following questions:
* Are the instructions correct in successfully achieving the results?
* Is there room for improvement in the experiment instructions/description? What suggestions would you make?
* Would you make any alterations to the structure of the experiment to yield better results? What, and why?
===Data===
Publish the data you have gained from your performing of the experiment here.
===Analysis===
Answer the following:
* Does the data seem in-line with the published data from the original author?
* Can you explain any deviations?
* How about any sources of error?
* Is the stated hypothesis adequate?
===Conclusions===
Answer the following:
* What conclusions can you make based on performing the experiment?
* Do you feel the experiment was adequate in obtaining a further understanding of a concept?
* Does the original author appear to have gotten some value out of performing the experiment?
* Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).