Monday, October 30, 2006

When UMBC assigns a CompSci project, God squashes an Angel.

Before every CompSci project, we're required to hand in a design. It's due a week before the due date. Now, I'll be the first to admit that I hate this class. And I just found out that because I don't meet certain prerequisites, I may not be allowed to receive credit for the class.

Project 3 is to have a program that looks at a text file, counts out how many of each character occur, and then determines (by data given to it) which language it is. This is my "design" for that project.


/* So, I have to come up with a design for project 3, huh? (cue impressive trumpet music) This sounds like a job for Someone Who Isn't Me!

In all seriousness, though, seriousness is a funny word.

No, no, no, seriously, though, I have actually given the design for project 3 some thought. Really. For really reals.

Like all good things, it starts with a monkey. Function. Shit, did I say monkey? 'Cause I totally meant to say function. Really. Function. Anyways. It starts with main. And main will do some stuff. 'Cause that's why main is there. To, y'know, do stuff.

Right now, it doesn't do anything of any value, but it will be totally awesome. I mean, seriously. Like, for reals. Once I get it working. And, don't get me wrong, I know that's not exactly a ringing endorsement, seeing as how neither of the last two projects actually compiled.

Nonetheless, this'll be awesome.

Or, at least, it would be, if I didn't suck so bad at this.


Okay, wait, now, hang on, I know I was talking about something important before the self-loathing kicked in. Now what was it...

Oh, yeah, that's right. I was talking about how awesome main() is going to be. It's going to totally kick all the other functions' asses.

...And now that I think about that, I don't even know if that's theoretically possible, but it sounds really, really cool. So... um... yeah. I'm just going to run with it, even if it doesn't actually make any sense.

At any rate, the first thing that main() will do, as reigning champion of all the other functions, is make a call to another function called PrintHappyGreeting(). I don't think I need to go into any kind of detail about what a function with a name like "PrintHappyGreeting" does. I'm thinking you can figure that one out.

Next, main() asks the user which of the five pamphlets he wants to read.

Oh, and just so we're clear, I already know which pamphlet is in which language. Oh yeah, that's right. I'm on to you. You thought you'd make it hard by making pamphlet5.txt the English one, huh? That's it, isn't it? And then the first one is in Spanish. Try and trip us up, is that it? And then have the Italian one, and then you'd think the French one would be next; that'd make sense, keep the Romance languages together, right? But noooooooooooo. You had to go and put the German one in the middle. Totally mess up the order.

And then, ummm...

Okay, yeah, I really don't know where I'm going with this one. Sorry.

...What was I talking about, anayway? I mean, before I started rambling on about the pamphlets and the languages and the other things and the --

I remember now! I was talking about waffles!

No, no, seriously, though, I was talking about main(), and it's how it's going to be so totally awesome. And it's just going to be like, "Okay, user, so, there's five different pamphlets I can play with. It's your choice entirely." And then the user will be like, "Holy crap! That's awesome! I get to choose! And not only do I get to choose, but I still retain total control of the keyboard! This is sooo fucking awesome!!!!!"

main() will do this with a series of if statements, that will call the proper fuction. I'll talk about those functions in just a second. However, this is important. I am aware that a series of if statements -- y'know, like, one after another after another -- may seem sorta superflous when I could just use a switch statement. I mean, I bet you just sitting there now, asking yourself, "why doesn't she just use a switch statement?" Well, that question actually has a very simple answer:

Because I have never actually gotten a switch statement to work.

So, I'm going to do it differently this time, and have project 3 actually work, for a change.

At this point, I've probably distracted you from the functions that my not-so-spiffy series of if statements will call. There are five of them, they all serve the same basic fundimental principle, and they have fairly straightforward names: Pamphl1(), Pamphl2(), Pamphl3(), Pamphl4(), and Pamphl5().

In essence, these five functions are all virtually identical to each other. They use fopen() and fscanf() to call their respective pamphlets.

It works out quite nicely, really.

Depending on which pamphlet the user chooses, it goes to the corresponding Pamphl_() function, which then reads the contents of the text file into a string.

This is useful, because we will need to access it later, but slightly annoying, because there is the distinct posibility that a cat may try to eat the string, thus destroying the data and causing a memory leak.

No, no, wait. I take that back. It only causes a memory leak if the cat leaves claw marks in the string.

Anyways, so, the string then passes through another fuction, that will count each letter.

The problem, though, is that the string gets passed my pointers.

And we all know that it's awfully, terribly rude to point. That's why, generally, it's more polite to pass by value, but, sometimes, it just can't be avoided, and you just have to be rude. Sometimes, though, you just have to point.

*/

No comments: