mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-28 05:33:48 -08:00
Merge pull request #834 from gilssonn/78-sine-wave-C++
C++ Implementation of Sine Wave
This commit is contained in:
3
00_Alternate_Languages/78_Sine_Wave/C++/README.md
Normal file
3
00_Alternate_Languages/78_Sine_Wave/C++/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [C++17](https://en.wikipedia.org/wiki/C%2B%2B17)
|
||||
21
00_Alternate_Languages/78_Sine_Wave/C++/sinewave.cpp
Normal file
21
00_Alternate_Languages/78_Sine_Wave/C++/sinewave.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <iostream> // std::cout, std::endl
|
||||
#include <string> // std::string(size_t n, char c)
|
||||
#include <cmath> // std::sin(double x)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << std::string(30, ' ') << "SINE WAVE" << std::endl;
|
||||
std::cout << std::string(15, ' ') << "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" << std::endl;
|
||||
std::cout << std::string(5, '\n');
|
||||
|
||||
bool b = true;
|
||||
|
||||
for (double t = 0.0; t <= 40.0; t += 0.25)
|
||||
{
|
||||
int a = int(26 + 25 * std::sin(t));
|
||||
std::cout << std::string(a, ' ') << (b ? "CREATIVE" : "COMPUTING") << std::endl;
|
||||
b = !b;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user