Forgotten

This is a discussion on Forgotten within the C++ Programming forums, part of the General Programming Boards category; Ok, I have been doing my exams and gave up programming so that I could concentrate more...can someone give me ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    Forgotten

    Ok, I have been doing my exams and gave up programming so that I could concentrate more...can someone give me a relatively easy task for me to set out to do and get me back into the swing of things as all my inspiration has gone.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    You could try the Snake Numbers Contest.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,442
    > can someone give me a relatively easy task for me to set out to do
    Anybody's homework on this board - just to see if you can do it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Simulate a home alarm system or something fun like that. You'll be programming and setting fires. Plus it's a good OOP excercise.

    I do have one rule though: no getter and setter functions for individual members of any class. As the class is supposed to work to keep "how it works" a secret, making the programmer able to change a specific member just by calling a setter function doesn't make much sense.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Can you detail taht a bit more please?

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    No. :P Figure out what you want it to do exactly; that's what makes it an exercise.
    - Set up rooms
    - Set up alarms, and what rooms have alarms
    - Cause disasters and write a log file stating who you called about the emergency, when, and why.
    - Make it even better if you can think of anything else.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    What do you mean by the whole getter and setter functions thing?

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Oh that! Well, some people will make a class like:
    Code:
    class Foo {
        int foo_data;
    public:
        const int getfoo(void) const { return foo_data; }
        void setfoo(const int foo_in) { foo_data = foo_in; }
    };
    Anything wrong with that? Well, what is so great about the functions that makes it better than a public data member? Nothing. No programmer is so uninspired that he won't figure out that if he needs to change a member he can call set()... you've not protected foo at all.

    What is okay though is to write functions that work with the data to do something specific instead of just changing members.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    So, basically you are saying that the STL is evil, because for example with strings I can do this:
    Code:
    string a("Umm");
    string b;
    b = a;
    ... the last line being the same as b.set(a) ?

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    No I'm not saying that, and that is not what happened in your code. In your code, string b is a copy of string a. Both strings still exist. You did not overwrite string a.

    Though I think you are talking about reinitialization.
    Code:
        string a("hello world");
        a = "goodbye cruel world";
    Reinitialization is not as bad when you use it intelligently, but this is different from being able to set some variable to fail and breaking a class on purpose, like get/set functions do.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    No, citizen's point is that the use of setter/getter functions tightly associated with specific member variables may break encapsulation, and these member variable may as well be declared with public access.

    For example, the length() member function of some string class might just return the value of a member variable, but it may not necessary be a getter function in this way, since it is concerned with a concept in the problem domain, i.e. that strings are of a certain length.

    Of course, the STL isnt particularly object oriented to begin with, but has more a focus on generic programming.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    Quote Originally Posted by anon
    So, basically you are saying that the STL is evil[...]?
    I believe Citizen is commenting on the fact that many of us don't really follow the advice on data abstraction by separating implementation from the interface. When we code public set and get member functions we aren't really for the most part following this concept. And some cases are so obvious that a class defined this way becomes nothing more than code trick to hide the fact we are lazy.

    A class that offers no data abstraction and no encapsulation is not a type. It's a data structure. We can have it redefined as a struct. To define it as class and hide behind it get and set function members show that we either don't understand what classes are meant to be or are too lazy to think of the correct way to implement them. I have many, many, times fallen prey to both when coding in Visual Basic.

    There are, of course, uses to get and set functions. Nothing is written in stone. However, citizen, I believe, was being more generic, offering the added challenge of thinking about a "true" class implementation. Just the alarms thing would be too easy.

    As for the string... the little i've studied so far of C++ (i'm a newcommer to it), the STL string type is presented to us by a typedef of the template basic_string. This template, and the class it hides, i'm sure, doesn't treat a string assigment as a set member function
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I seem to ave forgotten pretty much everything now...my mind is completely blank.

  14. #14
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Ah, all this talking confused you. Just read over the tutorials on the site to kick your brain back in. You'll start remembering things, and then you can come back to this thread.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I can't think what I would wan't to put in my class and what classes to have etc.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1st Assignment
    By Zeff in forum C Programming
    Replies: 29
    Last Post: 09-19-2006, 07:21 PM
  2. forgotten how to print values :(
    By darfader in forum C Programming
    Replies: 3
    Last Post: 08-12-2003, 09:47 AM
  3. Getting from function error!!!
    By frigga in forum C Programming
    Replies: 2
    Last Post: 11-19-2002, 02:37 PM
  4. Handwriting: soon to be forgotten?
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-26-2001, 06:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21