Thread: practice with classes

  1. #1

    practice with classes

    this may seem like an odd and very noobish remark, but could someone give me some problems where classes could be used? i tried searching google and came up empty and help is greatly appreciated,

  2. #2
    Registered User
    Join Date
    Jun 2002
    Say u wanted to make an employee roster. You could use multiple classes and inheritance. THe base class could be employee which wouldhave the salary and hours worked functions. Then in the other classes which would derive from Employee class they would have individual functions. Say a Construction guy would have a Equipment function to subtract equipment money from his pay.
    C++ Rules!!!!
    Microsoft Visual Studio .NET Enterprise

  3. #3
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Well, for a noobish example you could make a Triangle class.

    You'd have many things to consider.
    Have 3 private data members contain the coordinates of each point. It would also be wise to make an (X, Y) structure to hold both numbers in a easy to handle package.

    struct XYpair
    int theXcord;
    int theYcord;

    Or you could have 3 private data members be the length of each size.

    One of the mmbr functions could be getTriangleArea(), which calculates the area of the triangle.

    You could also think about optimization. Would it be better to have another data mmbr that stores the area of the triangle, and automatically updates any time the triangle changes, that way if someone repeatedly accesses the triangle's area but changes the triangle very little then you have increrased performance at the sacrafice of having that extra data mmbr taking up space. Or not have the data mmbr and have the area be recalculated everytime the area is requested.
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Phildelphia, PA
    In theory, any problem can be approached using object oriented design. Just think about the objects in a problem. In a bank, employees, customers, and money are all objects. In a zoo, monkeys, lions, and penguins are all objects. In any problem you can just look at the things in your problem and realize, 'hey, I can make that an object.' Whether or not OOP is always the best way to go is up for debate, but you should be able to code out most anything using this approach.

    I think that most programmers who were always taught top down design and then learn OOP are most confused by the simplicity of OOP. Everythings an object. It's that simple.

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. RPG ( practice with classes )
    By nickodonnell in forum Game Programming
    Replies: 3
    Last Post: 10-01-2005, 07:22 AM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  4. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM