Language C++
(GUI version)
| Date: | 05/28/05 |
| Author: | Martyn Davies |
| URL: | n/a |
| Comments: | 0 |
| Info: | n/a |
| Score: |
#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
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| extreme template metaprogramming | Richard Wolf | 04/20/05 | 5 | |
| meta programming | Arion Lei | 04/20/05 | 2 | |
| hacking style | Tim Robinson | 04/20/05 | 6 | |
| ob fuscated | Tapi (Paddy O'Brien) | 08/11/05 | 2 | |
| object-oriented version | Tim Robinson | 04/20/05 | 2 | |
| Preprocessor & self-include recursion | Chocapic | 02/27/07 | 0 |
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!
Comments