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.
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
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.
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]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
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]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
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.
no subject
From:Good luck on your textbook struggles!
(- reply to this
- thread
- link
)
no subject
From: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.
(- reply to this
- parent
- top thread
- link
)
no subject
From: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.
(- reply to this
- link
)
no subject
From:(- reply to this
- thread
- link
)
no subject
From:(- reply to this
- parent
- thread
- top thread
- link
)
no subject
From:(- reply to this
- parent
- top thread
- link
)