Question
for the above input the output should be values: 12 5 4 7 6 2 13 1 18 15 54 17 38 85 92 37
for the above input the output should be
values: 12 5 4 7 6 2 13 1 18 15 54 17 38 85 92 37 29 20 rowPos: 0 2 3 5 8 9 -1 12 -1 15 colPos: 2 4 6 1 8 2 6 7 8 1 7 9 3 5 8 0 1 8 Most influential user: 8 Most active user: 7 Users ranked by Influentiality: 8 5 7 1 3 0 6 9 2 4 Users ranked by Activity: 7 5 9 4 0 3 2 1 6 8 CRM Object Destroyed!!
You will create a class named CRM (using the given template file) that has fields for the three arrays. The class will have several methods, including finding the most influential user (i.e., the user whose posts have been retweeted the most times), finding the most active user (i.e., the user who has made the largest number of retweets), ranking the users in a descending order based on how influential they are, as well as ranking them based on how active they are. The latter two methods should compute a vector of all users, sorted according to their ranking. In case of ties, you can rank the users in ascending order of their id (i.e., 0, 1, 2, 3, ...). All input will be read via redirected input. That is, you should not open a file inside the program.
Your program should be given as input a matrix in the format that was illustrated in the example above. Please refer to the sample input and output files given, and make sure to follow these formats exactly. The CRM class structure should be as shown in the provided template file (you are responsible for filling-in the code that is missing where ___ is placed, as well as for fixing any syntax errors!). We have provided code for a few methods, and you need to make sure that they work correctly. You will also write code for other methods needed. The structure of your main program is also provided, and you should use that in your project
here is the template
#include using namespace std; class CRM { protected: int n; //The number rows of the original matrix int m; //The number of columns of the original matrix int nonZeros; //The number of non-zero elements in the original matrix int* values; //Array that contains all non-zero values of the matrix, assuming they are all integers int* rowPos; //Array that for each row of the original matrix contains the position in the values matrix in which the first non-zero element of this row is stored. int* colPos; //Array that contains the column number for each one of the non-zero values in the original matrix. //There may be others you may need public: CRM ( ); //default or empty constructor CRM (int rows, int cols, int numNonZeros); int getNumRows ( ); void addValue (int value); //add a new value in the values array void addRow (int row); //add a row number in the rowPos array void addColumn (int col);//add a column number in the colPos array void display (); //print the contents of the three arrays. Each array must be on a different line (separated by a /ew line character) and you have exactly a single space between each value printed. int mostInfluentialUser(); //find the most influential user int mostActiveUser(); //find the most active user int* influentialUsers (); //compute vector of users ranked by how much influential they are int* activeUsers (); //compute vector of users ranked by how much active they are ~CRM(); //destructor //You may define and use any other method you need }; //some of the methods Katia Papakonstantinopoulou CRM::CRM ( ) { n = 0; m = 0; values = NULL; rowPos = NULL; colPos = NULL; } CRM::CRM (int rows, int cols, int numNonZeros) { n = rows; m = cols; nonZeros = numNonZeros; values = new int [nonZeros]; rowPos = new int [n]; colPos = new int [nonZeros]; } int CRM::mostInfluentialUser(){ //fill in the code }; int* CRM::influentialUsers (){ int* outputVector = new int [n]; for (int i=0; i
//fill in the code return outputVector; } CRM::~CRM ( ) { if (values != NULL) delete [ ] values; if (rowPos != NULL) delete [ ] rowPos; if (colPos != NULL) delete [ ] colPos; cout > numRows >> numColumns; cin >> numNonZeros; A = new CRM (numRows, numColumns, numNonZeros); for (int i=0; i > row >> col >> value; (*A).addValue (value); (*A).addRow (row);/eeds to be done cleverly in the method (*A).addColumn (col); } (*A).display ( ); //Find most influential user int mostInf = (*A).mostInfluentialUser (); cout
cout
please just comment your code to explain how it works, I have it almost working on my end but cant iron out the kinks. Thank you.
In this project we deal with handling sparse matrices. We are interested in nxn matrices that represent the 'retweets' that take place among a set of n Twitter users. In particular, the element A[i,j] of matrix A represents the number of times user i has retweeted user j in a specific period. We store these matrices in a data structure called "Compact Retweet Matrix (CRM), which is explained in detail below. In this project you are asked to define this data structure in a class, together with a set of methods that operate on it. As an example, consider a set of 10 Twitter users and the following 10x10 matrix (consisting of 10 rows and 10 columns, each one numbered using integers from 0 to 9). The non-zero values are in red font just for the sake of clarity. 0 1 2 3 4 5 6 7 8 9 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 6 0 3 0 0 2 13 1 0 0 4 0 0 0 0 0 0 0 0 18 0 5 0 15 0 0 0 0 0 54 0 17 6 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 85 0 0 92 0 8 0 0 0 0 0 0 0 0 0 9 37 29 0 0 0 0 0 0 20 0 12 oo 1 4 O 2 0 0 0 ololo 7 o We consider the CRM as a triplet of arrays (values, rowPos, and colpos) which collectively include all the above information. In particular: The values array has size equal to the number of non-zero values in the matrix, and contains all these values, by the order they appear in the matrix. In the above matrix, there are 18 non-zero values. (The highlighting is used for the connection with the next array, please ignore it for now.) values array: 0 1 N 4 6 7 8 9 10 11 12 13 14 15 16 17 N00 12 5 4 7 7 6 6 N 13 1 18 15 54 17 38 85 92 37 29 20 The rowPos array has size equal to the number of users (10 in our case), and for each user it contains the position in values array in which the first nonzero value corresponding to this user appears. The highlighting colors are used in order to help you understand the relation between arrays rowPos and values. row Pos array: 0 1 2 0 2 8 9 3 5 4 8 5 9 6 -1 7 12 -1 Therefore, rowPos[0] = 0 indicates that the non-zero values in row 0 of the matrix start being stored at position 0 of the values array. Indeed, it is values[0]=12 and 12 is the first non-zero element in row (user) 0 of the matrix. Similarly, rowPos[1] = 2 indicates that the non-zero values in row 1 of the matrix start at index position 2 of the values array. Indeed, at index position 2 (i.e., values[2]), the value is 4 which is the first non-zero value in row 1. Therefore, the non-zero values of user 0 start from position 0 of the values array and extend up to position 1, since in position 2 we start storing the non-zero values of user 1, and hence they are 12 and 5. In the same spirit, rowPos[7] contains the value 12. This indicates that the first non-zero value in row 7 of the matrix can be found at values[12], which is 38. The non-zero values of user 9 extend from position 15 of the values array until, obviously, the end of it. We use -1 in the rowPos array to indicate the fact that a row does not contain any non-zero values. The colpos array has size equal to the number of non-zero values in the matrix (18 in our case), and for each such value it contains the column of the matrix in which it appears. colpos array: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 2 4 6 1 8 2 6 7 8 1 7 9 3 5 8 0 1 8 Your program should be reading a matrix and it should be storing it in a CRM data structure. Then it should be able to perform queries on this structure. INSTRUCTIONS AND GUIDELINES Input format: For the purposes of this project, when we give a matrix as an input, we will be providing that in the sparse format, i.e., a vector (row, col, value) for each non-zero value, indicating the row and column of the matrix in which this value appears. In the first line of the input, we give the total number of rows and the total number of columns of the matrix. For example, for the matrix above the input should be the following:Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started