======Part 2====== =====Entries===== ====Entry 5: March 26, 2012==== The fact that I can not figure out how to use atoi has led me to use this opus entry on Type Conversions. __The C Programming Language__ 2nd edition by Kernighan and Ritchie says "When an operator has operands of different types, they are converted to a common type according to a small number of rules. In general the only automatic conversions are those that convert a "narrower" operand into a "wider" one without loosing any information... A char is just a small integer, so chars may be freely used in arithmetic expressions. This permits considerable flexibility in certain kinds of character transformations. One is exemplified by this naive implementation of the function atoi, which converts a string of digits into its numeric equivalent." /* atoi: convert s to integer */ int atoi(char s[]) { int i, n; n = 0; for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i) n = 10 + n + (s[i] - '0'); return n; } That is all I really read and found in the book/index that specifically talked about the atoi function. __C Pocket Reference__ by Prinz & Kirch-Prinz **Conversion Between Strings and Numbers** "A variety of functions are declared in the header file //stdlib.h// to obtain numerical interpretations of the initial digit characters in a string. The resulting number is the return value of the function." int atoi( const char *s ); /*Interprets the contents of the string s as a number with type int. The analogous functions atol(), atoll()(*), and atof() are used to convert a string into a number with type long, long long(*), or double.*/ And that is pretty much what that book had to say about my problem so I guess I will go ahead and try to work on implementing this into my project bignum.c ====Entry 6: March 30, 2012==== for(x = digit1; x >= 0; x--) { *(result+x) = *(value1+x) + *(value2+x) + *(result+x); if(*(result+x) > 9) { *(result+x) = *(result+x) - 10; *(result+x - 1) = *(result+x - 1) + 1; } } For this opus entry I am going to try and re-break down what Matt went over with me in the last class session. The first line of the for loop in the the code block above is stating: for the instance that the variable x equals the int digit1 and also the variable x is greater than or equal to zero decrement x by 1. *(result+x) = *(value1+x) + *(value2+x) + *(result+x); This line is saying that the pointer of result+x is equal to the pointer of value1+x plus the pointer of value2+x plus the pointer of result+x which has been zeroed out for the program. if(*(result+x) > 9) The if statement is creating a condition that if the pointer of result+x is greater than the number 9 to go on and do what other instructions are in the if statement. { *(result+x) = *(result+x) - 10; *(result+x - 1) = *(result+x - 1) + 1; } Inside of the if statement as the code shown above is saying process this code when the if statement is true. Take the current result x variable you are working with and subtract 10 and take the next result x variable to the left and add 1 to it. ====Entry 7: April 3, 2012==== Inheritance in object-oriented programming is a way to use code that you have previously included in a class, usually refered to as parent classes, base classes, or a superclasses. The new classes that are inheriting the base class are commonly refered to as child classes or subclasses and or derived classes. #ifndef _RECTANGLE_H #define _RECTANGLE_H #include "shape.h" class rectangle: public shape{ public: virtual int perimeter(); virtual int area(); }; #endif As shown in the code block example above this file called rectangle.h would be inheriting the public classes code from the file shape.h making the parent file shape.h and the child file rectangle.h Class inheritance has three different types of data: Public: Any other files in your inheritance tree that include the header files needed to use those public variables of the class you are trying to access can. Protected: Only a child file of the parent can use protected files, if a child is not directly pointed to the parent file they are trying to access protected data from that child file will not be able to access the protected portion of that code. Private: Private variables are only accessable by the class they are defined in, although they can be accessed through a call to a protected or public variable in the same class that has access. ====Entry 8: April 5, 2012==== The GNU Compiler Collection or (GCC) is a programming code compiler, a compiler is an application that uses source code written in a programming language and creates object code to have an executable program from the source code. The languages the compiler can compile that we deal with in our class are C (gcc) and C++ (g++) The compiler consists of a front-end and back-end The front-end of the compiler handles the programming language setting up the information to be handled by the back-end The back-end deals with converting the language into the specific target architecture =====Keywords===== {{page>cprogpart2&nofooter}} =====Experiments===== ====Experiment 4==== ===Question=== What will happen if you do not include the \n at the end of a printf statement. ===Resources=== lab46 ===Hypothesis=== I am thinking that without the \n the printf statement will not display. State your rationale. I am pretty sure \n is a terminator for the printf statement. ===Experiment=== I am going to test my hypothesis on lab46 with my hello.c program. ===Data=== lab46:~$ nano hello.c lab46:~$ gcc -o hello hello.c lab46:~$ ./hello Hello, World!lab46:~$ ===Analysis=== Based on the data collected: * Was your hypothesis correct? No. * Was your hypothesis not applicable? it was applicable. * Is there more going on than you originally thought? (shortcomings in hypothesis) No. * What shortcomings might there be in your experiment? I guessed wrong. * What shortcomings might there be in your data? None. ===Conclusions=== The program still complied and ran without the \n at the end of my printf statement but as you can see the command prompt ended up on the same line that the program executed the printf on. So the \n is a line terminator and not a printf function terminator if that makes sense in the best of my ability to explain what I am experimenting. ====Experiment 5==== ===Question=== For this experiment I will be seeing what will happen if the program does not include a main function and just includes statements. Like this. #include { printf("Hello, World!\n"); return(0); } ===Resources=== Lab46 ===Hypothesis=== I am not sure what will happen I am assuming the program will not compile or function properly. State your rationale. I am thinking that the program needs a Function structure of some sort to run properly. ===Experiment=== going to test this on lab46 ===Data=== lab46:~$ gcc -o hello hello.c hello.c:3: error: expected identifier or '(' before '{' token ===Analysis=== Based on the data collected: * Was your hypothesis correct? Yeah I believe this time it was I did get an error for an expected identifier. * Was your hypothesis not applicable? it was applicable. * Is there more going on than you originally thought? (shortcomings in hypothesis) No I think the identifier the program is looking for is the main function. * What shortcomings might there be in your experiment? None. * What shortcomings might there be in your data? None. ===Conclusions=== The program did not compile when the line of int main() was removed from the program I am not 100% sure if it was asking for a function container, okay well i just did this experiment to test it further. #include main() { printf("Hello, World!\n"); return(0); } and the program ran and compiled so the int was not necessary it was looking for a main() function or a function container in general I am guessing. Not sure if it has to named main() but that sounds like another experiment. ====Retest 2==== 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).