Simple class problem.

This is a discussion on Simple class problem. within the C++ Programming forums, part of the General Programming Boards category; Alright, first off yes this is homework, but i'm giving it my try...but i just need some guidance on a ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Simple class problem.

    Alright, first off yes this is homework, but i'm giving it my try...but i just need some guidance on a few things. I honestly NEED to learn this stuff, and i know that.

    edit: clarify...i already wrote this code (except the test program, that is given to us)....i just need help correcting and understanding.

    Code:
    class Folder
    {
     public:
      Folder (bool& type, char* name, char* exten, double& size, char* date);
      add_entry(bool&, char* name, char* exten, double& size, char* date);
      delete_entry(char* name, char* exten);
      list_entry(char* name, char* exten);
      list_folders();
      Folder operator + (Folder& a, Folder& b);
    
     private:
      bool type;
      char name[8];
      char exten[3];
      double size;
      char date[10]; //must be xx/xx/xxxx format
    
    }
    
    list_entry(char* name, char* exten)
    {
    //what code?
    }
    Ok, the test program will be something like this:

    Code:
    int main () {
    
            Folder f1;
    
    f1.add_entry (true, "first", "dat", 1500, date);
    f1.add_entry (true, "second", "dat", 1500, date);
    f1.add_entry (true, "third", "txt", 1500, date);
    f1.list_folder();
    
    f1.delete_entry("second", "txt");
    f1.list_folder();
    f1.delete_entry("second", "dat");
    f1.list_folder();
    f1.add_entry (true, "SECOND", "dat", 1500, date);
    f1.list_folder();
    f1.delete_entry("*", "dat");
    f1.list_folder();
    
            // etc.
    }

    I am retarded when it comes to classes, my teachers taught it in a way i really don't understand. I understand structs really well, but i am LOST when it comes to classes, and i've been trying really hard to learn it.

    If anyone can kinda walk me through some of it explaining WHY things are how they are (or why they are wrong)...i'd VERY much appreciate the lesson. Thanks!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    In C++, the only difference between a struct and a class is that in a struct all members are public by default and in a class they are private.

    You didn't specify what you're having problems with. I can't give a lecture on the entire class concept.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    I recommend Thinking in C++ by Bruce Eckel which you can find at
    www.bruceeckel.com

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I would suggest commenting your code as it appears rather cryptic.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 12:29 PM
  2. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  3. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  4. Simple class problem
    By savageag in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2003, 10:50 AM
  5. problem with sending files to a class method..
    By utoots in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2003, 12:38 AM

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