Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `#ifndef SOCIALNETWORK_H_INCLUDED
- #define SOCIALNETWORK_H_INCLUDED
- #include <string>
- #include <vector>
- class User;
- class Post;
- class PublicPost;
- class PrivatePost;
- class TimeLine;
- class Post{
- //User taggedFriend;
- public:
- std::string content;
- Post();
- void set_content(std::string content);
- std::string get_content();
- virtual void PostOnFreindsWall(){};
- virtual void PostOnNewsFeed(){};
- };
- class PublicPost : public Post{
- public:
- PublicPost();
- void PostOnNewsFeed();
- };
- class PrivatePost : public Post{
- public:
- PrivatePost();
- void PostOnFriendsFeed(User &taggedFriend);
- };
- class TimeLine{
- public:
- std::vector <Post> posts;
- TimeLine();
- void ClearTimeLine ();
- void DisplayTimeLine ();
- };
- class User{
- private:
- std::string dateOfBirth;
- int postCode;
- std::string gender;
- std::string email;
- std::string country;
- std::string city;
- std::string userName;
- std::string password;
- public:
- TimeLine timeline;
- Post myPost;
- std::string firstName;
- std::string lastName;
- std::vector <User> friends;
- User();
- void setInfo();
- std::string get_firstName() const;
- std::string get_lastName() const;
- std::string get_dateOfBirth() const;
- int get_postCode() const;
- std::string get_gender() const;
- std::string get_email() const;
- std::string get_country() const;
- std::string get_city() const;
- std::string get_userName() const;
- std::string get_password() const;
- void displayUserDetails() const;
- void updateUserDetails();
- void add_friend(User& add);
- bool check_if_friend(User& check);
- };
- #endif // SOCIALNETWORK_H_INCLUDED
- `
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <vector>
- #include "SocialNetwork.h"
- using namespace std;
- Post::Post()
- {
- content ="nothing";
- }
- void Post::set_content(string content1)
- {
- content=content1;
- }
- string Post::get_content()
- {
- return content;
- }
- PublicPost::PublicPost()
- {
- }
- void PublicPost::PostOnNewsFeed()
- {
- TimeLine.posts.push_back(content);
- }
- PrivatePost::PrivatePost()
- {
- }
- void PrivatePost::PostOnFreindsWall(User &taggedFriend)
- {
- taggedFriend.timeline.posts.push_back(content);
- }
- TimeLine::TimeLine()
- {
- }
- void TimeLine::DisplayTimeLine()
- {
- for(int i=0; i<posts.size();i++){
- cout<<posts[i].content<<endl;
- }
- }
- void TimeLine::ClearTimeLine()
- {
- for(int i=0; i<posts.size();i++){
- posts.pop_back();
- }
- }
- void*/
- User::User()
- {
- firstName="none";
- lastName="none";
- dateOfBirth="none";
- postCode=0;
- gender="none";
- email="none";
- country="none";
- city="none";
- userName="none";
- password="none";
- cout<<"in user constructor";
- }
- void User::setInfo()
- {
- string firstName1;
- cout<<"Enter first name"<<endl;
- cin>>firstName1;
- firstName = firstName1;
- string lastName1;
- cout<<"Enter last name"<<endl;
- cin>>lastName1;
- lastName = lastName1;
- string dateOfBirth1;
- cout<<"Enter date of birth in format dd/mm/yy"<<endl;
- cin>>dateOfBirth1;
- dateOfBirth = dateOfBirth1;
- int postCode1;
- cout<<"Enter post code"<<endl;
- cin>>postCode1;
- postCode = postCode1;
- string gender1;
- cout<<"Enter gender"<<endl;
- cin>>gender1;
- gender = gender1;
- string email1;
- cout<<"Enter email"<<endl;
- cin>>email1;
- email = email1;
- string country1;
- cout<<"Enter country"<<endl;
- cin>>country1;
- country = country1;
- string city1;
- cout<<"Enter city"<<endl;
- cin>>city1;
- city = city1;
- string userName1;
- cout<<"Enter User name"<<endl;
- cin>>userName1;
- userName = userName1;
- string password1;
- cout<<"Enter password"<<endl;
- cin>>password1;
- password = password1;
- }
- string User::get_firstName() const
- {
- return firstName;
- }
- string User::get_lastName() const
- {
- return lastName;
- }
- string User::get_dateOfBirth() const
- {
- return dateOfBirth;
- }
- int User::get_postCode() const
- {
- return postCode;
- }
- string User::get_gender() const
- {
- return gender;
- }
- string User::get_email() const
- {
- return email;
- }
- string User::get_country() const
- {
- return country;
- }
- string User::get_city() const
- {
- return city;
- }
- string User::get_userName() const
- {
- return userName;
- }
- string User::get_password() const
- {
- return password;
- }
- void User::displayUserDetails() const
- {
- cout<<"Name: "<<firstName<<" "<<lastName<<endl;
- cout<<"Date of Birth: "<<dateOfBirth<<endl;
- cout<<"Post Code: "<<postCode<<endl;
- cout<<"Gender: "<<gender<<endl;
- cout<<"Email: "<<email<<endl;
- cout<<"Country: "<<country<<endl;
- cout<<"City: "<<city<<endl;
- }
- void User::updateUserDetails()
- {
- int a;
- cout<<"Select which information you want to update"<<endl;
- cout<<"1.First Name"<<endl;
- cout<<"2.Last Name"<<endl;
- cout<<"3.Date of Birth"<<endl;
- cout<<"4.Post Code"<<endl;
- cout<<"5.Gender"<<endl;
- cout<<"6.Email"<<endl;
- cout<<"7.Country"<<endl;
- cout<<"8.City"<<endl;
- cout<<"9.Change password"<<endl;
- cin>>a;
- if(a==1){
- string b;
- cout<<"Enter first name: ";
- cin>>b;
- firstName=b;
- }
- if(a==2){
- string b;
- cout<<"Enter last name: ";
- cin>>b;
- lastName=b;
- }
- if(a==3){
- string b;
- cout<<"Enter date of birth: ";
- cin>>b;
- dateOfBirth=b;
- }
- if(a==4){
- int b;
- cout<<"Enter post code: ";
- cin>>b;
- postCode=b;
- }
- if(a==5){
- string b;
- cout<<"Enter gender: ";
- cin>>b;
- gender=b;
- }
- if(a==6){
- string b;
- cout<<"Enter email: ";
- cin>>b;
- email=b;
- }
- if(a==7){
- string b;
- cout<<"Enter country: ";
- cin>>b;
- country=b;
- }
- if(a==8){
- string b;
- cout<<"Enter city: ";
- cin>>b;
- city=b;
- }
- if(a==9){
- string b;
- cout<<"Enter new password: ";
- cin>>b;
- password=b;
- }
- }
- void User::add_friend(User &add)
- {
- friends.push_back(add);
- for(int i=0;i<friends.size();i++)
- cout<<friends[i].firstName<<endl;
- }
- bool User::check_if_friend(User& checkfriend)
- {
- bool if_friend=false;
- for(int i=0; i<friends.size(); i++)
- {
- if(checkfriend.firstName==friends[i].firstName)
- {
- cout<<"Yes "<<checkfriend.firstName<<" is your friend" <<endl;
- if_friend = true;
- break;
- }
- }
- if(if_friend==false)
- {
- cout<<"No "<<checkfriend.firstName<<"is not your friend"<<endl;
- }
- return if_friend;
- }
- #include <iostream>
- #include "SocialNetwork.h"
- using namespace std;
- //User AllUsers[10];
- int main()
- {
- cout<<endl;
- User Superman;
- User Batman;
- User Deadpool;
- User Spiderman;
- cout<<endl;
- cout<<"USER INFORMATION FOR FIRST USER"<<endl;
- Superman.setInfo();
- cout<<endl;
- cout<<"USER INFORMATION FOR SECOND USER"<<endl;
- Batman.setInfo();
- cout<<endl;
- cout<<"USER INFORMATION FOR THIRD USER"<<endl;
- Deadpool.setInfo();
- cout<<endl;
- cout<<"USER INFORMATION FOR FOURTH USER"<<endl;
- Spiderman.setInfo();
- //Making all 4 users friends of each other
- Batman.add_friend(Superman);
- Batman.add_friend(Deadpool);
- Batman.add_friend(Spiderman);
- Superman.add_friend(Batman);
- Superman.add_friend(Deadpool);
- Superman.add_friend(Spiderman);
- Deadpool.add_friend(Batman);
- Deadpool.add_friend(Superman);
- Deadpool.add_friend(Spiderman);
- Spiderman.add_friend(Superman);
- Spiderman.add_friend(Deadpool);
- Spiderman.add_friend(Batman);
- Post newPost;
- newPost.set_content("Hello");
- Superman.myPost = newPost;
- Superman.myPost.PostOnNewsFeed();
- Superman.timeline.DisplayTimeLine();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement