Advertisement
Guest User

Untitled

a guest
May 5th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. `#ifndef SOCIALNETWORK_H_INCLUDED
  2. #define SOCIALNETWORK_H_INCLUDED
  3. #include <string>
  4. #include <vector>
  5.  
  6. class User;
  7. class Post;
  8. class PublicPost;
  9. class PrivatePost;
  10. class TimeLine;
  11.  
  12. class Post{
  13.  
  14. //User taggedFriend;
  15. public:
  16. std::string content;
  17. Post();
  18. void set_content(std::string content);
  19. std::string get_content();
  20. virtual void PostOnFreindsWall(){};
  21. virtual void PostOnNewsFeed(){};
  22. };
  23.  
  24. class PublicPost : public Post{
  25. public:
  26. PublicPost();
  27. void PostOnNewsFeed();
  28. };
  29.  
  30. class PrivatePost : public Post{
  31. public:
  32. PrivatePost();
  33. void PostOnFriendsFeed(User &taggedFriend);
  34. };
  35.  
  36. class TimeLine{
  37.  
  38. public:
  39. std::vector <Post> posts;
  40. TimeLine();
  41. void ClearTimeLine ();
  42. void DisplayTimeLine ();
  43. };
  44.  
  45. class User{
  46. private:
  47. std::string dateOfBirth;
  48. int postCode;
  49. std::string gender;
  50. std::string email;
  51. std::string country;
  52. std::string city;
  53. std::string userName;
  54. std::string password;
  55. public:
  56. TimeLine timeline;
  57. Post myPost;
  58. std::string firstName;
  59. std::string lastName;
  60. std::vector <User> friends;
  61. User();
  62. void setInfo();
  63. std::string get_firstName() const;
  64. std::string get_lastName() const;
  65. std::string get_dateOfBirth() const;
  66. int get_postCode() const;
  67. std::string get_gender() const;
  68. std::string get_email() const;
  69. std::string get_country() const;
  70. std::string get_city() const;
  71. std::string get_userName() const;
  72. std::string get_password() const;
  73. void displayUserDetails() const;
  74. void updateUserDetails();
  75. void add_friend(User& add);
  76. bool check_if_friend(User& check);
  77. };
  78.  
  79.  
  80. #endif // SOCIALNETWORK_H_INCLUDED
  81. `
  82.  
  83. #include <iostream>
  84. #include <cstdlib>
  85. #include <string>
  86. #include <vector>
  87. #include "SocialNetwork.h"
  88.  
  89. using namespace std;
  90.  
  91. Post::Post()
  92. {
  93. content ="nothing";
  94. }
  95. void Post::set_content(string content1)
  96. {
  97. content=content1;
  98. }
  99. string Post::get_content()
  100. {
  101. return content;
  102. }
  103.  
  104. PublicPost::PublicPost()
  105. {
  106. }
  107. void PublicPost::PostOnNewsFeed()
  108. {
  109. TimeLine.posts.push_back(content);
  110. }
  111.  
  112. PrivatePost::PrivatePost()
  113. {
  114. }
  115. void PrivatePost::PostOnFreindsWall(User &taggedFriend)
  116. {
  117. taggedFriend.timeline.posts.push_back(content);
  118. }
  119.  
  120. TimeLine::TimeLine()
  121. {
  122. }
  123.  
  124. void TimeLine::DisplayTimeLine()
  125. {
  126. for(int i=0; i<posts.size();i++){
  127. cout<<posts[i].content<<endl;
  128. }
  129. }
  130. void TimeLine::ClearTimeLine()
  131. {
  132. for(int i=0; i<posts.size();i++){
  133. posts.pop_back();
  134. }
  135. }
  136.  
  137.  
  138. void*/
  139.  
  140. User::User()
  141. {
  142. firstName="none";
  143. lastName="none";
  144. dateOfBirth="none";
  145. postCode=0;
  146. gender="none";
  147. email="none";
  148. country="none";
  149. city="none";
  150. userName="none";
  151. password="none";
  152. cout<<"in user constructor";
  153. }
  154.  
  155. void User::setInfo()
  156. {
  157. string firstName1;
  158. cout<<"Enter first name"<<endl;
  159. cin>>firstName1;
  160. firstName = firstName1;
  161. string lastName1;
  162. cout<<"Enter last name"<<endl;
  163. cin>>lastName1;
  164. lastName = lastName1;
  165. string dateOfBirth1;
  166. cout<<"Enter date of birth in format dd/mm/yy"<<endl;
  167. cin>>dateOfBirth1;
  168. dateOfBirth = dateOfBirth1;
  169. int postCode1;
  170. cout<<"Enter post code"<<endl;
  171. cin>>postCode1;
  172. postCode = postCode1;
  173. string gender1;
  174. cout<<"Enter gender"<<endl;
  175. cin>>gender1;
  176. gender = gender1;
  177. string email1;
  178. cout<<"Enter email"<<endl;
  179. cin>>email1;
  180. email = email1;
  181. string country1;
  182. cout<<"Enter country"<<endl;
  183. cin>>country1;
  184. country = country1;
  185. string city1;
  186. cout<<"Enter city"<<endl;
  187. cin>>city1;
  188. city = city1;
  189. string userName1;
  190. cout<<"Enter User name"<<endl;
  191. cin>>userName1;
  192. userName = userName1;
  193. string password1;
  194. cout<<"Enter password"<<endl;
  195. cin>>password1;
  196. password = password1;
  197. }
  198.  
  199. string User::get_firstName() const
  200. {
  201. return firstName;
  202. }
  203. string User::get_lastName() const
  204. {
  205. return lastName;
  206. }
  207.  
  208. string User::get_dateOfBirth() const
  209. {
  210. return dateOfBirth;
  211. }
  212.  
  213. int User::get_postCode() const
  214. {
  215. return postCode;
  216. }
  217.  
  218. string User::get_gender() const
  219. {
  220. return gender;
  221. }
  222.  
  223. string User::get_email() const
  224. {
  225. return email;
  226. }
  227.  
  228. string User::get_country() const
  229. {
  230. return country;
  231. }
  232.  
  233. string User::get_city() const
  234. {
  235. return city;
  236. }
  237.  
  238. string User::get_userName() const
  239. {
  240. return userName;
  241. }
  242.  
  243. string User::get_password() const
  244. {
  245. return password;
  246. }
  247.  
  248. void User::displayUserDetails() const
  249. {
  250. cout<<"Name: "<<firstName<<" "<<lastName<<endl;
  251. cout<<"Date of Birth: "<<dateOfBirth<<endl;
  252. cout<<"Post Code: "<<postCode<<endl;
  253. cout<<"Gender: "<<gender<<endl;
  254. cout<<"Email: "<<email<<endl;
  255. cout<<"Country: "<<country<<endl;
  256. cout<<"City: "<<city<<endl;
  257. }
  258.  
  259. void User::updateUserDetails()
  260. {
  261. int a;
  262. cout<<"Select which information you want to update"<<endl;
  263. cout<<"1.First Name"<<endl;
  264. cout<<"2.Last Name"<<endl;
  265. cout<<"3.Date of Birth"<<endl;
  266. cout<<"4.Post Code"<<endl;
  267. cout<<"5.Gender"<<endl;
  268. cout<<"6.Email"<<endl;
  269. cout<<"7.Country"<<endl;
  270. cout<<"8.City"<<endl;
  271. cout<<"9.Change password"<<endl;
  272. cin>>a;
  273. if(a==1){
  274. string b;
  275. cout<<"Enter first name: ";
  276. cin>>b;
  277. firstName=b;
  278. }
  279. if(a==2){
  280. string b;
  281. cout<<"Enter last name: ";
  282. cin>>b;
  283. lastName=b;
  284. }
  285. if(a==3){
  286. string b;
  287. cout<<"Enter date of birth: ";
  288. cin>>b;
  289. dateOfBirth=b;
  290. }
  291. if(a==4){
  292. int b;
  293. cout<<"Enter post code: ";
  294. cin>>b;
  295. postCode=b;
  296. }
  297. if(a==5){
  298. string b;
  299. cout<<"Enter gender: ";
  300. cin>>b;
  301. gender=b;
  302. }
  303. if(a==6){
  304. string b;
  305. cout<<"Enter email: ";
  306. cin>>b;
  307. email=b;
  308. }
  309. if(a==7){
  310. string b;
  311. cout<<"Enter country: ";
  312. cin>>b;
  313. country=b;
  314. }
  315. if(a==8){
  316. string b;
  317. cout<<"Enter city: ";
  318. cin>>b;
  319. city=b;
  320. }
  321. if(a==9){
  322. string b;
  323. cout<<"Enter new password: ";
  324. cin>>b;
  325. password=b;
  326. }
  327. }
  328.  
  329.  
  330. void User::add_friend(User &add)
  331. {
  332. friends.push_back(add);
  333. for(int i=0;i<friends.size();i++)
  334. cout<<friends[i].firstName<<endl;
  335. }
  336.  
  337. bool User::check_if_friend(User& checkfriend)
  338. {
  339. bool if_friend=false;
  340. for(int i=0; i<friends.size(); i++)
  341. {
  342. if(checkfriend.firstName==friends[i].firstName)
  343. {
  344. cout<<"Yes "<<checkfriend.firstName<<" is your friend" <<endl;
  345. if_friend = true;
  346. break;
  347. }
  348. }
  349. if(if_friend==false)
  350. {
  351. cout<<"No "<<checkfriend.firstName<<"is not your friend"<<endl;
  352. }
  353. return if_friend;
  354.  
  355. }
  356.  
  357. #include <iostream>
  358. #include "SocialNetwork.h"
  359.  
  360. using namespace std;
  361.  
  362. //User AllUsers[10];
  363.  
  364. int main()
  365. {
  366. cout<<endl;
  367. User Superman;
  368. User Batman;
  369. User Deadpool;
  370. User Spiderman;
  371. cout<<endl;
  372. cout<<"USER INFORMATION FOR FIRST USER"<<endl;
  373. Superman.setInfo();
  374. cout<<endl;
  375. cout<<"USER INFORMATION FOR SECOND USER"<<endl;
  376. Batman.setInfo();
  377. cout<<endl;
  378. cout<<"USER INFORMATION FOR THIRD USER"<<endl;
  379. Deadpool.setInfo();
  380. cout<<endl;
  381. cout<<"USER INFORMATION FOR FOURTH USER"<<endl;
  382. Spiderman.setInfo();
  383.  
  384. //Making all 4 users friends of each other
  385. Batman.add_friend(Superman);
  386. Batman.add_friend(Deadpool);
  387. Batman.add_friend(Spiderman);
  388. Superman.add_friend(Batman);
  389. Superman.add_friend(Deadpool);
  390. Superman.add_friend(Spiderman);
  391. Deadpool.add_friend(Batman);
  392. Deadpool.add_friend(Superman);
  393. Deadpool.add_friend(Spiderman);
  394. Spiderman.add_friend(Superman);
  395. Spiderman.add_friend(Deadpool);
  396. Spiderman.add_friend(Batman);
  397.  
  398. Post newPost;
  399. newPost.set_content("Hello");
  400. Superman.myPost = newPost;
  401. Superman.myPost.PostOnNewsFeed();
  402. Superman.timeline.DisplayTimeLine();
  403.  
  404. return 0;
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement