Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. // .h
  2.  
  3. #ifndef FIRST_MESSAGE_H
  4. #define FIRST_MESSAGE_H
  5. #include <iostream>
  6.  
  7.  
  8. class Message{
  9.  
  10. public:
  11.     long id;
  12.     char* data;
  13.     int size;
  14.     Message(int n )  ;
  15.      long getId() const ;
  16.     char* getData() const ;
  17.     int getSize() const ;
  18.  
  19.      char* mkMessage (int n) ;
  20.  
  21. private:
  22.     static int count ;
  23. };
  24.  
  25. std::ostream& operator​<<(std::ostream& ​out, ​const​ Message​& ​m);
  26. #endif //FIRST_MESSAGE_H
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. //.cpp
  34.  
  35.  
  36. #include "Message.h"
  37. #include <string>
  38. #include <iostream>
  39.  
  40.     int count = 0;
  41.  
  42.     Message::Message(int n) : size(n) {
  43.  
  44.     data = mkMessage(size);
  45.  
  46. }
  47.  
  48.     char* Message::mkMessage (int n){
  49.         std::string vocali = "aeiou";
  50.         std::string consonanti = "bcdfghlmnpqrstvz";
  51.         char* m = new char[n+1];
  52.         for (int i = 0 ; i<n ; i++){
  53.             m[i] = i%2 ? vocali[rand()%vocali.size()] :
  54.                     consonanti[rand() % consonanti.size()];
  55.         }
  56.         m[n] = 0;
  57.         std::cout << m << std::endl;
  58.         return 0;
  59.     }
  60.      long Message::getId() const {
  61.         return id;
  62.     }
  63.     char* Message::getData() const {
  64.     return data;
  65. }
  66.     int Message::getSize() const {
  67.         return size;
  68.     }
  69.  
  70.  
  71. std::ostream &operator<<(std::ostream &out, const Message &message) {
  72.     out << "[id:" << message.getId() << "][size:" << message.getSize() << "][message:" << message.getData() << "]";
  73.     return out;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement