Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StdAfx.h"
- #include "Sentence.h"
- #include <iostream>
- #include <sstream>
- // constructors
- Sentence::Sentence(void)
- {
- my_string = "";
- }
- Sentence::Sentence(std::string new_string)
- {
- my_string = new_string;
- }
- Sentence::Sentence(char chr)
- {
- my_string = chr;
- }
- Sentence::Sentence(int num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string = ss.str();
- }
- Sentence::Sentence(float num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string = ss.str();
- }
- Sentence::Sentence(double num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string = ss.str();
- }
- // overload operator +=
- void Sentence::operator += (std::string str)
- {
- my_string= my_string + str;
- }
- void Sentence::operator += (Sentence str)
- {
- my_string = my_string + str.my_string;
- }
- void Sentence::operator += (char letter)
- {
- my_string = my_string + letter;
- }
- // convert the var to string and add
- void Sentence::operator+=(int num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string += ss.str();
- }
- void Sentence::operator+=(float num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string += ss.str();
- }
- void Sentence::operator+=(double num)
- {
- std::stringstream ss (std::stringstream::in | std::stringstream::out);
- ss << num;
- my_string += ss.str();
- }
- // destructor
- Sentence::~Sentence(void){};
- // methods
- int Sentence::word_count()
- {
- //fix later
- return 0;
- }
- int Sentence::letter_count()
- {
- return my_string.size();
- }
- std::string Sentence::to_string()
- {
- return my_string;
- }
- void Sentence::draw()
- {
- std::cout << my_string;
- }
- // overload operator +
- Sentence Sentence::operator+(std::string str)
- {
- Sentence temp(my_string + str);
- return temp;
- }
- Sentence Sentence::operator+(Sentence str)
- {
- Sentence temp(my_string + str.to_string());
- return temp;
- }
- Sentence Sentence::operator+(char letter)
- {
- Sentence temp(my_string + letter);
- return temp;
- }
- // convert the var to string and add
- Sentence Sentence::operator+(int num)
- {
- Sentence temp2(num);
- Sentence temp3(my_string + temp2.to_string());
- return temp3;
- }
- Sentence Sentence::operator+(float num)
- {
- Sentence temp(num);
- Sentence temp2(my_string + temp.to_string());
- return temp2;
- }
- Sentence Sentence::operator+(double num)
- {
- Sentence temp(num);
- Sentence temp2(my_string + temp.to_string());
- return temp2;
- }
- void Sentence::set_string(std::string new_val)
- {
- my_string = new_val;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement