Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include "user.h"
  5.  
  6. User::User(std::string uname)
  7. {
  8.   username = uname;
  9.   the_wall = new Wall();
  10.   friends = new List<std::string>();
  11. }
  12.  
  13. User::User(const User & u)
  14. {
  15.   username = u.username;
  16.   password = u.password;
  17.   the_wall = new Wall();
  18.   the_wall->read(u.the_wall->print() );
  19.   friends = new List<std::string>();
  20. }
  21.  
  22. User::User(std::string uname, std::string pword)
  23. {
  24.   username = uname;
  25.   password = pword;
  26.   the_wall = new Wall();
  27. }
  28.  
  29. User::~User()
  30. {
  31.   delete the_wall;
  32. }
  33.  
  34. void User::setPassword(std::string pword)
  35. {
  36.   password = pword;
  37. }
  38.  
  39. void User::setUsername(std::string uname)
  40. {
  41.   username = uname;
  42. }
  43.  
  44. std::string User::getPassword() const { return password; }
  45. std::string User::getUsername() const { return username; }
  46.  
  47. void User::addPost(WallPost wp) { the_wall->addPost(wp); }
  48. void User::addPost(std::string text) { the_wall->addPost(text); }
  49. void User::addPost(std::string p, std::string u) { the_wall->addPost(p,u); }
  50. void User::deletePost(int index)
  51. {
  52.   the_wall->removePost(index);
  53. }
  54. WallPost & User::get_post(int index){
  55.   the_wall->get(index);
  56. }
  57.  
  58. std::string User::write()
  59. {
  60.   std::string c="";
  61.   c += /*"username:" +*/ username + "\n";
  62.   c += /*"password:" +*/ password + "\n";
  63.   c += /*"the wall:" +*/ the_wall->print();
  64.   return c;
  65. }
  66.  
  67. void User::readIn(std::string all)
  68. {
  69.     //username
  70.     //password
  71.     //WALL
  72.   std::istringstream iss(all);
  73.   std::getline(iss, username);
  74.   std::getline(iss, password);
  75.   std::string cin;
  76.   for(std::string temp; std::getline(iss, temp); )
  77.     cin += temp + '\n';
  78.   the_wall->read(cin);
  79. }
  80.  
  81. void User::addFriend(std::string f)
  82. {
  83.   friends->insert(0, f);
  84. }
  85.  
  86. void User::print_friends()
  87. {
  88.   for(Node<std::string> * tmp = friends->begin(); tmp!=NULL; tmp=tmp->next)
  89.     std::cout << "THIS IS A FRIEND" << tmp->getData() << std::endl;
  90. }
  91.  
  92. void User::send_friend_request(std::string u)
  93. {
  94.   std::ofstream outfile;
  95.   outfile.open("friend_requests.txt", std::ios_base::app);
  96.   outfile << username << "\n" << u << "\n";
  97. }
  98.  
  99. Wall * User::getWall()
  100. {
  101.   return the_wall;
  102. }
  103. List<std::string> * User::getFriends()
  104. {
  105.   return friends;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement