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
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
object-oriented version | Tim Robinson | 04/20/05 | 4 | |
hacking style | Tim Robinson | 04/20/05 | 14 | |
extreme template metaprogramming | Richard Wolf | 04/20/05 | 5 | |
meta programming | Arion Lei | 04/20/05 | 5 | |
Preprocessor & self-include recursion | Chocapic | 02/27/07 | 6 | |
feature creep | Jono | 04/27/09 | 1 | |
most extreme template metaprogramming | Henrik Theiling | 12/04/11 | 0 | |
8 | Jono | 04/15/09 | 0 | |
ob fuscated | Tapi (Paddy O'Brien) | 08/11/05 | 4 |
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
mjt said on 10/17/09 07:54:44
Amateurish coding.