Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, December 13, 2007

Updates

I've been pretty busy with life lately, haven't been able to pay as much attention to this kind of stuff as I would have liked.

Long story short, I took too many credits. Pretty sure I failed the math class I needed to get into the next class (no worries, there's a way around it that involves the exact same amount of work and will probably end up being easier on me).

I did give up on the long addition program after making a little more headway. Turns out that the end of line marker flipped out when the string was full, so I needed to call the skip_line function. That was all I got before giving up on it though, because the next project was much more difficult. The final project of the class was to read in an external file containing a partially completed Sudoku puzzle and solve it with algorithms.

Sounds fun, but I couldn't even read in the external file and so Me => Not turning it in. I skipped the study sessions because I wanted to get it by myself. A bad idea in retrospect and hopefully it doesn't drop my grade so low I can't move on. That would be discouraging enough to have to drop CS as a major (which doesn't leave me with a whole lot of options incidentally).

Oh well though. Somehow I don't think a 10-week course on a new (and basically first) programming language can cover enough about file i/o and multidimensional arrays (and the manipulation thereof) well enough to solve this problem. The study guides I skipped out on were provided by a student who probably wasn't new to programming (or Ada) so I am confident that without his help at least 50% of the class is with me. Still kicking myself for skipping, but oh well.

Next quarter will be much more focused for me: one math class and two CS classes (computer organization and programming II (with more Ada)). Basically this just means I won't have to write a paper all quarter. Fucking awesome.

In other news, I downloaded Visual Studio 2008 from the CS MSDN and I plan to finish my "Learn Visual C# in 24 Hours" book over Winter break. I'm only a chapter in but I can already tell that if I (God willing) stick with this, I'll learn a lot about the .NET framework and object-oriented programming. Plus it's a C derivative, which should be fun.

That's it for now, just keeping my fingers crossed for my final grades.

Sunday, November 18, 2007

Giving Up

Wow, I've really hit a wall on this one. Assignment's due tomorrow at 5 pm so unless I can get an answer from the professor or TA, I'm shit outta luck.

The assignment is called "Long Integer Addition" and the idea is to take two numbers (up to but not exceeding 30 digits) and add them together. Things to keep in mind:

-The "long integers" are not numeric data types (they are too long to be represented on 32 (or 64) bit machines). They are strings. What the fuck.
-Ada is very strongly typed, meaning casting (conversion) can't be done from integer to string. VB6's CInt and CStr will not work here.
-How do you add two values from a string literal and come up with their sum? You don't.

Well it would be nice if I could get far enough to do that, but I can't even get the basic input to go through. It'll take the first variable just fine, but freaks out when it comes to deux. Code:

Ada.Text_IO.Put(Item => "Enter a nonnegative long integer(30 digits maximum) >");
Ada.Text_IO.New_Line;
Ada.Text_IO.Get_Line(Item => X, Last => StrLenX);
Ada.Integer_Text_IO.Put(Item => StrLenX);
Ada.Text_IO.New_Line(2);
FOR Idx IN REVERSE 1 .. StrLenX LOOP
ArrayX(Idx) := X(Idx);
END LOOP;

That seems to work just fine. X is a 30-character length string and StrLenX is the length of the string. The For..Next loop at the bottom assigns the contents of the string to an array holding characters '0' through '9', the idea being that since each character will be stored as such in the string X, nothing outside that range will ever need to be represented.

A conditional would catch when the sum was over 9 and would carry the one, but I never got far enough to be concerned with that.

That first block works fine, but an identical block below it to correspond to Y variables (all declared as used obviously, the compiler would never let me get away with something stupid like that). It raises a data error when it goes to get string Y, which means that somewhere the data types are being misrepresented or mismatched through some bizarre and presently incomprehensible means.

That's all OK though, I don't know how to do this without casting the characters to integers and back.

Saturday, October 6, 2007

More Ada and Nerdery

So I had my first lab on Friday, and it turns out I'm the biggest nerd in my computer science class.

I don't have acne, I don't watch Battlestar Galactica, I don't play Halo, and I didn't know the name of the creepy laughing monster in Jabba's palace in Return of the Jedi (Salacious Crumb) until my sister told me.

But somehow it's true. I actually stayed in the lab after everyone had left, just so I could do my homework. I even came back after my next class to finish up. The TA had to remind me several times that I had finished the classwork and could leave whenever I wanted.

It was kind of an embarrassing revelation, but I had a problem I just had to figure out. And I still couldn't. Not to brag, but if I couldn't figure out how to screw around with the enumerated values and the TA didn't know how to help me, I think the rest of that class is fucked.

Right now I am working on two problems, one of which takes the colors of resistor bands (which, sadly, I have almost committed to memory) and converts them into ohms. The problem is taking three separate variables and concatenating them to become one number (e.g. 4,3, and 6 needs to become 436). This may not sound very hard, but it's kind of a daunting task*. The second needs to take a date and calculate what day of the week it will fall on, which is really just a formatting problem since we were given the linear algorithm (no loops, conditions, or arrays) to solve the problem.

God damned Ada, so picky and typesafe.

*As I typed this, I realized that if I could cast (convert) a string type to type integer/natural, I might have more luck. It won't work, but it's reassuring to know that I can come up with creative solutions that had not occurred to me.

Friday, September 28, 2007

Ada

All right, while I was sitting in class today I wrote my first Ada program on paper and compiled it when I got back to my dorm. Pretty simple (and obnoxious), but I think I've got the formatting/syntax down, at least for text I/O.

WITH Ada.Text_IO;

PROCEDURE Hello IS

Name : String(1..4);

BEGIN --Hello
Ada.Text_IO.Put(Item => "Enter your name:");
Ada.Text_IO.Get(Item => Name);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put(Item => "Hello, ");
Ada.Text_IO.Put(Item => Name);
Ada.Text_IO.Put(Item => "!");

END Hello;

This program, of course, takes a name and greets them. At least, only if the user has a four-letter name. This of course means that I'll need to dynamically allocate the contents of the array in memory.

Edit: I like how that last sentence really makes it obvious that English is not my first language. Which it is.

Tuesday, August 28, 2007

Commissioning a Symphony in C

...Kinda.

This whole week I've been trying to get into C and, surprisingly, the only problem I don't have is a lack of motivation.

First off, I can't find a compiler that will work. Fortunately I finally got a C/C++ compiler that has the I/O header I need. Unfortunately, I can't seem to get it to a) display anything for more than a fraction of a second when I use the printf() function or b) accept any kind of input with scanf() because hitting Enter exits out of the console. I could go to my dad (as I usually do when I need help with programming), but he always wants something in return, be it a nature hike, family function, or some other lame bonding experience.

The second problem I have is the textbook I'm using to learn C (which might explain the problems with compiling...) which was published right around my second birthday. It refers to ANSI C (the official C standard) as "the new way". As far as I can tell, this is the equivalent to my elementary school history texts that referred to landing on the moon as "an almost realized dream". But hey, basics are basics.

I am pretty excited to learn C though, since it would be my first "real" language (since I don't consider VB6 a real language). Hopefully this will set up the foundation for learning other languages, especially the OOP languages I'll need to learn for a CSCI degree (Ada95, C++, etc.).

I'm also hoping to do some Linux developing, particularly working on porting and recompiling applications to the Nintendo DS. My ultimate goal (unless it ends up being too hard or too much of a clusterfuck) is to get VLC running on it and stream video from a computer to the DS. Whether or not this is possible with a CLI is up in the air for the time being. It would also have to support UDP (the protocol VLC uses to stream video) which is also up in the air, but I digress.

Anyway, I'll post some source code when I finally get a functioning program (which I know you're dying to read).