Wednesday, July 9, 2014

It worked!

When life gives you lemons, you make lemonade. When Dancing Dan the Man gives you a second lab to do, you make a program. The challenge presented to the class was now to take the same set of pseudo-random data from the previous lab and place them into arrays. That alone was something none of us had really done before, but the lab had a second part. We were supposed to take the unsorted data placed into the array and prompt the user to selected which method (selection, bubble, or insert) of sorting would be wanted PLUS whether the user wanted just the finished array, the finished array with the beginning array, or the finished array with the beginning unsorted array and the intermediaries. This is how the program turned out. The same computer issues that plagued me during the last lab continued on. I relied on working on it with whoever was closest to me. Thankfully, this savior was once again David B. Through laughing and having a good time we had a final result. The program worked well in class. However, when testing it at the dorms I used compileonline.com. When I attempted to run it there were errors in the identical program ran in class. This took a little bit of playing around with the program but eventually a result occurred that was not error-filled.








The program starts by defining the basic libraries we were using. For this lab we needed <iostream>, <fstream>, and <string> to use input/output variables and expressions, instream/outsream files, and the string variable type, respectively. I used using namespace std; in order to use the commands in the standard library and save time. The program begins by declaring some variables and declaring a few void functions. All of these would be used well when the time came for it. I defined our array for having 80 more spots than needed just to guarantee no chaos ensued. I created the functions for all the sorting again to be defined later. The program began with the main function, where the program asked which type of sorting was requested using cout. The program continues by declaring more variables to be used for the method of displaying the array. After selection, the program imports the files using ifstream and then has a clause to break in case the data file instreamed was too large. Starting with selection sort, the program was designed to then display the initial unsorted data should that had been chosen, and proceed to sort it and post it in the manner requested. The same was done with the bubble sort and the insertion sort. Selection sort, given a list, takes the current element and exchanges it with the smallest element on the right hand side of the current element. The bubble sort, after i iterations, the last i elements are the biggest, and ordered. In each iteration, it sifts through the unsorted section to find the maximum. The insertion sort, after i iterations, the last i elements are the biggest, and ordered. In each iteration, sift through the unsorted section to find the maximum. The program outputs whatever was request using couts and cins.

This program did not come easily at all. It took a while to understand the references concept. Not only that, but we had to be shown how to begin because the entire class was incapable of finding how to begin. Once the initial ropes were laid out, it became easier to do the other sorts on our own. There were like always some semi-colon forgetting and some mistyping variables, but that was expected and quickly fixed. The challenging thing personally was that I did not expect the program to be so long and to have so many brackets. The main errors was trying to match the brackets correctly and put them in the right place. This used about an hour and a half to realize that all the errors that were being reported were from one bracket. Lesson learned. Bracket beforehand kids. Also, figuring out how many loops and where to place them was equally challenging. All in all, this lab was a great way to further showcase my acquired programming ability despite a few bumps along the way.

Computer mastery I welcome your challenges with an open mind and an open keyboard!!!

Thursday, June 26, 2014

The First Lab... and I Only Cried Twice!

The first true obstacle was the first lab presented to the class. The task at hand was taking a string of pseudo-random numbers in a file and creating a program that calculated the minimum, maximum, sum, and average. This was a task that at first glance seemed unachievable, but like the philosopher Ringo Starr once said, "I get by with a little help from my friends." This couldn't have been more true. When login errors made any function on my computer worthless, I was lucky to have David B. at the adjacent computer willing to give assistance when needed.

























I began the program by using <iostream>, <string>, and <fstream>, which allowed me to input and output not only words and variables but also files. The program did not use a string, but in order to remember to include it when needed, I placed in in anyways. "Using namespace std;" allowed us to avoid using "std::" throughout the program whenever working with data.  I streamed in the file and proceeded to define my variables. I established all of them as "float" as opposed to "double" because "float" allows for real numbers with less space taken up. Since the values were not as large size wise, using "double" for the particular set of data would not have been as efficient space wise (but for larger numbers "double" could also be used). The large numbers were defined as 0 and the "min" was defined as 99999 so that the numbers could get larger and smaller, respectively. However, the while loop was the star of the show. It's function let the data be run and adjust the min and max. The if and else if statements allowed the program to change the answers when presented with a criteria meeting number. If the following value exceeded the previous, it became the new max; on the other hand, if the value was less than the previous it became the new min. The sum was established by adding the previous term with the one following. Additionally, the variable "moo" added 1 to itself each time a new number came by (moo++). This made finding the average from the sum simple to get. The program goes to state all the values obtained whenever run: the min, the max, the sum, and the average. Equally important, to conclude the program, the data was exported to a file of its own which contained the answers as well. This was done by using ofstream and creating a new text file.

The program did not always run smoothly. After trying to run it the first time, the program shot out error messages across the program. I naively placed semi-colons where there was no need to. Thankfully, the program shot out errors and indicated the lines where the issue was. This helped to remedy the problem quicker. Near completion, the monitor also displayed each answer as it was modifying what the answer was. To further clarify, each time the program tested whether a number was larger or smaller than the previous (to find the min and max), the program spit out each answer as it went down the list of numbers. Upon further investigation, it became apparent that the key error was placing the "cout" inside of the loop; it therefore spit out the answer each time it checked a new number. The solution here was to put all the "cout"'s outside the loop.

With each corrected mistake I take an additional step forward in becoming a programming master.

The epic journey begins!

Our story starts out with a small town boy with some big town dreams. The goal: to make some programs and chronicle the adventure that will surely follow. Hold on to your keyboards as the drama presents itself.