System Beep C++


SUBMITTED BY: Guest

DATE: Dec. 16, 2013, 7:21 p.m.

FORMAT: C++

SIZE: 2.3 kB

HITS: 15869

  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4. //twinkle twinkle
  5. //CC GG AA G
  6. //FF EE DD C
  7. //GG FF EE D
  8. //GG FF EE D
  9. //CC GG AA G
  10. //FF EE DD C
  11. void playnote (char g, float l)
  12. {
  13. char n = g;
  14. if (n == 'A'||'a'){
  15. Beep(2750,l*1000);
  16. cout <<n;
  17. }
  18. else if(n == 'B'||'b'){
  19. Beep(3087,l*1000);
  20. cout << n;
  21. }
  22. else if(n == 'C'||'c'){
  23. Beep(1637,l*1000);
  24. cout << n;
  25. }
  26. else if(n == 'D'||'d'){
  27. Beep(1835,l*1000);
  28. cout << n;
  29. }
  30. else if(n == 'E'||'e'){
  31. Beep(2060,l*1000);
  32. cout << n;
  33. }
  34. else if(n == 'F'||'f'){
  35. Beep(2183,l*1000);
  36. cout << n;
  37. }
  38. else if(n == 'G'||'g'){
  39. Beep(2450,l*1000);
  40. cout << n;
  41. }
  42. }
  43. int main() {
  44. playnote('C', 0.4);
  45. playnote('C', 0.4);
  46. playnote('G', 0.4);
  47. playnote('G', 0.4);
  48. playnote('A', 0.4);
  49. playnote('A', 0.4);
  50. playnote('G', 0.4);
  51. Sleep(400);
  52. cout<<endl;
  53. playnote('F', 0.4);
  54. playnote('F', 0.4);
  55. playnote('E', 0.4);
  56. playnote('E', 0.4);
  57. playnote('D', 0.4);
  58. playnote('D', 0.4);
  59. playnote('C', 0.4);
  60. Sleep(400);
  61. cout<<endl;
  62. playnote('G', 0.4);
  63. playnote('G', 0.4);
  64. playnote('F', 0.4);
  65. playnote('F', 0.4);
  66. playnote('E', 0.4);
  67. playnote('D', 0.4);
  68. playnote('G', 0.4);
  69. Sleep(400);
  70. cout<<endl;
  71. playnote('G', 0.4);
  72. playnote('F', 0.4);
  73. playnote('F', 0.4);
  74. playnote('E', 0.4);
  75. playnote('D', 0.4);
  76. playnote('C', 0.4);
  77. playnote('C', 0.4);
  78. Sleep(400);
  79. cout<<endl;
  80. playnote('G', 0.4);
  81. playnote('G', 0.4);
  82. playnote('A', 0.4);
  83. playnote('A', 0.4);
  84. playnote('G', 0.4);
  85. playnote('F', 0.4);
  86. playnote('F', 0.4);
  87. Sleep(400);
  88. cout<<endl;
  89. playnote('E', 0.4);
  90. playnote('E', 0.4);
  91. playnote('D', 0.4);
  92. playnote('D', 0.4);
  93. playnote('C', 0.4);
  94. cout<<endl;
  95. return 0;
  96. }

comments powered by Disqus