======Part 1====== =====Entries===== ====Entry 1: January 26, 2012 - C/C++ Programming==== Today, for C/C++ in-class we learned a good deal about pointers. Beforehand, from learncpp.com I had read about pointers and even messed around with them in visual studio express but they always manage to confuse me or trip me up somehow. We also did a little on binary, and if knowing binary well becomes a necessity I will have to google and read up on it. Regarding pointers and whatnot, we made a .c file in class with two variables, with b pointing towards a. We would assign pointer b a value, and that value would then be assigned to a. It's almost like the point is a soft shortcut to whatever address it's pointing to. What threw me off was that we would then fstream the b value, and de-reference it, and then b would suddenly be equal to 12. I'm guessing repetition, and messing with the code, will help me understand it. For the most part, it all did make sense. Along with the binary, and signed and unsigned variables. Overall, pointers and referencing addresses of variables makes sense to me. When it comes to a bunch of things with pointers and address references going on at once, I find it a little challenging to try to follow what exactly is happening. As for binary, I can understand enough to understand how signed and unsigned works. ====Entry 2: February 1, 2012 - Unix/Linux Fundamentals==== I am supposed to make a tree of the UNIX file system, with my home directory in it along with a couple other things. root | home | smalik2 / | \ archives bin src / \ unix cprog ====Entry 3: February 9, 2012 - Unix/Linux Fundamentals==== All of the things that we learned in the first two weeks for Linux has actually helped me understand more other things outside of class. Going through directories, moving files, copying files, and other commands we've learned so far I've been using. Over the past couple weeks I've been modding and messing around with my phone, and since I try to primarily use Ubuntu, I end up using terminal a lot. When I run into a guide on a website and they just have lists of commands to type in terminal to make something happen, I actually know what they're talking about as opposed to just following directions. This level of understanding really helps when it comes to troubleshooting problems, and with not blindly following instructions just hoping that it will magically work. Since Android phones are based on a Linux kernel, when it comes to navigating my phones contents through the terminal on the computer, I actually know how to do it. I can really appreciate how nicely my need to know this material has coincided with this class. I also appreciate how widely used Linux appears to be, although many people probably do not realize it. ====Entry 4: February 12, 2012 - C/C++ Programming==== This past Friday in Object Oriented Problem Solving, we were creating an algorithm to read a user entered number. The ultimate goal will be to read the number and convert it to base ten, but right now the objective is to simply read in the number, each digit separately (without the user actually entering each digit separately). I attempted to do this using C, but kept on hitting various errors. Segmentation faults, syntax, logical errors, etc. The end result was that there was SOMETHING wrong with the line containing the modulus function, where it would take a mod of the number entered by powers of ten (basically knocking off and storing the last digit in the number), and the digit would not be stored in the Array. I am not sure if this is a problem with the array (I am still not comfortable with C, I'm much more used to C++) or the mathematical functions being performed. I briefly talked to Professor Oppenheim about it after class, but unfortunately I was in a rush so could not check the code with him. We will look over it next time we have class hopefully. We figured it out, the problem was that one of the variables that was being changed had not been passed by reference. Adding an & fixed this, and the program started running. ====Entry 5: February 27, 2012 - UNIX/Linux Fundamentals==== This is somewhat random, but I since I have been running Ubuntu 99% exclusively on my laptop now and it is Linux based, it is part of my everyday life pretty much. So much so that I recommend it over Windows to my friends. I was helping somebody (who is not taking UNIX) install it on their laptop, and then when they were trying to use it they had to ask me how to create just a text file - thanks to the UNIX class I could immediately just tell them 'just use terminal, and then nano [filename].txt'. I would have recommended vim, but they had tried it before and it didn't end well. Additionally, I am contemplating attempting the Linux from Scratch project which is basically building a linux based OS from scratch -- teaching you a ton about the whole thing and how it works in the process. Perhaps I will attempt this when I have more free time on my hands. =====Keywords===== {{page>cprogpart1&nofooter}} {{page>unixpart1&nofooter}} =====Experiments===== ====Change base 8 to base 10==== ===Question=== My experiment is to create a program that will convert any 3 digit base 8 number to base 10, and vice versa. ===Resources=== http://www.unitconversion.org/numbers/base-10-to-base-8-conversion.html -- To double check program once I begin testing it. http://science.widener.edu/~schultz/mathhelp2.html -- This will help me develop the logic to run behind the program. ===Hypothesis=== I'm guessing that by the time I finish, I will have a program that can accomplish the goal. ===Experiment=== See if the program will output correct data given an input (checked against the converter I found online). ===Data=== Program so far: GNU nano 2.2.4 File: Algorithm.c Modified =#include #include #include int main() { int number = 0; int array[3]; int count = 0; int random = 0; int result = 0; int choice; printf("This program will convert any three digit number to a different base\n"); printf("For base 8 to base 10, press 1\n"); printf("For base 10 to base 8, press 2\n"); scanf("%d", &choice); if(choice == 1) { printf("\nEnter a base 8, three digit number :"); scanf("%d", &number); printf("\nThat number will now be converted to base 10\n"); printf("\nThe number you input was: %d\n", number); for(count = 0; count <=2; ++count) { random = number%10; array[count] = random; number = (number-random)/10; } for(count = 2; count >=0; --count) { result = result + array[count]*(pow(8, count)); } printf("\nThat number in base 10 is %d\n", result); } if(choice == 2) { printf("Enter a base 10 number: "); scanf("%d", &number); printf("\nThat number will not be converted to base 8\n"); printf("\nThe number you input was: %d\n", number); for(count = 0; count <=2; ++count) { random = number%8; array[count] = random; number = (number-random)/8; } printf("\nThat number in base 8 is: "); for(count = 2; count >=0; --count) { printf("%d", array[count]); } printf("\n"); } return (0); } This code can successfully convert from base 8 to base 10. When it comes to converting from base 10 to base 8 however, there is no check to take into account that the numbers 8 and 9 don't exist in base 8, (they have to carry over). This is something that will have to be incorporated. Perhaps as a second experiment it would be good to do that, with some more menu options and invalid input coding added in. ===Analysis=== My hypothesis was mostly correct. The program mostly works. It still needs some safety nets built into it, however. ===Conclusions=== I know the language better. One major thing that I didn't realize was that when you input a number, you have to input it by reference (denoted by an &) if you wish to make changes to that number as the program progresses. ====Directory navigation==== ===Question=== I know that I can change directory from one end of the file system tree to the other by stating my destination as the entire file tree starting from the root. Can I do it if I only do part of the entire file tree that I wish to get to? ===Resources=== No resources consulted. ===Hypothesis=== I don't think it will work, but if UNIX has some sort of measure in place then I wouldn't be surprised by that. I don't think it will work because if you don't specify the entire file tree starting from the root, then UNIX wouldn't know for sure what you're talking about. ===Experiment=== I'm going to try to change from two different directories, first by using the file tree from the root, and then by using only part of it. ===Data=== lab46:/$ cd home/smalik2/src/cprog/Projects lab46:~/src/cprog/Projects$ cd / lab46:/$ cd src/cprog/Projects -bash: cd: src/cprog/Projects: No such file or directory lab46:/$ ===Analysis=== My hypothesis was correct, and applicable. ===Conclusions=== If you want to change directories more then one level at a time, you have to start by specifying the file system from the root (or starting from your current location). ====Change base 10 to base 8==== ===Question=== I am trying to figure out what is wrong with the code for experiment 1, where it will randomly return an incorrect value for a base 10 to base 8 conversion. ===Resources=== No other resources were consulted, other than the ones from Experiment 1. ===Hypothesis=== I think it's a problem with carrying over a digit, because going from base ten to base 8, base 8 requires more symbols to represent the same number as in base 10, so I may need an additional placeholder. ===Experiment=== Try to see if I can incorporate some logic to carry over a 1. ===Data=== ==New and improved code for Algorithm program== #include #include #include int main() { int number = 0; int array[4]; int count = 0; int random = 0; int result = 0; int choice; printf("This program will convert any three digit number to a different base\n"); printf("For base 8 to base 10, press 1\n"); printf("For base 10 to base 8, press 2\n"); scanf("%d", &choice); if(choice == 1) { printf("\nEnter a base 8, three digit number :"); scanf("%d", &number); printf("\nThat number will now be converted to base 10\n"); printf("\nThe number you input was: %d\n", number); for(count = 0; count <=2; ++count) { random = number%10; array[count] = random; number = (number-random)/10; } for(count = 2; count >=0; --count) { result = result + array[count]*(pow(8, count)); } printf("\nThat number in base 10 is %d\n", result); } if(choice == 2) { printf("Enter a base 10 number: "); scanf("%d", &number); printf("\nThat number will not be converted to base 8\n"); printf("\nThe number you input was: %d\n", number); for(count = 0; count <=2; ++count) { random = number%8; array[count] = random; number = (number-random)/8; } array[3] = number; printf("\nThat number in base 8 is: "); for(count = 3; count >=0; --count) { printf("%d", array[count]); } printf("\n"); } return (0); } ==Program running== The problem from experiment one was that with larger numbers, the program wouldn't work. It could convert 511 to 777, but fail to convert 777 to 1411. Now it does. lab46:~/src/cprog/MessingAround$ ./Algorithm This program will convert any three digit number to a different base For base 8 to base 10, press 1 For base 10 to base 8, press 2 2 Enter a base 10 number: 777 That number will not be converted to base 8 The number you input was: 777 That number in base 8 is: 1411 ===Analysis=== My hypothesis was correct. It wasn't necessarily a need to carry over a one, as the number%8 always returned a value between 0 and 7 (inclusive). However, if the final number that I end with is a 1, then that means I need a 1 in the thousands place. Which was a very easy fix. ===Conclusions=== This experiment was very good at developing troubleshooting, and forcing me to think on a very logical level.