test.cpp 864 B

12345678910111213141516171819202122232425262728293031
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <cmath>
  6. void saveListToFile(const std::vector<double>& data, const std::string& filename) {
  7. std::ofstream outFile(filename);
  8. if (outFile.is_open()) {
  9. for (const auto& value : data) {
  10. outFile << value << "\n";
  11. }
  12. outFile.close();
  13. } else {
  14. std::cerr << "Unable to open file";
  15. }
  16. }
  17. void generateWaveform(const std::vector<double>& data) {
  18. for (const auto& value : data) {
  19. int amplitude = static_cast<int>(value * 10); // Scale for visibility
  20. std::cout << std::string(std::abs(amplitude), amplitude > 0 ? '+' : '-') << "\n";
  21. }
  22. }
  23. int main() {
  24. std::vector<double> data = {0.1, 0.4, 0.8, 0.5, -0.3, -0.7, -0.4, 0.2};
  25. saveListToFile(data, "data.txt");
  26. generateWaveform(data);
  27. return 0;
  28. }