» Site Navigation | | | » Advertisement | | | » Recent Threads | | | | | | | | | Consumption Today 09:23 PM Today 09:50 PM 2 Replies, 3 Views | |  |  | Some simple C++ programs |  |
12-16-2006, 06:17 AM
|
#1 (permalink)
| Underground
Join Date: Sep 2006 Location: The o great land of Nooooooreeeway Age: 20 Posts: 658
GPoints: 38 Rep Power: 7 | Some simple C++ programs Nothing complicated, I just began a bit with C++. http://vestberg.net/~gommlem/dir/files/cppBeep.rar http://vestberg.net/~gommlem/dir/files/cppCtoF.rar http://vestberg.net/~gommlem/dir/files/cppTimer.rar
CppBeep PHP Code: //
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <windows.h>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
cout << endl << "This program will use your internal PC speaker to output ";
cout << endl << "tones. The program will simply start beeping while ";
cout << endl << "increasing the pitch. You can choose the length, pitch ";
cout << endl << "amount of beeps, and frequency increment for each beep. ";
cout << endl << "Press Ctrl+C to exit the program. The values in paranthesis";
cout << endl << "are default values.";
cout << endl << endl << "-----------------Made by Gommle------------------------- ";
// define tone lengths
int lWhole;
int lHalf;
int lQuarter;
int lEight;
int lSixteenth;
lWhole = 1600;
lHalf = lWhole/2;
lQuarter = lHalf/2;
lEight = lQuarter/2;
lSixteenth = lEight/2;
// define tone frequencys
int tLowG = 196;
int tA = 220;
int tHighA = 233;
int tB = 247;
int tC = 262;
int tHighC = 277;
int tD = 294;
int tHighD = 311;
int tE = 330;
int tF = 349;
int tHighF = 370;
int tG = 392;
int tHighG = 415;
cout << endl << "(0 or 1) Do you want to play some songs from the jukebox?";
int jukeplay;
cin >> jukeplay;
int SongToneLength = 210;
while(jukeplay==1)
{
int song;
cout << endl << "Available options:";
cout << endl << "1. Play Mortal Combat theme";
cout << endl << "2. Play Super Mario Bros theme";
cout << endl << "3. Play Star Wars theme";
cout << endl << "4. Exit Jukebox";
cout << endl << endl << "(1-4) Which option do you choose?";
cout << endl << endl << "Song:";
cin >> song;
switch(song)
{
case 1:
// play the mortal combat theme
Beep(tA, SongToneLength);Sleep(10);
Beep(tA, SongToneLength);Sleep(10);
Beep(tC, SongToneLength);Sleep(10);
Beep(tA, SongToneLength);Sleep(10);
Beep(tD, SongToneLength);Sleep(10);
Beep(tA, SongToneLength);Sleep(10);
Beep(tE, SongToneLength);Sleep(10);
Beep(tD, SongToneLength);Sleep(10);
Beep(tC, SongToneLength);Sleep(10);
Beep(tC, SongToneLength);Sleep(10);
Beep(tE, SongToneLength);Sleep(10);
Beep(tC, SongToneLength);Sleep(10);
Beep(tF, SongToneLength);Sleep(10);
Beep(tC, SongToneLength);Sleep(10);
Beep(tG, SongToneLength);Sleep(10);
Beep(tF, SongToneLength);Sleep(10);
break;
case 2:
// play themario theme
Beep(tE, SongToneLength);
Sleep(10);
Beep(tE, SongToneLength);
Sleep(10);
Beep(tE, SongToneLength);
Sleep(10);
Beep(tC, SongToneLength);
Sleep(10);
Beep(tE, SongToneLength);
Sleep(10);
Beep(tHighG, SongToneLength*2);
Sleep(10);
Sleep(SongToneLength);
Beep(tG, SongToneLength);
Sleep(10);
Sleep(SongToneLength);
Sleep(SongToneLength);
Sleep(SongToneLength);
break;
case 3:
// play darth vader thingy
Beep(tA, SongToneLength*2); Sleep(10);
Beep(tA, SongToneLength*2); Sleep(10);
Beep(tA, SongToneLength*2); Sleep(10);
Beep(tF, SongToneLength); Sleep(10);
Beep(tC, SongToneLength); Sleep(10);
Beep(tA, SongToneLength*2); Sleep(10);
Beep(tF, SongToneLength); Sleep(10);
Beep(tC, SongToneLength); Sleep(10);
Beep(tA, SongToneLength*3); Sleep(10);
Beep(tE, SongToneLength); Sleep(10);
Beep(tHighA, SongToneLength*2); Sleep(10);
Beep(tHighA, SongToneLength*2); Sleep(10);
Beep(tHighA, SongToneLength*2); Sleep(10);
Beep(tHighF, SongToneLength); Sleep(10);
Beep(tHighC, SongToneLength); Sleep(10);
Beep(tHighA, SongToneLength*2); Sleep(10);
Beep(tHighF, SongToneLength); Sleep(10);
Beep(tHighC, SongToneLength); Sleep(10);
Beep(tHighA, SongToneLength*3); Sleep(10);
Beep(tE, SongToneLength); Sleep(10);
break;
case 4:
jukeplay = 0;
break;
}
}
//start the main loop
while(1==1){
// define the frequency increment
int nFrequencyInc;
cout << endl << endl << "(30) Frequency increment for each loop: ";
cin >> nFrequencyInc;
// define the frequency increment
int nFrequencyStart;
cout << endl << "(180) Frequency start position: ";
cin >> nFrequencyStart;
// define the amount of beeps
int nTones;
cout << endl << "(10) Amount of beeps: ";
cin >> nTones;
// define the tone length
int nLength;
cout << endl << "(200) Tone length: ";
cin >> nLength;
// define the delay after tones
int nDelay;
cout << endl << "(40) Delay between tones: ";
cin >> nDelay;
// declare variables for the loop
int nCounter;
nCounter = 0;
int nFrequency;
nFrequency = nFrequencyStart;
// echo the amount of tones specified
while(nCounter < nTones)
{
// beep
Beep(nFrequency, nLength);
// increment the frequency by the user input
nFrequency = nFrequencyInc + nFrequency;
nCounter++;
Sleep(nDelay);
}
}
}
CppTimer PHP Code: //
// This program beeps after x minutes. Ideal for pizza making.
// Todo:
// Presets for different types of Pizza, cold oven and warm oven
//
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <windows.h>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// get minutes
int nMinutes;
cout << "This program will count down from a time you specify and make a";
cout << "beep sound when it's done";
cout << endl << "Minutes to wait: ";
cin >> nMinutes;
cout << endl << nMinutes << " minutes left..." <<endl;
// echo remaining minutes each minute
while(nMinutes > 0)
{
--nMinutes;
Sleep(60000);
cout << nMinutes << " minutes left..." << endl;
}
// wait for the user to press a key
Beep(600,200);
Beep(500,200);
Beep(400,200);
MessageBox (NULL, "Timer finished!" , "Timer", 0);
cout << nMinutes << "Done!" << endl;
system("PAUSE");
}
CppCelsiustoFahrenheit PHP Code: //
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100 + 32
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// enter the temperature in Celsius
int celsius;
cout << "Enter the temperature in Celsius:";
cin >> celsius;
// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius
// to Fahrenheit
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
cout << "Fahrenheit value is: ";
cout << fahrenheit << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
The first one is really fun at school. Try setting the tone to 2400-2600, length to 1000, and delay to 30-200 secs.
All of them will only work on Windows by the way.
__________________  | |
| |  |  | Re: Some simple C++ programs |  |
02-03-2007, 06:51 AM
|
#2 (permalink)
|
Join Date: Dec 2006 Age: 17 Posts: 6,460
GPoints: 1,014 Rep Power: 15 | Re: Some simple C++ programs The first one is kinda cool gj xD
I'm going to try it in school. hehe
__________________ Quote:
Originally Posted by Fewmitz Do more drugs to avoid the come down from all of the drugs?
Virus, your logic is flawless. | Current Anime Watchlist:
Elfen Lied - FINISHED T_T <3
D.Gray-Man - Up To Episode 40
Tenchi Muyo - Up To Episode 13
Night Wizard - Up To Episode 5 | |
| |
07-18-2007, 08:19 PM
|
#3 (permalink)
| Underground
Join Date: Jun 2007 Posts: 98
GPoints: 1 Rep Power: 5 | really simple, when i am in highschool , i did the same thing | |
| |
07-28-2007, 08:06 PM
|
#4 (permalink)
| Resident Psychopath.
Join Date: Nov 2006 Location: fewmitz@live.com Posts: 5,378
GPoints: 2,485 Rep Power: 17 | Quote:
Originally Posted by Ricardandroy really simple, when i am in highschool , i did the same thing | Did you also pass English? | |
| |
08-12-2007, 09:03 AM
|
#5 (permalink)
| Underground
Join Date: Sep 2006 Location: The o great land of Nooooooreeeway Age: 20 Posts: 658
GPoints: 38 Rep Power: 7 | I do this when I am 14 ;)
(Yes, pun intended.)
__________________  | |
| |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |