======Part 3======
=====Entries=====
====Entry 9: April 26, 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:
* On this day, I learned how to create nested functions to achieve a set goal.
* It allowed me to complete a project, as well as showed me what is possible with functions.
* I had trouble figuring out how to work pointer functions, due to the use of pointers inside of them and passing them to each other.
* I understand it, now. The use of nested functions should be easier for me, now.
====Entry 10: April 26, 2012====
* On this date, I found out that I can use **fscanf** instead of **fgetc** to accept character input that I need to change into integer.
* This allows me to use something I am more familiar with to assign input to values.
* What doesn't quite make sense to me is the buffer, and how if the buffer has a random value, like enter from the last time it was pressed, it gets printed.
* The challenge I am facing with the course at the moment is catching up on all of my work!
====Entry 11: April 5, 2012====
* On this date, we learned about polymorphism.
* Polymorphism allows a program to redefine functions and use them for a different purpose.
* The idea makes sense, what doesn't make as much sense is how to implement it in programming.
* I am having trouble with C++ and most of what that includes.
====Entry 12: April 22, 2012====
* On this date, we learned about Templates.
* Templates are like blueprints of code. It contains something that can be made but isn't actually made in the template.
* I'm not sure how I would use this, it seems that it would be important, but how to write it, I have no idea.
* I think I will try to implement it a few times.
{{page>cprogpart3&nofooter}}
=====Experiments=====
====Experiment 7====
===Question===
Will passing by reference work just as well as passing by value? Specifically, would they give me the same result?
===Resources===
Passing by reference is a method that, when looking at pointers, points one argument at the address of another. Passing by value allows the compiler to copy one or more values in one or more addresses into a function, and allows the function to use these values. The original variables that are used are not changed.
===Hypothesis===
I believe that they won't give me the same result. What will most likely happen is using pass-by-reference will allow me to manipulate the value given and the value given will be saved, but the value will not be saved as I would have liked with pass-by-value.
===Experiment===
In my experiment, I will create a running program that will use both methods for the same purpose. The program will have one function for performing passing-by-value; the main function will have the coding for passing-by-reference. I will perform the same change on the variables, and that will determine whether or not the same change takes place for both cases.
===Data===
Perform your experiment, and collect/document the results here.
**Code for the experiment:**
#include
#include
// Function to demonstrate passing-by-value
void passByValue( int val1, int val2 )
{
int pbv1, pbv2;
pbv1 = pbv1 + 5;
pbv2 = pbv2 + 5;
}
int main()
{
int pbv1 = 5, pbv2 = 10, pbr1 = 5, pbr2 = 10;
printf("Values before adding 5:\n");
printf("a: %d\nb: %d\nc: %d\nd: %d\n", pbv1, pbv2, pbr1, pbr2);
passByValue( pbv1, pbv2 );
pbr1 = pbr1 + 5;
pbr2 = pbr2 + 5;
printf("Values after adding 5:\n");
printf("a: %d\nb: %d\nc: %d\nd: %d\n", pbv1, pbv2, pbr1, pbr2);
return 0;
}
**Results of the experiment:**
lab46:~/src/cprog/Opus/Opus3$ ./experiment1
Values before adding 5:
a: 5
b: 10
c: 5
d: 10
Values after adding 5:
a: 5
b: 10
c: 10
d: 15
lab46:~/src/cprog/Opus/Opus3$
===Analysis===
Based on the data collected:
* Was your hypothesis correct?
-- My hypothesis was correct, they did not have the same change in values.
* Was your hypothesis not applicable?
-- My hypothesis was applicable, the variables that were passed by reference did change, but the variables that were passed by value did not remain changed, they went back to their original values.
* Is there more going on than you originally thought? (shortcomings in hypothesis)
-- Not really, all that I thought would happen, did happen. This just helped me to confirm my understanding of passing variables in different ways.
* What shortcomings might there be in your experiment?
-- I did not print what the value was in the function, so the value may have never changed. I am certain that it did, however.
* What shortcomings might there be in your data?
-- There weren't any, really. Everything seemed to work and was accounted for.
===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.
-- I can now say that I fully understand the difference between passing-by-value and passing-by-reference. I was confused on what the differences were, and if they were both applicable in any case, but it seems that they aren't and I need to decide when either is more appropriate.
====Experiment 8====
===Question===
When using logic operators, can one use more than two (in an if statement)?
===Resources===
Logic operators consist of //and//, //or//, //not//, //is equal to//, etc. These logic operators are usually used to check one variable or compare two variables which determine whether or not a piece of code will run or not. These operators are represented, in code, by these characters:
*//and//: **&&**
*//or//: **||**
*//not// or //not equal to//: **!=**
*//is equal to//: **==**
===Hypothesis===
I don't think that more than two logic operators can be used without any clarification of their separation (parenthesis separating them). I believe that this would cause confusion in the code, and the compiler would not read the code as it was intended to be read, therefore leading to a logical error, but not a syntax error.
===Experiment===
I am going to create a block of code that will test this. The if block will only run if **x** and **y** are **greater than 0** or **less than 0**.
===Data===
Code for the experiment (the one that separates):
#include
#include
int main()
{
int x = 0, y = 0;
printf("The following program will test to see if the result of two input numbers, when multiplied or divided, \
\nwill return a positive or negative number.\nPlease input the first value: ");
scanf("%d", &x);
printf("\nPlease input the second value: ");
scanf("%d", &y);
if( x == 0 || y == 0 )
{
printf("The value is zero.\n");
}
else if( ( x > 0 && y > 0 ) || ( x < 0 && y < 0 ) )
{
printf("The value will be positive\n");
}
else
{
printf("The value will be negative\n");
}
return 0;
}
The result for this code (with parenthesis as separation) worked and printed this:
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: -1
Please input the second value: -2
The value will be positive
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: 1
Please input the second value: 2
The value will be positive
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: -1
Please input the second value: 2
The value will be negative
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: 1
Please input the second value: -2
The value will be negative
lab46:~/src/cprog/Opus/Opus3$
Code without separation:
#include
#include
int main()
{
int x = 0, y = 0;
printf("The following program will test to see if the result of two input numbers, when multiplied or divided, \
\nwill return a positive or negative number.\nPlease input the first value: ");
scanf("%d", &x);
printf("\nPlease input the second value: ");
scanf("%d", &y);
if( x == 0 || y == 0 )
{
printf("The value is zero.\n");
}
else if( x > 0 && y > 0 || x < 0 && y < 0 )
{
printf("The value will be positive\n");
}
else
{
printf("The value will be negative\n");
}
return 0;
}
The result without separation:
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: 1
Please input the second value: 1
The value will be positive
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: -1
Please input the second value: -1
The value will be positive
lab46:~/src/cprog/Opus/Opus3$ ./experiment2
The following program will test to see if the result of two input numbers, when multiplied or divided,
will return a positive or negative number.
Please input the first value: 0
===Analysis===
Based on the data collected:
* Was your hypothesis correct?
-- My hypothesis was incorrect. I should have known, seeing as how C programming is free-form.
* Was your hypothesis not applicable?
-- It wasn't really applicable, I figured it out, and decided to double check my incorrectness-ocity-ism!
* Is there more going on than you originally thought? (shortcomings in hypothesis)
-- Not really with this, it is a simple concept, I just messed up!
* What shortcomings might there be in your experiment?
-- Well, at first, I had an error. I fixed it in the code and it ran properly.
* What shortcomings might there be in your data?
-- There don't appear to be any shortcomings in my data.
===Conclusions===
Well, my understanding of how free-form coding works seems to have eluded me for a time. I have regained it, and now I shall use that power to further my exploration into the world of programming! YEAH!
====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.
-- I decided to retest Josh Davis' experiment about multiplying an **int** value and a **float** value together. What would be the result?
-- http://lab46.corning-cc.edu/opus/spring2012/jdavis34/start#experiment_3
===Resources===
Evaluate their resources and commentary. Answer the following questions:
* Do you feel the given resources are adequate in providing sufficient background information?
-- He said he was able to create and run the program to provide a result for this experiment on his own from what he had learned in class. I believe it. He seemed to know what he was doing.
* Are there additional resources you've found that you can add to the resources list?
-- I would use the C for Engineers class as a resource, because I vaguely remember learning about this, the answer just escapes me.
* Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
-- I believe he does understand it.
* If you find a deviation in opinion, state why you think this might exist.
-- No deviations in opinion, sir!
===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?
-- I believe that he has a thorough hypothesis, but I don't think it will go as he plans it to.
* What improvements could you make to their hypothesis, if any?
-- I don't think that there are any improvements that you could make on his hypothesis. It seems very in depth.
===Experiment===
Follow the steps given to recreate the original experiment. Answer the following questions:
* Are the instructions correct in successfully achieving the results?
-- The instructions appear to be correct.
* Is there room for improvement in the experiment instructions/description? What suggestions would you make?
-- I would suggest that he should have given some sort of result, and spaced it all out, made it a little easier to read. Just small things.
* Would you make any alterations to the structure of the experiment to yield better results? What, and why?
-- I would not!
===Data===
Publish the data you have gained from your performing of the experiment here.
DA CODE:
#include
#include
int main()
{
float x, z1;
int y, z2;
printf("Please input a number with a decimal value: ");
scanf("%f", &x);
printf("\nPlease input a whole number: ");
scanf("%d", &y);
z1 = x * y;
z2 = x * y;
printf("\nThe result stored in a float variable: %f\n", z1);
printf("The result stored in an int variable: %d\n", z2);
return 0;
}
DA RESULT:
lab46:~/src/cprog/Opus/Opus3$ ./retest2
Please input a number with a decimal value: 1.2
Please input a whole number: 2
The result stored in a float variable: 2.400000
The result stored in an int variable: 2
lab46:~/src/cprog/Opus/Opus3$
===Analysis===
Answer the following:
* Does the data seem in-line with the published data from the original author?
-- It is hard to determine, because he never actually showed any results. He used a function he created to multiply them together, which is cool, but I didn't do that.
* Can you explain any deviations?
-- Mine was a little more organized and seemed to work better, since he said his did not compile.
* How about any sources of error?
-- There are no errors in mine.
* Is the stated hypothesis adequate?
-- The stated hypothesis is pretty good, had I not known ahead of time, I would have thought the same thing would happen.
===Conclusions===
Answer the following:
* What conclusions can you make based on performing the experiment?
-- I can conclude that it is not necessary to add a specifier of how many decimals is needed when printing out a float value or assigning a float value.
* Do you feel the experiment was adequate in obtaining a further understanding of a concept?
-- I do believe that this experiment was a good way of further understanding floats, since we didn't work with them much during the course.
* Does the original author appear to have gotten some value out of performing the experiment?
-- It appears that he knew, then, that his understanding of variables and data types was not complete and not as in depth as he thought.
* Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).
-- I have no suggestions.