======Part 2======
=====Entries=====
====Entry 5: March Day, 2012====
For the UNIX course I currently enrolled in i have created a IRC bot phenny.It's pretty cool, once you get going it becomes alot of fun. Creating a phenny bot is significant because it allows you to script a bot and based on some conditions the bot does things.In the begining i had some difficulty with scripting but this activity helped me.
====Entry 6: March Day, 2012====
GNU debugger
when you compile code use -g along with regular compile which looks like this
gcc -g -o acs2 acs2.c
then run your program in the debugger:
gdb ./acs2
to fully use this debugger set breaking points such as
break main break 11
break 17
once breaking points are set then you can run the program by typing "run"
type "n" for next line
you can also print values of variables if you type print "the variable name"
this is a very useful tool for finding possible mistakes or to fix mistakes.
this is a very basic use of gnu debugger this debugger is capible of much more so please explore.
====Entry 7: March Day, 2012====
C++ OOP-Object-Oriented Programming
to make a C++ file type .cc after you file instead of .c
compile with g++ -o hello1 hello.cc
C++ class notes
Classes & Objects
Inheritance/Multiple Inheritance
Polymorphism
Templates
====Entry 8: March Day, 2012====
class notes on struct
struct person{
char *name;//or --char name[20];
unsigned char age;
short int weight;
float gpa;
};
//struct differ from union bec struct allocate memory for each and dont share $
typedef struct person P;
P p1,p2,p3,p4,p5;
struct person p1;
struct person p2;
struct person p3,p4,p5;
p1.age = 29;
=====Keywords=====
{{page>cprogpart2&nofooter}}
{{page>unixpart2&nofooter}}
=====Experiments=====
====Experiment 4====
===Question===
What happends when you leave out a semi colin on a struct.
===Resources===
struct weki pages
===Hypothesis===
Based on what i read i think the result of your experiment will be a compile erroor.
i believe this because funtions do not need them after curly brace but a struct would have to
===Experiment===
i will create a struct and compile it to see if it compiles with out errors.
===Data===
like i thought the semi colin is very important. i recieved a error when compiling
===Analysis===
Based on the data collected:
my hypothesis correct, and applicable for the data collected.
===Conclusions===
based on the experiment performed and data collected leaving a semi colin out of a struct will cause an error when compiling. Error exspected expression.
====Experiment 5====
===Question===
when defining a funtion can you put a return type on a void funtion()
===Resources===
class notes void main() and int main()
===Hypothesis===
based on class notes i the void main cannot have a return valuenbecause void main mean nothing is being returned.
===Experiment===
i will create a void sum funtion and then type retutn(0); at the end pf the funtion. i will then compile and see what happends if any/
===Data===
lab46:~/src/cprog/project2$ gcc -o prog2f prog2f.c
prog2f.c: In function 'sum':
prog2f.c:56: warning: 'return' with a value, in function returning void
lab46:~/src/cprog/project2$
===Analysis===
Based on the data collected my hypothesis was not correct
but it was applicable. there was no short commings ut just a little more going on then exspected
===Conclusions===
based on the experiment performed and data collected having a return type to a void funtion will give a warning but will still compile.
====Retest 2====
===State Experiment===
brobbins exsperiment 1
===Resources===
Evaluate their resources and commentary. Answer the following questions:
* Do you feel the given resources are adequate in providing sufficient background information?
* Yes
* Are there additional resources you've found that you can add to the resources list?
* No
* Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
* Yes
* If you find a deviation in opinion, state why you think this might exist.
* No the hypothesis looks looks good.
===Hypothesis===
Based on what I have learned about the C programming language thus far, I believe that the use of the exit command within a function will only cause the function to exit and not the entire program due to the fact that the exit argument would only be in scope with the current function and not the rest of the program.
* Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
* Yes
* What improvements could you make to their hypothesis, if any?
* None
===Experiment===
* Are the instructions correct in successfully achieving the results?
* Yes
* Is there room for improvement in the experiment instructions/description? What suggestions would you make? No accomplishes the what is exsperimented.
* Would you make any alterations to the structure of the experiment to yield better results? What, and why? No the structire of the exsperiment is is sufficient enough.
===Data===
This is the original code
#include
#include
#include
int iseven(int value)
{
int tmp;
tmp=value % 2;
return(tmp);
}
void add(int *list, int total, int value)
{
int i, s=0;
for(i=0; i < total; i++)
{
if(*(list+i)==-1)
{
*(list+i)=value;
s=i;
break;
}
}
}
int *init(int total, int *status)
{
int i, *tmp;
*status=0;
if(total > 0)
{
tmp=(int*)malloc(sizeof(int)*total);
for(i=0; i < total; i++)
{
*(tmp+i)=-1;
}
*status=1;
}
return(tmp);
}
int main(int argc, char **argv)
{
int *list, i, x=0;
list=init(atoi(*(argv+1)),&x);
if(x==0)
{
fprintf(stderr, "Error on initialization!");
exit(1);
}
for(i=0; i < atoi(*(argv+1)); i++)
{
add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
}
for(i=0; i < atoi(*(argv+1)); i++)
{
if(iseven(*(list+i))==0)
{
fprintf(stdout, "%d is even\n", *(list+i));
}
else
fprintf(stdout, "%d is odd\n", *(list+i));
}
return(0);
}
This is the output received from the unmodified code.
lab46:~/src/cprog$ ./iseven 5 30
13 is odd
16 is even
27 is odd
25 is odd
23 is odd
lab46:~/src/cprog$
The following is the code that has been modified to reflect the question above. Note the change in the “add” function, the “break” statement has been changed to an “exit” statement with a return code of zero. Also note the inclusion if the new printf statements within each function. These are included so I am able to tell how far the program progresses.
#include
#include
#include
int iseven(int value)
{
printf("Diag 1\n");
int tmp;
tmp=value % 2;
return(tmp);
}
void add(int *list, int total, int value)
{
printf("Diag 2\n");
int i, s=0;
for(i=0; i < total; i++)
{
if(*(list+i)==-1)
{
*(list+i)=value;
s=i;
exit(0);
}
}
}
int *init(int total, int *status)
{
printf("Diag 3\n");
int i, *tmp;
*status=0;
if(total > 0)
{
tmp=(int*)malloc(sizeof(int)*total);
for(i=0; i < total; i++)
{
*(tmp+i)=-1;
}
*status=1;
}
return(tmp);
}
int main(int argc, char **argv)
{
printf("Diag 4A\n");
int *list, i, x=0;
printf("Diag 4B\n");
list=init(atoi(*(argv+1)),&x);
printf("Diag 4C\n");
if(x==0)
{
fprintf(stderr, "Error on initialization!");
exit(1);
}
printf("Diag 4D\n");
for(i=0; i < atoi(*(argv+1)); i++)
{
printf("Diag 4Da\n");
add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
printf("Diag 4Db\n");
}
for(i=0; i < atoi(*(argv+1)); i++)
{
if(iseven(*(list+i))==0)
{
fprintf(stdout, "%d is even\n", *(list+i));
}
else
fprintf(stdout, "%d is odd\n", *(list+i));
}
return(0);
}
The following is the resulting output after the modifications.
lab46:~/src/cprog$ ./iseven 5 30
Diag 4A
Diag 4B
Diag 3
Diag 4C
Diag 4D
Diag 4Da
Diag 2
lab46:~/src/cprog$
===Analysis===
* Does the data seem in-line with the published data from the original author?
* Yes every thing comes out good
* Can you explain any deviations?
* There was no deviations from experiment
* How about any sources of error?
* Code could have been written a little better
* Is the stated hypothesis adequate?
* Yes stated hypothesis is adequate
===Conclusions===
* What conclusions can you make based on performing the experiment?
* With the data collected the hypothesis is correct
* Do you feel the experiment was adequate in obtaining a further understanding of a concept?
* yes
* Does the original author appear to have gotten some value out of performing the experiment?
* Yes
* Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).
* No