#FreshmanProgrammer
Explore tagged Tumblr posts
ernest-henley · 3 years ago
Photo
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
Text Only Version:
Journal #6
Module 6: Singly Linked Lists and Doubly Linked Lists
What I’ve Learned
Perhaps the most challenging module yet for our CMSC 21 course, the linked lists are very complex yet extremely similar when compared to our previous topic about structures each with their distinct characteristics and functionalities. With the aid of the lecture videos, lab handouts, and lecture slides, supplemented by our C-sessions, I have learned how to execute basic operations, insert a data, delete a data, pass as parameters, and use both singly and double linked lists in crafting my program that requires multiple-element handling, and dynamic memory allocation during the runtime. I have also concurred how they contrast with an array of structures and use them to my advantage with regard to the task I intended to accomplish.
Drawing/Tracing a Linked Lists
At first, I attempted to devise a way in accomplishing our lab exercise without the use of any tracing or drawing as I initially find it time-consuming compared to having directly addressed the problem. But over time, I find myself lost and unable to finish my task especially after encountering multiple segmentation errors in the add playlist function. Thus, I finally brought myself to draw. After a couple of minutes of pondering and logically tracing, to my surprise, I immediately deducted that something is wrong with the memory allocation that I addressed after finding out what solved my issue. Overall, tracing is immensely beneficial in these types of cases, especially in a linked list where nodes are pointing here and there.
Do not use type-definition declaration of structure
As per the heading, using a type-definition declaration of structure when developing self-referential structures for linked lists is deeply discouraged. This is due to the fact that a type-definition declaration misses a node tag and is only comprised of a node. Hence, referencing to itself is unlikely since by the time it reached the line where it references to itself, the node utilized is still not yet defined causing an error.
Why is the head pointer important?
As we may all know, the head pointer is very important in a linked list. This is for the reason that the head pointer is the one to point towards the first node. By now, we are well aware the prior node contains the pointer to the subsequent nodes (ie. the second node contains the pointer to the third node, …) showcasing the importance of being able to access the node before it, consequently, making the head pointer the most important since it is like the root of a tree. Without the head pointer, we would not be able to access the ensuing nodes and elements we need.
Forgetting to assign NULL to an empty list and last node is a crime
It is extremely important to assign NULL to an empty list and to the last node of a list as having a NULL value is the only way to signify whether the sequential list has reached its end. Without it, the system will continue to traverse sequentially even after it reached the point where it does not contain any data or element that is of use in the program resulting in an error when you are determining its count and assignment of unknown values and unknown characters when you attempted to print it.
Are linked lists better than arrays?
Answering this question is like choosing between coffee and soft drinks for me. It is completely a matter of what task you intend to accomplish. In some cases arrays are better than linked lists, sometimes linked lists are better. Arrays are much more simple and easier to understand attested by how you can easily keep track of positions and sizes with a simple counting variable. Accessing an element is as easy as inputting its index to which multiple functions are easy to compose if ever you are in need to identify a specific index. In contrast, I find linked lists more efficient and of great assistance when you are to sort/arrange every element inserted in a specific manner. Just like how you can arrange every element being inserted alphabetically or numerically (ie. Ages, dates, ranking, etc.), very beneficial in programs that require such functionality.
Problems and how I solved them
Similar to my previous lab exercise, I have encountered multiple cases of syntax and semantic error while doing the sixth module lab exercise more than I ever did in the prior activity. I had a little drawback with the sorting mechanism I implemented to every element inputted by the user but was able to address it after a couple of experiments with the process of comparing them separately, in contrast to confining them into one. The load function is what I would deem to be the most difficult to solve, it took me from a couple of hours to a whole day of being unable to solve the issue. I saved them with ease but is quite unsuccessful in loading them properly without encountering a segmentation fault. I encountered the recurring problem (segmentation fault) numerous times, again having little to no clue of what was causing it answering the subsequent question if I have faced such a case.
Documentations
See images above.
References
Sir Koy’s Youtube channel and Facebook page:
https://www.youtube.com/channel/UCExYInunCMZ5nF0eudCBFrw
https://www.facebook.com/sirkoylapitan
About the Author
Ernest Henley L. Tabilas
CMSC 21 - ST & ST1L
Freshman Student
Contact No: 09506177177
University of the Philippines Los Baños
Follow and like our page and posts for more journals and experience as a freshman programmer!
0 notes
ernest-henley · 3 years ago
Photo
Tumblr media Tumblr media Tumblr media Tumblr media
Text Only Version:
Journal #5
Module 5: Structures and Files
What I’ve Learned
The entire course for the fifth module of our Computer Science 21 journey has taught me multiple things with regards to ‘Structures and Files’ and how they are valuable, specifically in cases where you require a certain amount of variables to handle. It makes data storing much more convenient and efficient compared to having made them one by one. I’ve learned how to define and initialize a structure, execute operations among the structure variables, pass them as parameters, utilize them in an array, etc. Likewise, the ability to save every information accumulated during the runtime of the program is extremely beneficial in various cases which are largely utilized today. I have learned how to store and load data in/from a file as the extent of our lecture videos.
-When should we use arrays?
Structure Definition
Throughout my experience of programming including structures, I found myself more often than not, to be using ‘both’ the type-definition structure with a tag and a synonym as it minimizes the amount of space and typing I have to do whenever I have to create a new variable of structure. Aside from that, it also gives me more freedom and flexibility in using whichever method of initialization I deemed would be more useful in various types of situations. Hence, it is indeed most of the time applicable in any possible instances. (See example below) (See image above in Page 2)
The inability of a structure to have an instance of itself
As per its definition, structures are unable to have an instance of themselves. This is due to the fact that aside from using a synonym that is not yet defined in certain definitions of structures, referring to a structure to itself means an endless loop or recursion will occur. It is basically impossible since in order to finish initializing a structure it will undergo a self-referential process to identify the amount of memory necessary for allocation which will continue endlessly as you may have guessed and likewise allocate an endless amount of memory for the structure.
When should you use ‘->’ and ‘.’ When accessing a structure member?
When we are accessing a particular structure member within it as is, using the dot (.) operator is the ideal method for doing so. In comparison, if we are to access the members of the structure data type of a ‘pointer’, using the arrow operator (->) is the only way to accomplish the task.
Problems and how I solved them
I have encountered multiple cases of syntax and semantic error while doing the fifth module lab exercise. The added song to a playlist function gave me a hard time inserting such in the specific playlist that the user have chosen as I initially forgot and interchanged the integer variable I used to accept the user choice and the integer variable I used in the for loop of accessing the song’s details index which results to an instance where adding a song to a particular list will also add to all other existing playlists. Hence, interchanging them once again solved my issue. Besides that, what took most of my time is saving the data in a file and loading them in the same manner and positions. Specifically in the load function as I encountered segmentation fault numerous times without any idea of what was causing it. To be honest, I did multiple tweaking to my code and once I tested it, it suddenly fixes the problem. I had little to no clue what change I did to subside the segmentation fault that I constantly faced before answering the subsequent question if I have faced such a case.
Documentations
See images above.
References
Sir Koy’s Youtube channel and Facebook page:
https://www.youtube.com/channel/UCExYInunCMZ5nF0eudCBFrw
https://www.facebook.com/sirkoylapitan
About the Author
Ernest Henley L. Tabilas
CMSC 21 - ST & ST1L
Freshman Student
Contact No: 09506177177
University of the Philippines Los Baños
Follow and like our page and posts for more journals and experience as a freshman programmer!
0 notes
ernest-henley · 3 years ago
Photo
Tumblr media Tumblr media Tumblr media
Text Only Version:
Journal #4
Module 4: Strings and Arrays
-How’s my experience?
The enormous shift in how C mandates strings and arrays in comparison to Python gave me the biggest challenge for the entire course of Module 4. As opposed to having the option to utilize built-in functions in almost any task we want to perform in Python, C requires a bit more expertise and dedication in order to accomplish our intended goal when we are to use arrays in a complex program. In simple terms, C is a bit more hands-on and component-heavy type of programming language when it comes to providing programmers with the tools necessary to construct programs more efficiently. The most important concept I’ve acquired I reckon is the utilization of multi-dimensional arrays and dynamic memory allocation both of which are essential in future endeavors, particularly when developing an interactive program where static data types will not suffice. Furthermore, I have concurred how one element stored in a single index in an array does not necessarily occupy the same amount of space (in bytes) as the others.
-Problems and how I solved them
Honestly speaking, I've encountered a number of mistakes for which I have little to no understanding of the root cause. More often than not, I have difficulties in inadvertently arriving at a code that results in a segmentation fault. Since it is a very broad and intricate error, it is very troublesome to troubleshoot and determine where and what went wrong. Aside from that, a minor issue that I immediately resolved with the help of my instructor was passing an array to another function alongside an integer as another parameter for the purpose of it serving as the discrete size of the array as they initially give me casting errors for (integer without a cast something I forgot the specific error message).
-When should we use arrays?
As per its definition, arrays are a sequence consisting of the same data type, they are most ideal to utilize when you are in need of collecting multiple variables (strictly of the same data type) compared to a single variable limited to only itself. One of the finest examples is keeping track of students' grades, listing tourist destinations, and, like in our exercise, determining whether or not user input is a palindrome.
-How are they stored in memory?
Though the specific values and amount of those completely vary depending on the programmer’s goal, they are generally stored chronologically as blocks of elements theoretically arranged in a horizontal manner as to how we generally perceive it and vertically in the RAM memory. All of the elements stored are of course of the same data type confined in a consecutive memory location even when we are to put multi-dimensional arrays in the table. They are accessed using the specific index they are stored to where the first index (0) plays an important role in passing and accessing the entirety of the array. Refer to the image above. As you may also notice, ‘\0’ is always stored at the last index as they are the ones to denote the terminating point of the array and likewise require allocated memory for itself. Thus, explaining why it is necessary to always increase the supposed sizes of the array by 1 to store the aforementioned element.
-Documentations
See images above.
-References
Sir Koy’s Youtube channel and Facebook page:
https://www.youtube.com/channel/UCExYInunCMZ5nF0eudCBFrw
https://www.facebook.com/sirkoylapitan
-About the author
Ernest Henley L. Tabilas
CMSC 21 - ST & ST1L
Freshman Student
Contact No: 09506177177
University of the Philippines Los Baños
Follow and like our page and posts for more journals and experience as a freshman programmer!
0 notes
ernest-henley · 3 years ago
Photo
Tumblr media Tumblr media Tumblr media Tumblr media
Text Only Version:
Journal #3
Module 3: Pointers and Parameter Passing
-How’s my experience?
    Halfway to the semester, we are finally examining the capacities that pointers and parameters passing bring to the table of C programming. This, by far, is the most challenging module to study. Technicalities aside, what makes it more or less confusing is determining the appropriate symbol or character to insert before the variable with accords to what purpose you want it to execute. The experience has been trouble-free for the most recent C-numan session massively assisted us in accomplishing the activity. Allowing us adequate room to make use of our problem-solving skills, creativity, and critical thinking to attain the goal of the given exercise. Repetitive studying and re-watching of lecture vids have also been quite beneficial, as proper training is essential in mastering pointers. So far, I’ve enjoyed C programming and am still left curious about the potential capabilities that the mentioned programming language has.
-What Have I learned? 
      For our third project, we are tasked to craft a program that fetches and prints the three largest prime integers in between x and y with both of them (x and y) being the user input. It is pretty similar to our prior exercise, except that it only prints the three largest ones among them, and the points of interval or range are now fully configurable by the user without it being restricted to starting with number one (1). As a result, I was able to reuse a portion of code from my previous program (The prime integers printer part) for my current exercise and minimize the problems ahead.  
    To sum up all of my learnings, I have learned the basic functions, syntax formats, and scenarios of usage of pointers as well as parameters passings. I also came to realize that it is often more preferrable to do a parameter passing of local variables in contrast to multiple global variables whenever we were to modify the values of the variables as it conserves more memory in the system and is likewise more flexible and organized compared to the latter. Generally, I am able to effectively integrate all of my module 3 learnings into our third hands-on practice during our full week of class.
-Problems and How I Solved It
    I firmly believe the most difficult part in this specific exercise was devising a way for me to print only the three largest integers instead of including all the prime integers between the interval for I, initially, am admittedly clueless on how will I be able to achieve my desired result. As a former Python enthusiast, I always prefer to use lists and arrays when dealing with such discrepancies for they are the most efficient method of doing such tasks. Unfortunately, we are yet to study arrays in C programming and are strictly restricted in using only those methods that we’ve already studied. To solve such, the first thing that came to my mind is assigning a counter to limit the max number of integers to be printed to three (3). Now I am able to print only three integers to the terminal, but still oblivious to how will the three be the largest prime integer. At the last minute, I have come to realize that all the integers are automatically sorted numerically from lowest to highest and immediately thought of reversing the loop process from highest to lowest in order to fetch the three largest integers first before anything else which thankfully solved my main problem for the exercise. I took care of other minor errors in my code and was able to complete my program after that.
-Why Pointers and When to Use Them?
    Why should pointers be used specifically in a pass-by-reference you might wonder? Well, the simple answer to that is because when we are passing a value by reference, we are not duplicating the particular argument and instead merely pass the address to be used or modified in the locality of the function where it is referenced to, to which pointers are made for such duty. Most often than not, they are ideally used in instances where we need to modify the variable/argument especially when you want to do it across the locality of various codes. Other than that, as mentioned before, it is ideal to use in conserving memory, subsequently, when confronted with altering memory-consuming arguments (large objects), pass-by-reference is the way to go.
-Conclusion
    Taking everything to account, the third module course has been seamlessly scrutinized with it providing a stepped-up challenge compared to the previous modules but at the same time opens up a variety of functionalities and potential uses for our future endeavors in programming in general. Once again, I had an exceedingly fruitful week of learning, with me being successful in attaining the goals for the program with the help of our professors and peers. I am anticipating on acquiring more practical skills and knowledge for the remainder of the semester ahead. Cheers!
-References
Sir Koy’s Youtube channel and Facebook page:
https://www.youtube.com/channel/UCExYInunCMZ5nF0eudCBFrw
https://www.facebook.com/sirkoylapitan
-About the author
Ernest Henley L. Tabilas
CMSC 21 - ST & ST1L
Freshman Student
Contact No: 09506177177
University of the Philippines Los Baños
Follow and like our page and posts for more journals and experience as a freshman programmer!
0 notes
ernest-henley · 3 years ago
Photo
Tumblr media Tumblr media Tumblr media Tumblr media
Text Only Version:
Journal #1
Module 1: Introduction to C
-How’s my experience?
   Transitioning from Python to C programming was like returning home after a ten-year length of the trip. It feels so familiar yet so different. Numerous commands are fundamentally different from python but provide similar functionality. Thus, a well-composed introduction is vital in guiding us to the journey of C programming, especially for people like me who have little to no background education with regards, particularly to C programming language. Which in this case, was excellently provided by our professors utilizing lecture handouts, tutorial videos, lecture slides, and most importantly, lab exercises like the ’BMI Calculator’ which we will be investigating more in the latter part of this journal.
-What Have I learned?
    Our initial activity is to develop a Body  Mass Index or BMI Calculator that, just like its name, calculates the BMI of  the user making use of their entered weight and height either in the form of  Kilograms (kg) and Centimeters (cm) or Pounds (lb) and Feet (ft). Utilizing  the provided materials, I was able to successfully develop it within a day  with proper effort. To summarize it all, I have learned the basics of C programming, namely the use of conditional statements, switch statements, loops, and other preliminaries like the format and organization of codes, do’s and don’ts, and numerous more essentials in C programming. Initially, I am also able to learn how to install, update, and utilize Ubuntu WSL in running our codes. Overall, I successfully applied all the knowledge we have gathered in our entire course for module 1 to our first-ever hands-on exercise.
-Problems and Difficulties?
    Of course, this does not come without encountering any single drawback. Although there are no major struggles that keep me from finishing my activity, the single thing that I consider to give me the most trouble is in the technicalities of my codes.  As I have mentioned before, we are currently in between the transition from Python to C programming language. At some point in time, I unconsciously omit mistakes in my code treating its syntax like Python instead of C. For example, in Python, you are able to directly create a conditional statement with three variables in comparison like ‘1.5 < n < 2.5’. In contrast, C requires you to create two separate conditions in the same branch with the conjunction of two ampersands ‘&&’ in between them. Thus, instead of inputting the earlier condition I have mentioned, I instead need to format it like this: ‘1.5 < n && n < 2.5’. See the image below. Aside from that, other minor struggles I have is in locating the directory of my created directory using Ubuntu.
-How did I solve it?
    The most effective method I found in solving these types of problems is going back, and repeatedly studying and keeping pointers about the foundations of C programming, especially the introductory part. Basically, learning it by heart. The recorded sessions of Professor Arian together with the playlist tutorial videos of Sir Koy massively assisted us in accomplishing our task while learning the basics of C programming. I likewise browse through the internet for some additional information that are supplementary on our current topic. With that, I was able to develop a fully functional BMI calculator complying with every given instruction and abiding towards the objectives and goals of our module 1 lab exercise.
-Conclusion
   Overall, I can say that the first given exercise serves very well its purpose of introducing us to C programming with very comprehensive use of the learning materials provided, which likewise did an excellent job in educating us regarding our current topic. I would recommend practicing this specific programming exercise for anyone that is looking forward to engaging in C programming for the very first time as it teaches us the very foundation of the more complex and structured programming language in future discussions and practices for C. I am looking forward for more in the following weeks ahead!
-References
Sir Koy’s Youtube channel and Facebook page:
https://www.youtube.com/channel/UCExYInunCMZ5nF0eudCBFrw
https://www.facebook.com/sirkoylapitan
-About the author
 Ernest Henley L. Tabilas
CMSC 21 - ST & ST1L
Freshman Student 
Contact No: 09506177177 
University of the Philippines Los Baños
Follow and like our page and posts for more journals and experience as a freshman programmer!
1 note · View note