12345678910111213141516171819202122232425262728293031 |
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <cmath>
- void saveListToFile(const std::vector<double>& data, const std::string& filename) {
- std::ofstream outFile(filename);
- if (outFile.is_open()) {
- for (const auto& value : data) {
- outFile << value << "\n";
- }
- outFile.close();
- } else {
- std::cerr << "Unable to open file";
- }
- }
- void generateWaveform(const std::vector<double>& data) {
- for (const auto& value : data) {
- int amplitude = static_cast<int>(value * 10); // Scale for visibility
- std::cout << std::string(std::abs(amplitude), amplitude > 0 ? '+' : '-') << "\n";
- }
- }
- int main() {
- std::vector<double> data = {0.1, 0.4, 0.8, 0.5, -0.3, -0.7, -0.4, 0.2};
- saveListToFile(data, "data.txt");
- generateWaveform(data);
- return 0;
- }
|