Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language C++

(GUI version)

Date:05/28/05
Author:Martyn Davies
URL:n/a
Comments:1
Info:n/a
Score: (1.68 in 19 votes)
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
#include <StdCtrls.hpp>

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TTimer *Timer1;
        TMemo  *Memo1;
        void __fastcall Timer1Timer(TObject *Sender);
private:	// User declarations
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};

//---------------------------------------------------------------------------

#endif


//---------------------------------------------------------------------------
//
// Programming language: C++ (Borland C++ Builder) 
// 99 bottles of beer, C++ GUI version
// By Martyn Davies (martynd@yahoo.com)
//

#include <vcl.h>
#include <stdio.h>
#include "Unit1.h"
// Unit1.h defines a TForm with one TMemo field (Memo1) and a TTimer (Timer1).

TForm1 *Form1;
const int max_beers=99;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  Memo1->Lines->Clear();
  Memo1->ScrollBars = ssVertical; 
  Timer1->Interval = 250;     //sing each verse in 250 ms
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  char *line=new char[30];
  static int beers=max_beers;
  char *bott;

  if(beers==1)
    bott = "bottle";
  else  
    bott = "bottles";
    
  if(beers>0){
    sprintf(line,"%d %s of beer on the wall,",beers,bott);
    Memo1->Lines->Add(line);
    
    sprintf(line,"%d %s of beer,",beers,bott);
    Memo1->Lines->Add(line);
    
    sprintf(line,"Take one down, pass it around,");
    Memo1->Lines->Add(line);
    
    if(--beers==1)
      bott = "bottle";
    else  
      bott = "bottles";
    sprintf(line,"%d %s of beer on the wall.",beers,bott);
    Memo1->Lines->Add(line);

    Memo1->Lines->Add(" ");
  }                                                
}
//---------------------------------------------------------------------------

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
object-oriented versionTim Robinson04/20/054
hacking styleTim Robinson04/20/0514
extreme template metaprogrammingRichard Wolf04/20/055
meta programmingArion Lei04/20/055
Preprocessor & self-include recursionChocapic02/27/076
feature creepJono04/27/091
most extreme template metaprogrammingHenrik Theiling12/04/110
8Jono04/15/090
ob fuscatedTapi (Paddy O'Brien)08/11/054

Comments

>>  mjt said on 10/17/09 07:54:44

mjt Amateurish coding.

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: