User Tools

Site Tools


opus:spring2014:acrowle1:journal

C/C++ Programming Journal

January 24, 2014

My first lab experience was a great one, although I admit I felt a bit intimidated using a LINUX based OS rather than a Windows one. That will be a challenging hurdle to overcome, in that I am a creature of habit and very much reliant on using my mouse to point, click, drag, save, etc.

I must say that I am feeling more concerned at this point about the repositories, more so than learning a new computer program language. The Bitbucket repository thing is a little confusing, as is the TortoiseHg Workbench. I am trying to calm my nerves knowing that it's been only one week.

January 30, 2014

In this lab we discussed data types, more specifically, character data types. For character data types, there are signed and unsigned, meaning that signed encompasses both positive and negative values, and an unsigned data type includes only positive values. Since a computer stores only numeric code, characters such as A or b, have a unique numeric code to represent the character. Character data types are usually selected when invoking a logical approach to obtaining a solution rather than a math approach. We discussed in detail about binary, octal, decimal, and hexadecimal. I must say that I have a lot of work to do to understand the hexadecimal concept as far as computers go. I was a little lost.

Frustrations: I have written, compiled, and executed my code. However, I don't know what any of it means really. I have spent a lot of time on this but I am struggling to understand it, let alone write a report about it. Please tell me that this is the hardest thing I will struggle with this semester!

Outcomes: After some considerable effort, I did in fact, overcome the learning hurdles to complete the project and learned quite a bit in the process. I finally wrote my program and obtained the expected results! Whew!!!

February 13, 2014

In this lab we discussed the use of the manual (man 3 —) to obtain program info. This was both useful AND convenient to use for looking up a specific item using /whatever I want to check out, and typing 'n' for next match, 'N' for previous match.

We went over in some detail that computers are good for choices, decisions (selections). This was a Segway into conditions: if statements, else if, and else.

We also discussed the next project, Squares, using a mental math technique. I was surprised at how clever the premise of these techniques are, how easily an answer is derived without a calculator or working it out on paper! Actually, I am a little dismayed that in all the Math and Physics (I am a Math Science major and I work in a research facility) that not one of my professors have shared these techniques! With this project we will encounter if and else statements to compile and execute the code.

February 20, 2014

This lab session was a tad bit intimidating as we discussed for loops and switch statements. We worked the code out on paper prior to compiling the good. This was helpful in that it forced us to consider what things such as srand are, how the mod operator % works, etc to understand what the code is doing. It also gave us a little more practice and exposure with conditional statements such as if, else if, and else. We also looked at using a switch statement using case and breaks.

February 27, 2014

In this lab we discussed arrays, single dimensional Character arrays and single dimensional arrays and memory. We covered the fact that if you enter a string: A1b, that using strlen will get the length of the string including '\n' and the null terminator, '\0'. For example, an array:

  • input[0]: 'A'
  • input[1]: '1'
  • input[2]: 'b'
  • input[3]: '\n'
  • input[4]: '\0'

If input[3]=7 is declared, the equivalent way to represent the same expression is *(input+3)=7. The latter is the more accepted method or the more accurate way to represent it, however the compiler will accept the former, input[3]=7.

Additionally, we talked about fgets and the fact that it is “like” scanf but NOT token limited and it can tolerate spaces/whitespace.

As far as projects, we discussed the upcoming project, Nikhilam. This is another mental math assignment, the premise: all from 9 last from 10. We went through a few subtraction problems as well as some multiplication problems. I must admit, I am enjoying this bit. I guess the fact that I make a habit of taking the 'hard' approach in programming, is really just that it's just always been instilled. Though being a creature of habit, it's a hard habit to break of.

March 6, 2014

Today we discussed the Multiply By 11 project as there were questions about it, particularly since this is the first program we were asked to use command line arguments. I am only just about to begin the Nikhalim project (I know, I'm behind), so I am not quite there yet. However, it will hopefully all make perfect sense to me when I get there.

Loops

While: a top driven loop (happens zero or more times ) This basically states that while this condition is true, do this.

do while: a bottom driven loop (happens one or more times) This basically says do this, then while(condition).

Next, we disused adding or calling another function. In our example, int square(int value). Pretty straight forward until I try to do it, I'm sure!

March 13, 2014

In this lab we discussed the next project, Vertically and Crosswise Multiplication. This technique addresses multiplication problems in general, not just the special cases of squares ending in 5, or multiplication by 11.

Furthermore, we discussed in some detail, how to get started with a hex editor. This is still a bit illusive to me but I will play with the implementation of building a table first and then populate it with reading in a file.

March 20, 2014

In this lab we spent some time discussing the vertically and crosswise project, more specifically writing loops to determine carries (the factor, or number of times a number is divisible by 10 for example). This was helpful because we determined we could use either for loops or while loops to accomplish the same task. Additionally, we reviewed arrays and we wrote a simple program to demonstrate an array of 8 elements and a for loop, prompting the user to enter a test score and then added additional variables total and sum, used to calculate and output an average score.

It's all starting to make sense. Of course, seems to make perfect sense while we review the concepts in lab, but then when I attempt to implement into my own code, I become confused.

March 27, 2014

In this lab we started out discussing arrays and structs. Both are, in simple terms, containers. We then moved on to look at code that included the graphics design library. First we looked at a triangle. To view the image, it must be opened in a web browser. Being that we were logged into lab46, http://www/~acrowle1/triangle1.png. To understand GD color definitions, it should be noted that (0,0) is the top left. The positive x is to the right and positive y goes from top to bottom. gd_ImageCreate is 8 bit, while gd_ImageCreateTrueColor is more than 256 bits. One of our objectives was to look at another program, circle2.c, and change the pacman from white to yellow. Below is the image of the modified image. http://lab46.corning-cc.edu/~acrowle1/circle2.png To obtain this, yellow was added and defined under the color definitions as color[YELLOW] = gdImageColorAllocate(img, 0xFF, 0xFF, 0x00);

April 10, 2014

Today we wrote our first C++ programs. We started quite simply with “Hello World!” The timing of this lab was perfect as we had started to discuss C++ in lecture with Joe. While C is a powerful language, C++ adds the object-oriented programming capability to C. There are two main concepts associated with C:

  • Encapsulation:
    • Class-Variables, functions
  • Inheritence:
    • Member of a class

To better explain these elements, the “Hello World!” code is shown below.

#include<cstdio> #include<iostream>

int main() {

      //printf("Hello, World!\n");
      std::cout<< "Hello, World!"<< std::endl; //this is equivalent to printf$
      return(0);

}

Note that '.h' is not required to append the header files included for the C++ program. Also, notice that std is a class, and cout a member function of std class. In C++, rather than using scanf(“%d”, &a), you may simply use cin»a to get input.

April 17, 2014

Today we discussed the final. I'd be lying if I told you I wasn't freaking out a little bit. I am quite comfortable using math to obtain solutions for problem solving but not so comfortable using logic, pointers, arrays, etc. I wish I had an entire semester to spend on that material to feel more confident in my ability to write code that worked and made perfect sense to me! I have yet to get my 'multby11.c' code working. I can't seem to get past the fact that the data type is char and in order to make the code work appropriately, the string or array needs to be manipulated.

Moving on…. We discussed 'Inheritance' as we continued learning more about C++ programming. Quite simply, this reiterates that idea of a parent class and sub-classes that belong to the parent class, where certain behaviors or features are inherited from the parent, NOT the other way around. A parent cannot inherit from a child or sub-class.

April 24, 2014

Today we all worked on our final projects independently. With some help as needed. For me, I was still trying to catch up and figure out how to make the multby11 program work…and really, figure out how and where to begin. This project is torture to me because of the whole array/pointer requirement and the command line arguments. Hoping this will be mostly finished by this Thursday so I can work on other stuff for the final. Nerves!!

I also worked more on my sprite that I hadn't yet completed. I decided to try to make a Star Wars Yoda character since my husband and oldest son, 4, are the biggest fans of all the movies, including the animated series, The Clone Wars. While it looks rather blocky, it does look like Yoda. Below is the link to open it. http://lab46.corning-cc.edu/~acrowle1/yoda.png

opus/spring2014/acrowle1/journal.txt · Last modified: 2014/04/27 15:39 by acrowle1