fcamuso

Corso C++ 23 - lezione 33 (funzioni terza parte)

May 27th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1.  
  2. int valore_assoluto(int n)
  3. {
  4.     return n >= 0.0 ? n : - n;
  5. }
  6.  
  7. void print(int n, char simbolo='-') {
  8.     std::string n_str = std::format("{}", n);
  9.     std::string bordo = std::string(n_str.length(), simbolo);
  10.  
  11.     std::println("{}", bordo);
  12.     std::println("{}", n);
  13.     std::println("{}", bordo);
  14. }
  15.  
  16. void print(const std::vector<int>& v, char simbolo='=') {
  17.     std::string bordo = std::string(50, simbolo);
  18.    
  19.     std::println("\n\n{}\n{}", bordo, bordo);
  20.     for (int n : v) {
  21.         std::println("*{}*",n);
  22.     }
  23.     std::println("{}\n{}", bordo, bordo);
  24. }
  25.  
  26. // API C sottostante (simulata ovviamente)
  27. void send_data_i(int d){};
  28. void send_data_f(float d){};
  29. void send_data_s(const char* d){};
  30.  
  31. // Wrapper C++ usando gli overload
  32. void send(int d) { send_data_i(d); }
  33. void send(float d) { send_data_f(d); }
  34. void send(const char* d) { send_data_s(d); }
  35.  
  36.  
  37. int stima_ampiezza() { return 60; }
  38.  
  39. void riga_divisoria(char simbolo, int lunghezza)
  40. {
  41.     std::println("{}", std::string(lunghezza, simbolo));
  42.     return;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment