Sunday, March 30th, 2008 03:59 pm

boring C++ stuff

This has been a long week; I haven't read anything, work was bad and going to get worse (if I vanish for a week, that's where I am; arguing that, yes, the drop down on Page X is not working, really, promise, look at the fucking screencaps), and my program for class is officially late. I can afford the loss of five points (from twenty), but I don't like risking that. I also don't like the program very much. It works, but--it's not--aesthetically pleasing.

Mea culpa. I've been working on that pretty much every free minute, trying to make it work. I hate the repetition over and over reading an array, but there's no way to move it to a function and just feed in what I need read, and believe me, I tried. [livejournal.com profile] adannu tried. We just couldn't make it work. So it's not pretty and minimal and it has repeating for statements and I hate looking at it. It does follow the directions in word and spirit, but--right. No.

It's the same thing that's happening with the OTW Rails blog project--I did it correctly, but I can't just walk away to the next project. I can't--it's not quite perfect; I found a space recently when I was finally going to pry myself away and completely freaked out. Crashed my laptop with ten separate pages in Apana open trying to find how I'd put an entire line of space in.

...it's not even an unsightly space. It's just that I didn't put it in by my own will, and by God, it's not staying. Unless I want to put it back after I find out what unholy class I called that did that. Then it's okay.

The Darkness of Arrays and Classes (with beloved [livejournal.com profile] adannu gently keeping me sane)

One long weekend and finally wrestled two dimensional and one dimensional arrays into compliance. I glanced at three dimensional, but I couldn't think of a practical reason for them. Not yet anyway. I need to think more. The only thing i could think of was creating the Road Coloring problem in it, which is a.) useless and b.) I don't want to have a breakdown writing it.

Coordinates. Coordinates. Coordinates. Coordinates.

So. Arrays and Classes.

I took apart the Rock, Paper, Scissors one I wrote last semester and turned everything into a function that repeated more than once to work on my understanding of functions. It was fairly easy to use that one, since the program was all very simple, if very long and confusingly repetitious. Transferred everything to single and two dimensional arrays, which really helped cement the idea of array = address, then rewrote the play program to reduce it to basically two functions of a couple of lines each (three or four), which two dimensional arrays are fabulous for. The bulk is the cout statements at this point. Once that ran correctly (and a lot less confusing--I will say this, functions are freaking *clarifying* in what does what--I decided to try and turn it into classes.

Yeah.

I did it, but I'm not sure of what the point is. Blueprint, Volkswagon, whatever--I can't quite grasp how to organize classes. I ended up creating two--one for anything that required a char answer (y or n), and one for gameplay and all integers.



Arrays

The first two dimensional array (gameType) was a string array, for "He wins", "You win" and "Tie", matched with a parallel (sort of) single array (gameName) for "Rock", "Paper", and "Scissors"--basically, all display. I wrote out the pseudocode first and realized I couldn't have scoring using those. The second two dimensional (gameValue) was a set of numbers parallel (sort of) to a one dimensional array (gameScore) that actually stored the scores(0 = total games played, 1 = your score, 2 = his score, 3 = tie games).

That shortened *everything*. myHand was created to get the user's choice of 1 (rock), 2 (paper), or 3 (scissors). hisHand is the random number generator's choice.

It also worked really well in not having to mix my strings and integers together in the same function.

Playing

cout << gameName[myHand] << " versus " << gameName[hisHand] << endl;
cout << gameType[myHand][hisHand] << endl;

Scoring

gameScore[gameValue[myHand][hisHand]] = gameScore[gameValue[myHand][hisHand]] + 1;
gameScore[0] = gameScore[0] + 1;

I know how it works. I do. But I have to re-read it every time, because I didn't expect being able to use a two dimensional array value to subscript a one dimensional array to point to where the value will go. Just writing that gives me a headache.

Functions

So easy it hurts. I can't believe I used to find this hard.

Classes

That was--weird. It still is. There are two, Display (char value functions and display only functions) and Play (integer functions). It was basically taking all my functions and moving them into classes.

Pro: no variable name alias change. At least, not that I've needed so far.

Cons: initializing an array from a class is more complicated than I thought, as in, I had to create a member function to do it and it fucked up accumulating total scores.

That was a problem. My original hope was that I could move all variables into the classes and leave main for objects only. That epically didn't work on this version. It almost worked, except the damned accumulator array.

I'm still not sure of the point, to be honest. My functions are now all in classes. I've reduced main() to 23 lines (not including spaces and comments, since I format for my own readability, which means I put space everywhere. But--I have no idea how to organize this. By theme? By concept? By usability by another program? It's irritating I can create them, but not figure out what they're supposed to do.

(Also, our professor gave us an example. There is no hell like that example. It's like advanced level C++ and I can't even read the .h files to save my life. The cpp file was utterly bewildering on its own. Plus, they also involve inheritance and are in three h files as well as a cpp, and I stopped even trying to follow the logic. Seriously, I have no idea what he was thinking. I found a neat char validation class program in the book I like a lot more. It uses the format we just used and makes sense. It also shows what it looks like in the cpp and how it looks in h, which helped make the jump, since his program did not do this.

So, for the future:

1.) Add in a file read/write to save names and scores. Yes. I'm sure that will work out brilliantly.

2.) Add in class for cheats. Now this makes sense to me--put all my cheats in a single class. That way I can keep them from affecting the rest of the program and how it runs.

3.) Use this for pointer work, since I've read the section on pointers five times and still don't understand. Teh book says, this is very hard to grasp. Oh let me count the fucking ways. I do like they don't ever bother to start showing the effects with very simple programs and slowly moving up in complexity. I--how is tht a good idea? Every time, it's an accounting business where they combine with multiple arrays and five kinds of variables and six loops and setprecision and fix it to death. Seriously. Stop that shit. Show on something simple where that is the only thing that's unfamiliar.

Seriously Diebin -- become a professor and write a textbook. It blows my mind how bad the examples are. I'm using my first semester C++ book to grasp the content on a minimal level most of the time, and the old book doesn't cover pointers.

Not panicking. I'm guessing Rock, Paper, Scissors is my new standard program for working out new concepts.

From: [identity profile] mary-alice.livejournal.com Date: 2008-03-31 12:38 am (UTC)
Really, pointers aren't all that complicated -- they're just addresses. (As in: "go to the nth entry in this array".) The notation is what always tripped me up. (My beginning C++ programming debugging mantra: "just throw ampersands and asterisks in until it works". Sigh.)

Good luck on your textbook struggles!

From: [identity profile] seperis.livejournal.com Date: 2008-03-31 01:08 am (UTC)
*grins* I did that with the ampersands. Every variable in functions I ask "Do I want this changed? Yes or no?" That's basically the entirety of my philsophy.

I'm still blinking at constructors and destructors. I really need to add those first and see how they work. And figure out which functions can be private and which public as well now that it's working with all public and no class variables. It's--something. I'm not sure what. The example programs are so huge and unfamiliar that figuring out what they do line per line takes most of the time I use studying--adding in the new stuff just boggles.

*stares at book* I really want C++ for dummies. They have to have better explanations. Gah.
ext_3058: (Default)

From: [identity profile] deadlychameleon.livejournal.com Date: 2008-03-31 03:39 am (UTC)
Pointers are largely regarded to be the worst thing about C/C++. That and it's annoying tendency to produce segmentation faults.

http://en.wikipedia.org/wiki/Pointer_(computing)#C_pointers

I don't know if that helps. It's not actually as hard as it looks.

From: [identity profile] thepouncer.livejournal.com Date: 2008-03-31 10:05 pm (UTC)
Hey you. Totally unrelated to this post, but I just had a friend ask about my roomies situation at Con.txt and wanted to confirm that you and Madelyn and, er, I forget her name, are definitely in with me? That's the assumption I'm working from, but I hadn't heard anything back from you guys and so thought I'd check *g*

From: [identity profile] seperis.livejournal.com Date: 2008-04-01 02:09 am (UTC)
Yes! Definitely!

From: [identity profile] thepouncer.livejournal.com Date: 2008-04-01 02:11 am (UTC)
\o/

Profile

seperis: (Default)
seperis

Tags

Quotes

  • If you don't send me feedback, I will sob uncontrollably for hours on end, until finally, in a fit of depression, I slash my wrists and bleed out on the bathroom floor. My death will be on your heads. Murderers
    . -- Unknown, on feedback
    BTS List
  • That's why he goes bad, you know -- all the good people hit him on the head or try to shoot him and constantly mistrust him, while there's this vast cohort of minions saying, We wouldn't hurt you, Lex, and we'll give you power and greatness and oh so much sex...
    Wow. That was scary. Lex is like Jesus in the desert.
    -- pricklyelf, on why Lex goes bad
    LJ
  • Obi-Wan has a sort of desperate, pathetic patience in this movie. You can just see it in his eyes: "My padawan is a psychopath, and no one will believe me; I'm barely keeping him under control and expect to wake up any night now to find him standing over my bed with a knife!"
    -- Teague, reviewing "Star Wars: Attack of the Clones"
    LJ
  • Beth: god, why do i have so many beads?
    Jenn: Because you are an addict.
    Jenn: There are twelve step programs for this.
    Beth: i dunno they'd work, might have to go straight for the electroshock.
    Jenn: I'm not sure that helps with bead addiction.
    Beth: i was thinking more to demagnitize my credit card.
    -- hwmitzy and seperis, on bead addiction
    AIM, 12/24/2003
  • I could rape a goat and it will DIE PRETTIER than they write.
    -- anonymous, on terrible writing
    AIM, 2/17/2004
  • In medical billing there is a diagnosis code for someone who commits suicide by sea anenemoe.
    -- silverkyst, on wtf
    AIM, 3/25/2004
  • Anonymous: sorry. i just wanted to tell you how much i liked you. i'd like to take this to a higher level if you're willing
    Eleveninches: By higher level I hope you mean email.
    -- eleveninches and anonymous, on things that are disturbing
    LJ, 4/2/2004
  • silverkyst: I need to not be taking molecular genetics.
    silverkyst: though, as a sidenote, I did learn how to eviscerate a fruit fly larvae by pulling it's mouth out by it's mouthparts today.
    silverkyst: I'm just nowhere near competent in the subject material to be taking it.
    Jenn: I'd like to thank you for that image.
    -- silverkyst and seperis, on more wtf
    AIM, 1/25/2005
  • You know, if obi-wan had just disciplined the boy *properly* we wouldn't be having these problems. Can't you just see yoda? "Take him in hand, you must. The true Force, you must show him."
    -- Issaro, on spanking Anakin in his formative years
    LJ, 3/15/2005
  • Aside from the fact that one person should never go near another with a penis, a bottle of body wash, and a hopeful expression...
    -- Summerfling, on shower sex
    LJ, 7/22/2005
  • It's weird, after you get used to the affection you get from a rabbit, it's like any other BDSM relationship. Only without the sex and hot chicks in leather corsets wielding floggers. You'll grow to like it.
    -- revelininsanity, on my relationship with my rabbit
    LJ, 2/7/2006
  • Smudged upon the near horizon, lapine shadows in the mist. Like a doomsday vision from Watership Down, the bunny intervention approaches.
    -- cpt_untouchable, on my addition of The Fourth Bunny
    LJ, 4/13/2006
  • Rule 3. Chemistry is kind of like bondage. Some people like it, some people like reading about or watching other people doing it, and a large number of people's reaction to actually doing the serious stuff is to recoil in horror.
    -- deadlychameleon, on class
    LJ, 9/1/2007
  • If imitation is the sincerest form of flattery, then Fan Fiction is John Cusack standing outside your house with a boombox.
    -- JRDSkinner, on fanfiction
    Twitter
  • I will unashamedly and unapologetically celebrate the joy and the warmth and the creativity of a community of people sharing something positive and beautiful and connective and if you don’t like it you are most welcome to very fuck off.
    -- Michael Sheen, on Good Omens fanfic
    Twitter
    , 6/19/2019
  • Adding for Mastodon.
    -- Jenn, traceback
    Fosstodon
    , 11/6/2022

Credit

November 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 2022
Page generated Apr. 23rd, 2025 09:19 am
Powered by Dreamwidth Studios