Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include "StdAfx.h"
  2. #include "Sentence.h"
  3. #include <iostream>
  4. #include <sstream>
  5.  
  6.  
  7. // constructors
  8. Sentence::Sentence(void)
  9. {
  10.     my_string = "";
  11. }
  12.  
  13. Sentence::Sentence(std::string new_string)
  14. {
  15.     my_string = new_string;
  16. }
  17.  
  18. Sentence::Sentence(char chr)
  19. {
  20.     my_string = chr;
  21. }
  22.  
  23. Sentence::Sentence(int num)
  24. {
  25.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  26.     ss << num;
  27.     my_string = ss.str();
  28. }
  29.  
  30. Sentence::Sentence(float num)
  31. {
  32.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  33.     ss << num;
  34.     my_string = ss.str();
  35. }
  36.  
  37. Sentence::Sentence(double num)
  38. {
  39.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  40.     ss << num;
  41.     my_string = ss.str();
  42. }
  43.  
  44. // overload operator +=
  45. void Sentence::operator += (std::string str)
  46. {
  47.     my_string= my_string + str;
  48. }
  49. void Sentence::operator += (Sentence str)
  50. {
  51.     my_string = my_string + str.my_string;
  52. }
  53. void Sentence::operator += (char letter)
  54. {
  55.     my_string = my_string + letter;
  56. }
  57.  
  58. // convert the var to string and add
  59. void Sentence::operator+=(int num)
  60. {
  61.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  62.     ss << num;
  63.     my_string += ss.str();
  64. }
  65. void Sentence::operator+=(float num)
  66. {
  67.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  68.     ss << num;
  69.     my_string += ss.str();
  70. }
  71. void Sentence::operator+=(double num)
  72. {
  73.     std::stringstream ss (std::stringstream::in | std::stringstream::out);
  74.     ss << num;
  75.     my_string += ss.str();
  76. }
  77.    
  78. // destructor
  79. Sentence::~Sentence(void){};
  80.  
  81. // methods
  82. int Sentence::word_count()
  83. {
  84.     //fix later
  85.     return 0;
  86. }
  87. int Sentence::letter_count()
  88. {
  89.     return my_string.size();
  90. }
  91.  
  92. std::string Sentence::to_string()
  93. {
  94.     return my_string;
  95. }
  96.  
  97. void Sentence::draw()
  98. {
  99.     std::cout << my_string;
  100. }
  101.  
  102. // overload operator +
  103. Sentence Sentence::operator+(std::string str)
  104. {
  105.     Sentence temp(my_string + str);
  106.     return temp;
  107. }
  108.  
  109. Sentence Sentence::operator+(Sentence str)
  110. {
  111.     Sentence temp(my_string + str.to_string());
  112.     return temp;
  113. }
  114.  
  115. Sentence Sentence::operator+(char letter)
  116. {
  117.     Sentence temp(my_string + letter);
  118.     return temp;
  119. }
  120.  
  121. // convert the var to string and add
  122. Sentence Sentence::operator+(int num)
  123. {
  124.     Sentence temp2(num);
  125.     Sentence temp3(my_string + temp2.to_string());
  126.     return temp3;
  127. }
  128.    
  129. Sentence Sentence::operator+(float num)
  130. {
  131.     Sentence temp(num);
  132.     Sentence temp2(my_string + temp.to_string());
  133.     return temp2;
  134. }
  135.  
  136. Sentence Sentence::operator+(double num)
  137. {
  138.     Sentence temp(num);
  139.     Sentence temp2(my_string + temp.to_string());
  140.     return temp2;
  141. }
  142.  
  143. void Sentence::set_string(std::string new_val)
  144. {
  145.     my_string = new_val;
  146. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement