Thursday, March 26, 2009

Introduction to Programming :: Input/Output

In order for the following text to be legible, a screen shot had to be taken to ensure that example code would not be deleted when posted. Sorry for any inconvenience. Click on the images to enlarge them.




Thursday, March 19, 2009

Introduction to Programming :: Multidimensional Arrays

In the last post arrays were discussed and implemented. The next step to arrays is multidimensional arrays. Multidimentsional arrays can be as large as needed but they do use up more and more memory depending on the number of dimensions. Declaring multidimensional arrays is similar to what was previously discussed. A bidimensional array is declared as follows: int newArray [2] [4]; In order to reference a location, specify the name of the array and the locations as follows: newArray [1] [2]; . This may be hard to visualize but what this means is [row] [column]. By calling newArray[1][2]; the user is trying to reference row 1, column 2. Row 1 column 2 yields a value of 4. Remember that declaring a variable such as int newArray [2] [4]; is defining the dimensions of the array. If a reference to the location newArray[2] [4] was made; the program would not work. The correct way is to reference newArray [1] [3] instead.



The following code will fill the table above. This is controlled by two for loops. The first loop controls which row is being filled. The second for loop is computing inside the first loop in order to increment a counter and fill the columns in the row. Example: first row is filed 1,2,3,4; second row is filled 2,4,6,8.

Tuesday, March 17, 2009

Introduction to Programming :: Arrays

Cplusplus.com defines an array as: "An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier."

In order to intialize an array you simply declare it as follows: int newArray [10]; (type name [ size ];) This creates an array of integers and declares the name and size. There are many ways to fill an array. An example would be int newArray [3] = { 1, 2, 3,}. Arrays can consist of any data type and can also include records, meaning multiple fields per item. (this will be discussed in future posts.) Array data is accessed by looking at a memory location. (newArray[2];) Assuming we have an array of integers 1,2,3 array location [2] is equal to the integer 3. The first memory location in the array is referenced by newArray[0]. The following code is an example of initializing an array and using a for loop to print out the values of the entire array.




In the next post expect to see more about arrays and multidimensional arrays.

Wednesday, March 11, 2009

High School Programming, Good or Bad?

I recently read a blog that discussed the disadvantages of high school programming. Roman Zimine's perspective on the topic was that first year college computer science students are at a disadvantage if they had previously programmed in high school. The author stated that, "those who take programming courses in high school can find themselves at a disadvantage, as they have to unlearn bad programming habits while learning a new and very different language." While there are certainly cases of poor teaching and bad habits in some schools, this does not mean that all students will have the same problem.

I took programming courses in high school and I did not find myself any worse off than students who had not had programming prior to college; in fact I had a better understanding of basic concepts such as declaring variables and standard libraries. In no way was I disadvantaged by taking high school classes. The author had based his thoughts on his CS135 class in Scheme. This was the introduction language of choice for his university. Scheme is a functional language which is often very difficult to write in. Functional program languages often require a strong background in mathematics and recursion. Scheme would obviously be difficult for a freshman to comprehend having few if any mathematics courses.

Programming in high school can give an advantage to most students. It is of course possible to have a bad instructor which may lead to poor habits but most likely students will learn the basics of programming as well as using compilers. Although I disagree with the authors position of programming is bad in high school, I do agree with him that students often choose to go into the computer science field based on their grades in high school. He said, "They may think “Well, I’m getting 75% in English, 80% in Math, and 91% in Computer Science… I guess I’ll apply to a Computer Science program!" Grades in high school can be misleading; course difficulty in high school is much easier than any college course. High school can be a great opportunity to experience programming and other computer science topics as well as preparing you for college. The best way to ensure you are getting the most out of high school programming classes is to challenge yourself and practice programming outside of the classroom.