User Tools

Site Tools


blog:spring2016:btaylo15:start

Brian Taylor's Spring2016 Opus

C/C++ Programming

. .

\ `\~~---..---~~~~~~--.---~~| /   
 `~-.   `                   .~         _____ 
     ~.                .--~~    .---~~~    /
      / .-.      .-.      |  <~~        __/
     |  |_|      |_|       \  \     .--'
    /-.      -       .-.    |  \_   \_
    \-'   -..-..-    `-'    |    \__  \_ 
     `.                     |     _/  _/
       ~-                .,-\   _/  _/
      /                 -~~~~\ /_  /_
     |               /   |    \  \_  \_ 
     |   /          /   /      | _/  _/
     |  |          |   /    .,-|/  _/ 
     )__/           \_/    -~~~| _/
       \                      /  \
        |           |        /_---` 
        \    .______|      ./
        (   /        \    /        
        `--'          /__/

Introduction

My name is Brian Taylor, and I would consider myself a nerd. I may not be as advanced as some of my classmates, but my interests fall primarily in the field of computers and I am definitely more advanced than the average person. Music and video games are my other hobbies. I am relatively proficient at Java thanks to Joe's problem solving class and I am working on porting my Pong game to Android.

C/C++ Programming Journal


Jan 19, 2016

I remember when I wrote a research paper on Linux in freshman year of high school. Well, no time like the present to learn about the past (get it, because UNIX came before Linux). Coming from Windows command prompt, UNIX seems pretty simple once you know the commands. I've used an actual floppy-based DOS computer before, so mostly mouse-less computing doesn’t faze me. Figuring out the write command was fun. I wrote and compiled the Hello World program in C, adding in a second line to personalize it just for kicks. After figuring out the trick to multiplying by 11, I already have ideas on how to code it, I just need to learn how to do it in C. I also have ideas for making Pong, as well.

Feb 2, 2016

Having already done the 11's mental math program, the fives was not too hard. However, when splitting the input into an array, the numbers were converted to their ASCII codes. I converted them back by subtracting the ASCII equivalent of 48, “0”, but I would still like to eventually learn why and possibly correct it. I also configured my VIM settings to have line numbers, syntax coloring and enabled mouse-mode. I think I have an understanding of pointers, but I can tell I could understand it better. I still don't understand the application of them, either. I wrote a program for UDP discovery in Java, but now I want to make the receiver for Linux/UNIX machines and coded in C. I can tell it's going to be a while until I get that far, though.

Feb 8, 2016

I have enjoyed these mental math programs we have had to write, as well as C programming in general. The first day of the year calculator was fun. After finishing years 2000 to 2099, I started entering years higher than that. After examining the results, researching what I consider “leap centuries”, and tinkering with the code countless times, I created a working version that can go up to the year 57988, with the only limit I know of being the size of the array of multiples of 7, which is currently 9999. I actually had to find a website to verify my results, as the calendar program on the UNIX machines only goes to the year 9999. In retrospect, I believe this code could be adapted to finding the day of the week of any day in any year, using January 1st as the base and working from that. Anyway, I’m enjoying this class and I’m eager to see what else we do.

Feb 22, 2016

Coming into this course, we noticed the graph of the grades for last semester's class. One project in particular had the lowest overall grade. After asking about it, we learned that it was multiplying by elevens using mental math and the trick to doing it. Feeling challenged, I went ahead and coded the program in Java with arrays and loops as I knew how. Given, this was in the first couple days, so I did not yet have the knowledge to code it in C. However, within the first week or two I had it done in C, but still using loops and arrays. When we actually got to the project, we learned that loops and arrays were not allowed, but I didn’t have a hard time expanding my loops, and because of this project, I learned how to get the digits of a number without using an array.

Feb 29, 2016

This project has been the most complicated one so far. Back in Computer Essentials, we learned about how the highest levels of encryption use prime numbers, so going in to a project where people literally study this for it to be their careers was a little overwhelming at first. Starting with brute force, we all used the same algorithm, checking all numbers between 2 and a max number to see if they divide evenly by anything other than 1 and itself. If a number isn’t, then it is prime. This method is 100% effective, but very slow for high numbers. For the next iteration, the brute method can be optimized using the sqrt() function. For any prime number, you only need to check if it is divisible by numbers from 2 to the square root of the max. This greatly reduces the run time. For the final iteration, we were allowed to use algorithms or optimizations we want to try and get the best time we can. I decided to use the Sieve of Eratosthenes for my algorithm. My best time as I’m writing this is 3.355351s for the 67108864 range.

March 7, 2016

All I can say is that it is a big relief to not have to optimize every little thing in this week's program. After going a little overboard on the prime number project and winning, it feels nice to be able to take it easy on a project, but that doesn't mean I didn't do it the first day it was due. Since I did the multiply by eleven’s project like the first or second week using loops and arrays, redoing it to fit the specifications wasn’t hard. I had to change my math a bit to accommodate carries, but that wasn’t hard either after doing a binary calculator in problem solving. I made sure to accommodate the times that the final iteration has a carry, like 999 times 11. I think at this point I’m ready for the next project.

March 14, 2016

This project was pretty fun. I learned about this project early as well, so I had a plan going in to it. Probably for the first and possibly last time I will ever use math outside of a math class, I harkened back to Pre-Calc (from high school and last semester) and remembered that the X,Y coordinates of points on a circle can be found using ( radius * cos(theta) ) and ( radius * sin(theta) ). By incrementing the angle, theta, and drawing the points, you can make a circle out of squares. By drawing more circles with different radii, you can draw concentric circles. By changing the radius while drawing a circle, you can draw spirals. I also was looking into a way to have these PNG files viewable in the terminal, which led me to explore PNM’s and libcaca. The version of libcaca I had only supported BMP files, so I wrote a bash script to convert PNG’s to PNM’s, then the PNM’s to BMP’s that can be viewed. Ascii-art has always been an interest of mine, so a way to put it to use was fun.

March 22, 2016

Inputting a string and then shifting the letters to make it a secret message was a cool project to do. Loading from a file will be useful for many situations in the future. Changing how the program runs based on its compiled name was interesting. I learned about a lot of useful string functions (strtok, strlen and strcmp), and learning about function prototypes will be immensely helpful in the future. Probably the biggest help for me was the understanding of chars, that they are actually just a smaller type of integer unless called specifically using its value as an ASCII code. We had to write our own atoi function to read a number from a string from a file. For fun, I looked up how to color the output of the program, but I removed that at the end so that piping and such would work fluidly with the program. At first, I was shifting all characters with ASCII codes 32 through 126, so that symbols would work and the message was shifted using the ASCII table. However, what I needed to do was only shift letters, so I shifted uppercase letters in the uppercase range and lowercase in the lowercase range, leaving spaces and symbols alone so that the form of the message was intact.

April 4, 2016

Making a hex viewer? No problem. Coloring in the lines? Problem. By using an array to temporarily store consecutive sets of 16 bytes from a file, and using the hexadecimal format specifiers, creating a program to open a file and display its contents in hexadecimal and ASCII was easy. I used code from previous projects to open the file and fgetc its contents. The hardest part of the main project was detecting EOF at the right time. To do this, I put the section for storing the data into the temporary array first in the “for” loop, and if feof was detected, a flag was set and the position of the last character in the file was set. Then I print the offset, hex and ASCII values. Then there’s adding color. I was able to figure out how to correctly store 6 pairs of extra arguments to be used as highlighted sections, but actually implementing it was difficult. By the end, for some reason, my program only correctly highlights when 4 or fewer pairs of arguments are present, any more than that and the program displays incorrectly. It also can only do 2 highlighted sections per line, cannot wrap around lines, and the start positions of the highlights have to be in ascending order. Basically, I’m content with just a plain hex viewer.

April 13, 2016

This was a relatively easy week for me, since I did this project weeks in advance because I got bored. The project was to subtract any number from the power of ten with one more digit than the input number. You can easily do this by subtracting each number left to right by 9, then the last by 10. I got it working easily, however, upon further testing I found a very specific bug. Whenever the program did 10 – 0, it returned a 10 of course, but this means that 1000 – 100 = 8100, or 8 10 0. I fixed this by looping back through the result array and fixing the carries. Going back to mental math programs was a nice break and refresher on certain parts of code.

April 20, 2016

This week’s project was pretty fun. We used the flattenstatus command to get our grade data and then display it in a readable way. For me, my grade in this class is about a 113/100 because of all the bonus I did, so that’s nice. I learned a bit about floats for this project, since I wanted to have the option of decimals instead of truncating every number into int form, and it was necessary for dividing my accumulated points by the total possible points. This project, at least the part where you read data with what are basically headers separating the sections, reminds me of my personal project I’ve been working on, Secret Picture Messages (spm0). My program encodes 24-bit bitmaps with a secret message, and the picture looks no different to the original. Anyway, I’m already thinking about how to solve the EOCE projects and I’m excited to try my ideas.

blog/spring2016/btaylo15/start.txt · Last modified: 2016/01/18 16:05 by 127.0.0.1