JohnOne Posted September 19, 2012 Share Posted September 19, 2012 So this is my big explosion into the world of OO in C++.If someone would be so kind as to suggest what exactly I needfocus on to get to my next goal I'd be mighty obliged.expandcollapse popupclass Room { private: bool occupied; bool riverveiw; bool ensuite; public: Room () : occupied(false), riverveiw(false), ensuite(true) { } bool IsEnsuite() { return ensuite; } }; class Guest { private: bool VIP; double totalbill; public: Guest () { } }; class BBHouse { private: public: Room room1; Room room2; Room room3; Room room4; BBHouse () { } }; int main () { BBHouse BB1; if (BB1.room1.IsEnsuite()) { std::cout << "Ensuite" << "\n"; } std::cin.get(); }Sorry, tags stripping leading WS.I have a Guest class there as you see, but guests come and go, so what is theprocedure called for dynamically adding a guest to a room, and of course removing too.I thin what I have here is called composition, and I have a sneaky feeling that aggregationis what I need, but I'm unsure how to combine the two.Any hint / tips / angry confrontations welcome? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Shaggi Posted September 19, 2012 Share Posted September 19, 2012 (edited) e: misread post, sec i would just use any stl container (list/vec probably), and encapsulate + get/add/remove methods, which also handle checkout bills and such Edited September 19, 2012 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted September 19, 2012 Author Share Posted September 19, 2012 Cheers. Getting a little scared looking at stl containers though. Is this my only path? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jaberwacky Posted September 19, 2012 Share Posted September 19, 2012 (edited) I think with one class you have neither composition nor aggregation. When you get into inheritance and the like then you can then start talking in those terms. (I'm no expert so I may very well be wrong.) Edit: Good start though. You've come a long way in your programming knowledge. EDIT: One facepalm after another. I just expanded your post to see more than one class. DAMMIT! Edited September 19, 2012 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted September 19, 2012 Author Share Posted September 19, 2012 lol AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Shaggi Posted September 19, 2012 Share Posted September 19, 2012 Cheers. Getting a little scared looking at stl containers though. Is this my only path? You shouldn't be - theyre there to help you. And, no it isn't. but im pretty sure it's the easiest - you dont wanna handle dynamic memory yourself, unless it's absolutely necessary. Firstly, you choose a container - a list, map or vector would be ideal for this type of job. Any would do, but here's a quick example using a map: expandcollapse popup#include <map> #include <string> int main() { ... hotel.AddGuest("john"); hotel.RemoveGuest("john"); ... } class BBHouse { .... std::map<std::string, Guest> guests; // maps provide an easy interface to look up an guest using a string like an array. //consider adding rooms as a map/list or something too, so you can have an expandable hotel. seems nice public: void AddGuest(string name, int room = -1) { //this assumes a design where this class autofits a guest into a room, unless a specific room number is given // snip: this is the room our algorithm gives us. maybe add errorchecking here if house is full // not quite sure how you want room & guest relationship - but use references so rooms and guests have relationships Room & assigned_room = get_first_avaible_room(); Guest new_guest; //new_quest.name = name; optional: see further down guests[name] = guest; //should room be selfaware? assigned_room.add(guest); } public: void RemoveGuest(string name) { //do billing here //now erase entry guests.erase(guests.find(name)); } private: Room & get_first_avaible_room(); // returns a reference to a room, that is empty .... } class Guest { ... //this is optional, but it might be nice to have the guest name stored public: string name; ... } JohnOne 1 Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted September 19, 2012 Author Share Posted September 19, 2012 Thanks Shaggi, enough for me to be getting on with there. Cheers. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now