The brutal winter continues in my area, with no end in site! I saved weather data collected for 31 days from December to January in a CSV file. This file was used in last month’s Exercise. For this month’s Exercise, your job is to read the same data file, but also to report on the results.
Continue reading
Category Archives: Exercise
The CSV File
Of all the common file formats, the CSV is probably the oldest one still in use. It’s a plain text file, so the formatted data appears is readable by humans: Each line is a record. Each field is separated by a single comma.
Continue reading
Find the Error: Pointers, Structures, and Files
This month’s Exercise was originally how to create a structure pointer, fill it with data, and write that data to a file. It’s a procedure fraught with traps and peril. What’s even more challenging is when you’re presented with this type of code and it doesn’t work, but it’s your job to fix it.
Continue reading
Ranking Scores
In your fancy, new game, the program dutifully track players and their scores. When the game is over, or at the end of a round, the players not only want to know their scores, but where each sits in the overall ranking. That process takes a bit more coding than just spitting out the scores.
Continue reading
When You Need a Function
I believe two reasons exist for creating functions. The first is repetition; when you have a chunk of code that duplicates several times, it’s best to shove it off into a function where it can be called repeatedly. The second reason is readability.
Continue reading
The Curse of Typecasting
In the C language, it’s called typecasting: A variable of one type — for an instant — masquerades as another variable type. In Hollywood, however, it’s a curse: The typecast actor can play roles other than the one he’s famous for creating. That sucks.
Continue reading
Take Your Turn
The game of Tic-Tac-Toe, also called Noughts and Crosses, provides a fertile field to plow for any budding programmer. It involves a matrix (array), logic, decisions, and all sorts of fun. If you haven’t yet coded your own Tic-Tac-Toe game, I urge you to do so, but that’s not the topic for this month’s Exercise.
Continue reading
Your Card is Valid
When you type a credit card number on a website, or scan the card into a physical device, a quick calculation is performed to ensure that the card number is valid. This check happens before the bank is contacted to verify the account and the amount. The technique used to perform the quick calculation is known as the MOD 10 algorithm.
Continue reading
Tally the Digits
The programming adventure is full of interesting twists and turns, and with each new puzzle comes multiple opportunities to flex your coding skills and devise new solutions. For this month’s Exercise, the task is to take an integer value and add up all its digits. The mathematical term for this operation is a digit sum.
Continue reading
Find the Best Size Container
Not everything in the real world appreciates the holy computer numbers. These are binary values that parallel the powers of 2: 1, 2, 4, 8, 16, 32, 64, and so on.
A common computer puzzle is how to allocate storage specific to those holy numbers, especially when the sizes of items that you’re working with don’t exactly line up to a specific holy computer number.
Continue reading