Thread: n00b question regarding classes

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    12

    n00b question regarding classes

    I wanna build a Class called "Building" and each building object
    has a number of rooms(int), floors(int), floor area(int) and a heating type(char "e" or "o")
    either Electric or Oil. Initial Values should be 0(zero) and "e"

    tell me if i got this right or not
    Code:
    #ifndef BUILDING_H
    #define BUILDING_H
    
    class Building
    {
    
    public:												// Electric = "E" Oil = "O"
    	Specs(int = 0, int = 0, int = 0, char = "e");	// Heating type
    	void setRooms(int);								// set rooms
    	void setFloors(int);							// set Floors
    	void setArea(int);								// set Area
    	void heatingType(char);							// set Heating Type
    
    	// get functions
    	int getRooms();									// return Rooms
    	int getFloors();								// return Floors
    	int getArea();									// return Area
    	char heatingType();								// return Heating Type
    	
    private:
    	int Rooms;
    	int Floor;
    	int Area;
    	char Heat;
    
    }

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    close...
    Code:
    void Specs(int R=0, int F=0, int A=0, char H='e');
    then don't forget to actually assign those values when you define the constructor...
    Last edited by major_small; 07-12-2005 at 02:11 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Personally I would organize things a bit differently. A building has floors so I would make my Building class contain a vector of Floor objects. A Floor contains rooms so I would maybe make a Floor class contain a vector of Room objects, etc... (depends on how detailed/complex you want to get)

    Code:
    class Building
    {
    
    public:
        // This looks like a constructor, in that it does not have a return type...
        // But it is not named the same as the class name, error?
        // Plus what major_small already said...
        Specs(int = 0, int = 0, int = 0, char = "e");  
    
    };  // Missing semicolon
    Last edited by hk_mp5kpdw; 07-12-2005 at 02:15 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I missed that that wasn't a constructor, but hk's right... you're going to need to fix that into a constructor...

    I wouldn't worry about the level of detail hk suggested though--unless you have a practical purpose for that, it may be overkill
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    12
    Thanks for the help guys... i think i got it figured out....almost.... i have to admit this is the best programming forum out there... i'm sure i'll have more questions later on..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A little question about classes
    By Newbeee in forum C++ Programming
    Replies: 9
    Last Post: 06-15-2006, 03:46 PM
  2. Replies: 2
    Last Post: 06-11-2006, 05:56 PM
  3. Just starting to learn C++ Question about classes
    By uraliss in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2006, 03:31 AM
  4. Complete n00b Question, Client -> Sever MMO Program?
    By Zeusbwr in forum Networking/Device Communication
    Replies: 4
    Last Post: 07-28-2005, 08:33 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM