Category Archives: C++

Birthday surprise

My wife and I wrote this little program for my little brother, who is a freshman computer science major. It was a lot of fun, and brought back memories of my C++ days in school.

Obviously the programming wasn’t challenging, but getting the parameters right was a lot of fun.


#include <iostream>
#include <windows.h>

#define doo 262 //frequency do 262 Hz
#define re 294 //frequency re 294 Hz
#define mi 330 //frequency mi 330 Hz
#define fa 349 //frequency fa 349 Hz
#define sol 392 //frequency sol 392 Hz
#define la 440 //frequency la 440 Hz
#define si 495 //frequency si 495 Hz
#define od 523 //frequency do 523 Hz

using namespace std;

int main()
{  
  
  Beep(doo,100);
  Beep(doo,100);
  Beep(re,180);
  Beep(doo,190);
  Beep(fa,200);
  Beep(mi,300);
  Beep(doo,100);
  Beep(doo,100);
  Beep(re,180);
  Beep(doo,190);
  Beep(sol,220);
  Beep(fa,300);
  Beep(doo,100);
  Beep(doo,100);
  Beep(od,260);
  Beep(la,260);
  Beep(fa,220);
  Beep(mi,200);
  Beep(re,300);
  Beep(466,100); //b-flat is 2^(1/12)*440 http://en.wikipedia.org/wiki/Note#Note_frequency_.28hertz.29
  Beep(466,100); //b-flat is 2^(1/12)*440 http://en.wikipedia.org/wiki/Note#Note_frequency_.28hertz.29
  Beep(la,260);
  Beep(fa,300);
  Beep(sol,300);
  Beep(fa,300);

  return 1;
}