Drinks Invitation Written In C++

A Member? Please Login  
type your username and password to login
Date: October 14, 2008, 08:52 AM
249639 members and 148319 Topics
Latest Member: Flillcoothe
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Drinks Invitation Written In C++
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Drinks Invitation Written In C++  (Read 569 views)
Fdeveloper (m)
Drinks Invitation Written In C++
« on: June 28, 2006, 05:24 PM »

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)
Re: Drinks Invitation Written In C++
« #1 on: June 30, 2006, 11:53 AM »

cool. 

Code:
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)
Re: Drinks Invitation Written In C++
« #2 on: July 04, 2006, 12:56 PM »

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)
Re: Drinks Invitation Written In C++
« #3 on: July 04, 2006, 04:24 PM »

Excellent stuff clocky!!

I particularly like your definition of the "Person" base class which you then extend to "You" & "Me".  Classic java programming  Smiley
c0dec (m)
Re: Drinks Invitation Written In C++
« #4 on: July 25, 2006, 09:28 PM »

@clocky.

bad bad OOP  Grin. there's no need to inherit if you're only modifying a member variable. only inherit if you're adding functionality.
clocky (m)
Re: Drinks Invitation Written In C++
« #5 on: July 25, 2006, 09:46 PM »

@codec

Please can u explain?
c0dec (m)
Re: Drinks Invitation Written In C++
« #6 on: July 27, 2006, 11:51 AM »

was refering to your "You" and "Me" classes
clocky (m)
Re: Drinks Invitation Written In C++
« #7 on: July 28, 2006, 10:18 AM »

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)
Re: Drinks Invitation Written In C++
« #8 on: August 05, 2008, 04:32 PM »

Where is c0dec.
sayhi2ay (m)
Re: Drinks Invitation Written In C++
« #9 on: August 07, 2008, 01:51 AM »

Quote from: clocky on July 04, 2006, 12:56 PM
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)
Re: Drinks Invitation Written In C++
« #10 on: August 11, 2008, 05:03 PM »

read the code and deduce for yourself
sayhi2ay (m)
Re: Drinks Invitation Written In C++
« #11 on: August 11, 2008, 06:27 PM »

perhaps if you had put comment inside you code, it would have been readable, i executed it and nothing came, doesnt make sense
Derby
Re: Drinks Invitation Written In C++
« #12 on: August 12, 2008, 12:44 AM »

Quote from: c0dec on June 30, 2006, 11:53 AM
cool.

Code:
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)
Re: Drinks Invitation Written In C++
« #13 on: August 12, 2008, 08:35 AM »

@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  Wink
candylips (m)
Re: Drinks Invitation Written In C++
« #14 on: August 12, 2008, 06:03 PM »

harmless code as codec said. i don't think they were coding for a context.
 I.t. Professionals Needed  The Programmer As A Mechanic  Need For More Programmers In Nigeria  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.