Question

Usage Usage: sna inputFile userName outputFile Requirements Summary Create a program that will re...

Usage Usage: sna inputFile userName outputFile Requirements Summary Create a program that will read in the text file containing graph specification of Twitter account followers and write to the output a list of all users within a depth of 3 of the specified root user (the user specified from the userName command line argument), that are not already being followed by that user. The program should be able to create the directed graph from the input file and output the results according to the In-Degree of Centrality. Assignment Name The assignment name for this assignment is: sna 1. Social Network Analysis and Common Metrics As social networking is becoming more and more popular among people, there is a growing interest in the study of extracting information from these networks, the so-called social network analysis (SNA). The usage of social network analysis, however, is far beyond that of Facebook or Twitter. The principle of SNA can be applied to other things; such as, finding the source and flow of an infectious disease, and scheduling the optimal production-market distribution for a globalized company. The basic structure of SNA is a graph. To evaluate the characteristics of a graph and the nodes inside, people gradually develop a set of metrics, some of them are: Degree of Centrality In an undirected graph, the degree centrality of a node i (denoted by CD(i)) is the node degree (number of edges), denoted by deg (i). CD(i) = deg (i) Centrality captures “how connected" a node is in general. In a directed graph, the degree of centrality comes in two types: the in-degree centrality and the out-degree centrality. The in-degree centrality is number of edges that end at the node (i.e., the number of edges going to the node). The out-degree centrality is the number edges starting at the node (i.e., the number of edges leaving the node). 2. Dataset Description: Twitter accounts and their friends The inputFile will consist of real Twitter accounts with their friends and for each friend his/hers friends etc. By using this data build up a graph and calculate the In-Degree of Centrality for each user. The input file will have the following format: github john_stewart github microsoft microsoft oracle Each line contains two usernames separated by three spaces. Each username is no longer than 15 characters and contain only alphanumeric characters (letters A-Z,a-z, numbers 0-9) with the exception of underscores. The two columns define the relationship between two accounts. The user in the second column is following the user in the first column. Thus, this is a directed graph. For an empty file, a file that does not have the correct format, or if the specified userName is not found, the program should create an empty output file. You can also assume that the input graph will be connected. Starting at any node, your program will be able to visit all other nodes using a breadth-first or depth-first search, or a variant thereof. 3. Task Decomposition Define User class and read input file Define a User class representing each node in the graph. For this class there are some essential concepts that must be captured:  name: store a username  followers: other users following this account  following: other users that this account is following The created User class objects need to be stored properly. Decide a way to store this list of all users from input data sets; class definitions are up to you, but the fundamental structure will reflect a directed graph with nodes and edges. Calculate the in-Degree centrality Calculate the in-degree centrality for all users. Using the following relationship, the program should find all users within a depth of 3 from the specified root user who are not already followed by the specified root user. Write results to output file The program should create the outputFile consisting of a list of all the users within a depth of 3 of the specified root user, that are not already being followed by that user. The list should be printed in descending order of in-degree of centrality. In case of ties, the users should be output alphabetically by username (case-insensitive). The outputFile should have the following format. inDegreeofCentrality should be output using the default precision. Looking for new accounts for userName (inDegreeofCentrality) to follow userName1 (inDegreeofCentrality) userName2 (inDegreeofCentrality) 4. Alpha Submission For the alpha submission, submit a complete project that reads in the data, creates the directed graph, and calculates the in-degree of centrality for all users. Then print to the output file the following single line with the specified root users in-degree centrality. inDegreeofCentrality should be output using the default precision. Looking for new accounts for userName (inDegreeofCentrality) to follow

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

The below is the required code for the given problem. In the below code See how you can able to defile User class, read input file and extract usernames to create list of users, adds followers to a user. Once this users list is created, you can create an adjacency matrix to define which account is connected to whom and that matrix can be used to count the required no. of users.

Code:-

1. User.h:

#ifndef USER_H_
#define USER_H_

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

class User {
private:
   string name;
   vector<User> followers;
   vector<User> following;
public:
   User(string name="");
   virtual ~User();
   const vector<User>& getFollowers() const;
   const vector<User>& getFollowing() const;
   const string& getName() const;
   void addFollower(User user);
   void addFollowing(User user);
   int getFollowersCount();
   int getFollowingCount();
};

#endif /* USER_H_ */

2. User.cpp:

#include "User.h"
User::User(string name) {
   this->name = name;
   //cout<<this->followers.size()<<endl;
}
const vector<User>& User::getFollowers() const {
   return followers;
}
const vector<User>& User::getFollowing() const {
   return following;
}
const string& User::getName() const {
   return name;
}
void User::addFollower(User user)
{
   this->followers.push_back(user);
}
void User::addFollowing(User user)
{
   this->following.push_back(user);
}
int User::getFollowersCount()
{
   return this->followers.size();
}
int User::getFollowingCount()
{
   return this->following.size();
}
User::~User() {
}

3. inputFile.txt:

github   john_stewart
github   microsoft
microsoft   oracle

4. main() function:

#include <iostream>
#include <fstream>
#include <sstream>
#include "User.h"


using namespace std;

int main() {
   vector<User> users; //list of users
   int numUsers = 0;
   string inputFileName = "./inputFile.txt";
   ifstream infile(inputFileName.c_str());
   if(!infile)
   {
       cerr<<"ERROR:Unable to open or read"<<inputFileName<<endl;
       cout<<"Aborting...";
       return -1;
   }
   string line="";
   while(getline(infile,line))
   {
       //cout<<line<<endl;
       stringstream ss(line);
       string username1,username2;
       bool existing1 = false,existing2=false;
       ss>>username1;
       for(vector<User>::iterator it=users.begin();it!=users.end();++it)
       {
           if((string)(it->getName())==username1)
           {
               cout<<"existing..."<<username1<<endl;
               existing1 = true;
               break;
           }
       }
       User user1(username1);
       if(existing1 == false)       {

           users.push_back(user1);
           cout<<"Added:"<<username1<<endl;
           numUsers++;
       }
       ss>>username2;
       for(vector<User>::iterator it=users.begin();it!=users.end();++it)
       {
           if((string)(it->getName())== username2)
           {
               cout<<"existing..."<<username2<<endl;
               existing2 = true;
               break;
           }
       }
       User user2(username2);
       if(existing2 == false)
       {
           users.push_back(user2);
           cout<<"Added:"<<username2<<endl;
           numUsers++;
       }
       user1.addFollower(user2);
       ss.clear();
   }
   infile.close();
   return 0;
}

5. Sample output:

Added:github
Added:john_stewart
existing...github
Added:microsoft
existing...microsoft
Added:oracle

If you find difficulty to understand the code, please let me know in comments tab below, Then I will provide another code or else i will any modifications in the present code. Hope it will helps you. Please give Thumbs Up!! Thank you for posting the question, All the best.

Add a comment
Know the answer?
Add Answer to:
Usage Usage: sna inputFile userName outputFile Requirements Summary Create a program that will re...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • How to solve my code for my Deliv C program?

    ProgramIntro.pngProgramIntro2.pngProgramIntro1.pngProgram1.pngProgram2.pngGraph Class:import java.util.ArrayList;//Graph is a class whose objects represent graphs. public class Graph {    ArrayList<Node> nodeList;    ArrayList<Edge> edgeList;       public Graph() {        nodeList = new ArrayList<Node>();        edgeList = new ArrayList<Edge>();       }       public ArrayList<Node> getNodeList() {        return nodeList;   }   public ArrayList<Edge> getEdgeList() {        return edgeList;   }   public void addNode(Node n) {        nodeList.add(n);   }   public void addEdge(Edge e) {        edgeList.add(e);   }   public String...

  • How can I solved my Java Program for DelivC

    //Graph Class: import java.util.ArrayList; //Graph is a class whose objects represent graphs.  public class Graph {     ArrayList<Node> nodeList;     ArrayList<Edge> edgeList;         public Graph() {         nodeList = new ArrayList<Node>();         edgeList = new ArrayList<Edge>();         }         public ArrayList<Node> getNodeList() {         return nodeList;    }    public ArrayList<Edge> getEdgeList() {         return edgeList;    }    public void addNode(Node n) {         nodeList.add(n);    }    public void addEdge(Edge e) {         edgeList.add(e);    }    public String toString() {         String s = "Graph g.\n";         if (nodeList.size() > 0) {             for (Node n : nodeList) {         // Print node info         String t = "\nNode " + n.getName() + ", abbrev " + n.getAbbrev() + ", value " + n.getVal() + "\n";         s = s.concat(t);         }         s = s.concat("\n");             }         return s;     }  } // Node Class: import java.util.ArrayList;  // Node is a class whose objects represent nodes (a.k.a., vertices) in the graph.  public class Node {    String name;     String val; // The value of the Node     String abbrev; // The abbreviation for the Node     ArrayList<Edge> outgoingEdges;     ArrayList<Edge> incomingEdges;             String color; //Create the color of the TYPE Node List     int start; //Create the Starting Time     int end; //Create the Ending Time             public Node( String theAbbrev ) {         setAbbrev( theAbbrev );         val = null;         name = null;         outgoingEdges = new ArrayList<Edge>();         incomingEdges = new ArrayList<Edge>();     }         public String getAbbrev() {         return abbrev;     }         public String getName() {         return name;     }         public String getVal() {         return val;     }         public ArrayList<Edge> getOutgoingEdges() {         return outgoingEdges;     }         public ArrayList<Edge> getIncomingEdges() {         return incomingEdges;...

  • Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS...

    Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS algorithm. Your program should read an input file name and determine if the input graph is a DAG (= directed acyclic graph) or not. If the graph is not a DAG, your program has to stop without further processing. However, if it’s a DAG, your program should display the starting node(s), popping-off order, and topologically sorted list. In the problem, you can assume that...

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

  • Please provide C language code no c++ ,txt file also needed with comment Finish task 5...

    Please provide C language code no c++ ,txt file also needed with comment Finish task 5 Task5: Breadth First Search (15 pts) · Write a program to read the graph information from the file and traverse the graph using BFS algorithm as introduced in lecture. The input for each algorithm is an undirected unweighted connected graph stored in a local file using an adjacency list. Following is the example of the input file (graph.txt) and the graph First line is...

  • Heres what I have so far: /* Preprocessor directives */ #include <stdio.h> #include <math.h> #define pi...

    Heres what I have so far: /* Preprocessor directives */ #include <stdio.h> #include <math.h> #define pi 3.14159 #define inputfile "c:\\engr 200\\oil_explore.txt" #define outputfile "c:\\engr 200\\oil_report.txt" /* Main function */ int main(void) { /* Declare variables */ double ratio, depth, ideal_charge, length, weight, number_sticks, wellsite; int i; FILE *explore, *report;    /* Open input file */ explore = fopen(inputfile,"r"); report = fopen(outputfile,"w"); /* Verify input file */ if(explore == NULL) { printf("\n\nERROR OPENING INPUT FILE\n\nPROGRAM TERMINATED\n\n"); return 0; } /* Read...

  • Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a...

    Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a linked list data structure. Gives the user the following options:                         1. To create and add the first node to a linked list.          2. To add a single node to the pre-existing linked list.             The list must already exist before a new node can be added.            The nodes should be maintained in ascending order based on the data value within the nodes...

  • How can I get started in this program for this DelivC?

    SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...

  • Update the program in the bottom using C++ to fit the requirements specified in the assignment....

    Update the program in the bottom using C++ to fit the requirements specified in the assignment. Description For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text of either one of the inputs is “quit”, the program should immediately exit. If “quit” is not found, each of these lines of input will be treated as a command line to be executed. These...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT