Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,615 members, 7,809,256 topics. Date: Friday, 26 April 2024 at 06:52 AM |
Nairaland Forum / Science/Technology / Programming / Drinks Invitation Written In C++ (2359 Views)
Creating UWP Application In C# Or C++ (xaml) / Urgent!!! Convert Source Code Written In VB6. To VB .NET / [problem] Write A Program In C++ That Finds The Hcf Of 2 Numbers Without Using A Recursive Function (2) (3) (4)
Drinks Invitation Written In C++ by Fdeveloper(m): 5:24pm On Jun 28, 2006 |
I thought I would share this with fellow C++ programmers out there. The following is the code I send to my colleagues to invite them for a drink when I get to the end of my contract. #define VC_EXTRALEAN #include <afxwin.h> CNotThirsty Goodbye::Execute() { CColleague oMe = "FDeveloper", oYou = "Colleagues"; CString sWhat = "Farewell drink", sWhy = "End of my contract"; CObject oWhatever; CNotThirsty oNotThirsty = null; /* Define event Date/Time: 30/06/06 17:30:00 */ CTime dtNow( 2006, 6, 30, 17, 30, 0 ); if( ( dtNow >= CTime::GetCurrentTime() ) && ( oYou.FeelLikeIt ) ) { for( int oYou.Step = 1; ! oYou.InDrinksBar; oYou.Step ++ ); { oYou.DistanceToDrinksBar --; } while( ( ! oYou.HadEnough ) && ( ! oMe.OutOfMoney ) ) { oYou.Drink( (Drink) oWhatever( sWhat, sWhy ) ); } oNotThirsty = (CNotThirsty) oYou; } return oNotThirsty; } I'd be really interested in similar code that anyone else may have in C++ or any other language, |
Re: Drinks Invitation Written In C++ by c0dec(m): 11:53am On Jun 30, 2006 |
cool.
|
Re: Drinks Invitation Written In C++ by clocky(m): 12:56pm On Jul 04, 2006 |
Nice one Fdeveloper, i was a bit bored so i did a lame port of your code to java import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; /** * @author * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class DrinksInThePub { public static void main(String[] args) { Me me = new Me("clocky" You you [] = {new You("Fdeveloper", new You("cOdec"}; String sWhat = "Farewell drink"; String sWhy = "End of my contract"; int distanceToPub = 200; Calendar date = new GregorianCalendar(); date.set(2006,6,30,17,30,0); for(int i = 0; i < you.length; i++){ if(date.after(new Date()) && you[i].isFeelingLineDrinking()){ for(int step = 1; step <= distanceToPub ;step++){ you[i].setDistanceCovered(step); } you[i].setInPub(true); while(!you[i].isHadEnoughDrinks() && !me.isOutOfMoney()){ you[i].drink(sWhat,sWhy); } } } } } public class Person { private String name; private int distanceCovered ; private boolean inPub = false; private boolean hadEnoughDrinks = false; private boolean outOfMoney = false; private String reason; private boolean feelingLineDrinking = true; public Person(String name){ this.name = name; } public boolean isFeelingLineDrinking() { return feelingLineDrinking; } public void drink(String what, String why){ this.reason = what +" "+ why; } public void setDistanceCovered(int distanceToNearestPub) { this.distanceCovered = distanceToNearestPub; } public boolean isHadEnoughDrinks() { return hadEnoughDrinks; } public boolean isInPub() { return inPub; } public void setInPub(boolean inPub) { this.inPub = inPub; } public boolean isOutOfMoney() { return outOfMoney; } } public class You extends Person { /** * @param name */ public You(String name) { super(name); } } public class Me extends Person { /** * @param name */ public Me(String name) { super(name); } } |
Re: Drinks Invitation Written In C++ by Fdeveloper(m): 4:24pm On Jul 04, 2006 |
Excellent stuff clocky!! I particularly like your definition of the "Person" base class which you then extend to "You" & "Me". Classic java programming |
Re: Drinks Invitation Written In C++ by c0dec(m): 9:28pm On Jul 25, 2006 |
@clocky. bad bad OOP . there's no need to inherit if you're only modifying a member variable. only inherit if you're adding functionality. |
Re: Drinks Invitation Written In C++ by clocky(m): 9:46pm On Jul 25, 2006 |
@codec Please can u explain? |
Re: Drinks Invitation Written In C++ by c0dec(m): 11:51am On Jul 27, 2006 |
was refering to your "You" and "Me" classes |
Re: Drinks Invitation Written In C++ by clocky(m): 10:18am On Jul 28, 2006 |
but inheritance is also useful if u have the same functionality that u wish to reuse in different classes which was d case in d sample . anyway it was just an harmless code i wrote during a bored afternoon |
Re: Drinks Invitation Written In C++ by candylips(m): 4:32pm On Aug 05, 2008 |
x |
Re: Drinks Invitation Written In C++ by sayhi2ay(m): 1:51am On Aug 07, 2008 |
clocky: What does this do exactly ? |
Re: Drinks Invitation Written In C++ by candylips(m): 5:03pm On Aug 11, 2008 |
read the code and deduce for urself |
Re: Drinks Invitation Written In C++ by sayhi2ay(m): 6:27pm On Aug 11, 2008 |
perhaps if you had put comment inside you code, it would have been readable, i executed it and nothing came, doesnt make sense |
Re: Drinks Invitation Written In C++ by Derby: 12:44am On Aug 12, 2008 |
c0dec:Talk About All This At Forum For Certification and C++ http://pass4sure.smfforfree2.com Register now!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
Re: Drinks Invitation Written In C++ by Ghenghis(m): 8:35am On Aug 12, 2008 |
@c0dec is mixing up classes and object instances You dont need to inherit 'cause You and me are Persons (right ?) you just need to create two instances of Person Person you = new Person("c0dec" Person me = new Person("Ghenghis" The issue about inheriting to change a member variable is this : 1) In good OOP Member variables shouldn't be public except through accessors, if they where private then you wont be have access to them through inheritance anyway. also you inherit for many reasons : type, behaviour etc. , anyways u didn't need it at all in this case |
Re: Drinks Invitation Written In C++ by candylips(m): 6:03pm On Aug 12, 2008 |
harmless code as codec said. i don't think they were coding for a contest. |
(1) (Reply)
Android User Registration And Login Source Code With Complete Back-end Dashboard / Download Over 120 Graphic Design Video Tutorials / Join My Flutter/dart Developer Community On Whatsapp
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |