|
Fdeveloper (m)
|
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,
|
|
|
|
|
|
c0dec (m)
|
cool. class DreamBabe { private: const double m_boobs; const double m_bootay; const int m_thatThing;
bool MadLove(const c0dec) { return true; }
public: const int m_IQ;
DreamBabe() : m_IQ(130) {} ~DreamBabe();
void Listen(hiphop) void Listen(nuMetal) void Plays(const c0dec); void Plays(games); void Cooks(const every);
bool IsDumb() { return false; } bool IsAGoldDigger() { return false; } bool IsFat() { return false; }
}
|
|
|
|
|
|
clocky (m)
|
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 < Ulength; 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); }
}
|
|
|
|
|
|
Fdeveloper (m)
|
Excellent stuff clocky!! I particularly like your definition of the "Person" base class which you then extend to "You" & "Me". Classic java programming 
|
|
|
|
|
|
c0dec (m)
|
@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.
|
|
|
|
|
|
clocky (m)
|
@codec
Please can u explain?
|
|
|
|
|
|
c0dec (m)
|
was refering to your "You" and "Me" classes
|
|
|
|
|
|
clocky (m)
|
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
|
|
|
|
|
|
candylips (m)
|
Where is c0dec.
|
|
|
|
|
|
sayhi2ay (m)
|
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 < Ulength; 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); }
}
What does this do exactly ?
|
|
|
|
|
|
candylips (m)
|
read the code and deduce for yourself
|
|
|
|
|
|
sayhi2ay (m)
|
perhaps if you had put comment inside you code, it would have been readable, i executed it and nothing came, doesnt make sense
|
|
|
|
|
|
Derby
|
cool. class DreamBabe { private: const double m_boobs; const double m_bootay; const int m_thatThing;
bool MadLove(const c0dec) { return true; }
public: const int m_IQ;
DreamBabe() : m_IQ(130) {} ~DreamBabe();
void Listen(hiphop) void Listen(nuMetal) void Plays(const c0dec); void Plays(games); void Cooks(const every);
bool IsDumb() { return false; } bool IsAGoldDigger() { return false; } bool IsFat() { return false; }
} Talk About All This At Forum For Certification and C++ http://pass4sure Register now!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
Ghenghis (m)
|
@c0dec is mixing up classes and object instances You don't 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 
|
|
|
|
|
|
candylips (m)
|
harmless code as codec said. i don't think they were coding for a context.
|
|
|
|
|
|