1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* Multiline comment
In this program, you can
experiment with some fun
stuff like changing color,
making sounds and drawing
lines in slow motion
Dont forget to put comments
in your program!
*/
// single line comment
// preprocessor directives
# include <iostream>
# include <windows.h> // included here for Beep( hertz, milliseconds );
// and Sleep( milliseconds ); functions
using namespace std;
// main
int main()
{
// declare variable choice
// of type short
short choice;
// display menu
cout << "\t\tPlease make a selection from the list below:\n\n"
<< "\t\t1.Change color\n\n"
<< "\t\t2.Make sound\n\n"
<< "\t\t3.Draw line\n\n"
<< "\t\t4.Exit program\n\n"
<< "\t\t? ";
cin >> choice;
switch ( choice )
{
case 1:
// clear screen
system ( "cls" );
// black background (0), blue text(9)
system ( "color 09" );
cout << "\n\n\t\tBlack background, blue text\n\n";
//Experiment with numbers ranging
// from 0 to 9, and A to F for
// different colors
break;
case 2:
// clear screen
system ( "cls" );
// make sounds
Beep( 100, 100 );
Beep( 500, 200 );
Beep( 1000, 300 );
Beep( 1500, 400 );
Beep( 1900, 1000 );
// the 1st number represents hertz,
// the second number represents
// the time duration in milliseconds
// experiment with different numbers and
// don't forget to include windows.h
break;
case 3:
system ( "cls" );
cout << endl;
for ( int i = 0; i < 80; i++ )
{
// print line
cout << "-";
// pause for 50 milliseconds before continuing
// experiment with different times
Sleep( 50 );
}// end for
break;
case 4:
// clear screen
system ( "cls" );
// display exit message
cout << "\n\n\t\tThank you for using this program\n\n";
// pause for 2 seconds
Sleep( 2000 );
// display exit message
cout << "\n\n\t\tGoodbye!\n\n";
Sleep( 2000 );
// close program
exit ( 1 );
break;
default:
// clear the fail state
cin.clear();
// ignore input error
cin.ignore( 1000, '\n' );
// clear screen
system ( "cls" );
// display error message
cout << "\n\n\t\tIncorrect Input!\n\n";
// pause screen for 2 second
Sleep( 2000 );
break;
}// end switch
// pause the screen
system ( "pause" );
}// end main
| |