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!!!

No comments:

Post a Comment