Question: Write a C++ program following the instructions below (previous program is after the instructions, please complete as soon as possible, and thank you so much

Write a C++ program following the instructions below (previous program is after the instructions, please complete as soon as possible, and thank you so much in advance):

Write a C++ program following the instructions below (previous program is after

the instructions, please complete as soon as possible, and thank you so

much in advance): Previous Program: #include using namespace std; class Profile {

Previous Program:

#include

using namespace std;

class Profile {

private:

string username;

string displayname;

public:

Profile(string usrn, string dspn) {

username=usrn;

displayname=dspn;

}

Profile(){

username="";

displayname="";

}

string getUsername() {

return username;

}

string getFullName() {

return displayname + " (@" +username + ")";

}

void setDisplayName(string dspn){

displayname=dspn;

}

};

class Network {

private:

static const int MAX_USERS = 20;

int numUsers=0;

Profile profiles[MAX_USERS];

bool following[MAX_USERS][MAX_USERS];

int findID(string usrn){

for (int i=0; i

if (profiles[i].getUsername() == usrn) {

return i;

}

}

return -1;

}

public:

Network() {

for (int i=0; i

for (int j=0; j

following[i][j] = false;

}

}

}

bool addUser(string usrn, string dspn) {

Profile newUser(usrn, dspn);

if (numUsers

profiles[numUsers++] = newUser;

return true;

}

return false;

}

bool follow(string usrn1, string usrn2) {

int usrnID1 = findID(usrn1);

int usrnID2 = findID(usrn2);

if (usrnID1 != -1 && usrnID2 != -1) {

following[usrnID1][usrnID2] = true;

return true;

}

return false;

}

void printDot() {

cout

for (int i=0; i

cout

}

for (int i=0; i

for (int j=0; j

if(following[i][j]) {

cout \"@"

}

}

}

cout

}

};

int main() {

Network nw;

nw.addUser("mario", "Mario");

nw.addUser("luigi", "Luigi");

nw.addUser("yoshi", "Yoshi");

nw.follow("mario", "luigi");

nw.follow("mario", "yoshi");

nw.follow("luigi", "mario");

nw.follow("luigi", "yoshi");

nw.follow("yoshi", "mario");

nw.follow("yoshi", "luigi");

nw.addUser("wario", "Wario");

for (int i=2; i

string usrn = "mario" + to_string(i);

string dspn = "Mario" + to_string(i);

nw.addUser(usrn, dspn);

nw.follow(usrn, "mario");

}

nw.follow("mario2", "luigi");

nw.printDot();

}

Task D. Class Network : Posting (Bonus) Write a new program social4.cpp , which is an improved version of the previous program The class Network should be changed to allow users post messages and remember them. You should 1. (Outside the class Network ), define a new struct: struct Postf string username string message; l; 2. In the class Network , add private variables private: static const int MAX_POSTS- 100; int numPosts; Post posts [MAX POSTS]; 7number of posts /array of all posts 3. Modify constructor Network so that it initializes numPosts to O 4. Add two functions in the public interface of the class public: //Add a new post bool writePost(string usrn, string msg); Print user's "timeline" bool printTimeline(string usrn); The first function, writePost(usrn, msg) adds a new post to the posts array. It performs successfully if the username is found in the network and the posts array is not full, in this case the function also should return true . Otherwise, nothing is added and the function returns false The second function, printTimeline (usrn) prints out the timeline of the user usrn . The timeline of a user is the list of all posts by the user and by the people they follow, presented in reverse-chronological order. They should be printed in the following format: Displayname (eusername): message Displayname (eusername): message Displayname (srme): message Displayname (username) message To summarize, the final version of the class Network and struct Post declarations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!