1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aalyn [17]
3 years ago
10

Write a Twitter class that sets the Twitter user first (who is to be followed) and lets the client add up to 5 followers, which

will be stored in an array with a capacity of 5. These users/followers could be in the form of string or Profile. (Note that the followers are not stored as users, but as strings or Profiles).
At any time, your main program should be able to remove any user, x from following another user, y (i.e., x is no longer in the array of followers of y).
You are free to design your program as you wish as long as you fulfill the following requirements:
Twitter class should be declared as a template class (the template parameter defines how the followers are represented)
Twitter class includes a constructor that initializes the name of the user that is passed. The number of followers starts off at 0.
AddFollower function in Twitter class should be defined correctly. It takes as parameter an object of the template parameter.
RemoveFollower function in Twitter class should be defined correctly. It takes as parameter an object of the template parameter.
PrintFollowers function in Twitter class should be defined correctly. It displays the name of all the followers. (Remember: each follower is an object of the template parameter. As you will declare Profile struct which can be a template parameter, for the Profile struct, we must overload stream insertion << operator. Now, we can use cout << follower to display the follower).
Submitting a main program that tests the Twitter class as follows:
Twitter object
Twitter object
Whenever any change is made to a Twitter object (like a follower is added, a follower is removed), call PrintFollowers to display the followers of the Twitter object.
Computers and Technology
1 answer:
Rzqust [24]3 years ago
4 0

Answer:

Twitter.h

========

#ifndef Twitter_h

#define Twitter_h

#include <iostream>

using std::string;

using std::cout;

using std::endl;

template <typename T>

class Twitter

{

private:

string name;

T followers[5];

int numFollowers;

public:

Twitter(string n);

bool AddFollower(T follower);

bool RemoveFollower(T follower);

void PrintFollowers();

};

template <typename T>

Twitter<T>::Twitter(string n)

{

name = n;

numFollowers = 0;

}

template <typename T>

bool Twitter<T>::AddFollower(T follower)

{

if(numFollowers < 5)

{

followers[numFollowers] = follower;

numFollowers++;

return true;

}

else

return false;

}

template <typename T>

bool Twitter<T>::RemoveFollower(T follower)

{

int index;

bool found = false;

for(index = 0; index < numFollowers; index++)

{

if(followers[index] == follower)

{

found = true;

break;

}

}

if(found)

{

//shift all other followers after the one to be removed to one position left

for(++index; index < numFollowers; ++index)

{

followers[index-1] = followers[index];

}

numFollowers--;

return true;

}

else

return false;

}

template <typename T>

void Twitter<T>::PrintFollowers()

{

cout << "Followers for " << name << endl;

for(int i = 0; i < numFollowers; i++)

cout << followers[i] << endl;

 

cout << "------" << endl << endl;

}

#endif /* Twitter_h */

main.cpp

=========

#include "Twitter.h"

#include <iostream>

using namespace std;

struct Profile {

string userName;

int age;

string state;

};

 

ostream& operator << (ostream & output, Profile p) {

output << p.userName;

return output;

}

bool operator == (const Profile &p1, const Profile p2)

{

return p1.userName == p2.userName;

}

int main()

{

Twitter<string> t1("John");

Twitter<Profile> t2("Bob");

 

cout << "Adding followers to John" << endl;

t1.AddFollower("Bill");

t1.AddFollower("Jack");

t1.PrintFollowers();

 

Profile p1 = {"Alice", 20, "Alaska"};

Profile p2 = {"Janet", 22, "California"};

Profile p3 = {"Jim", 20, "Texas"};

 

cout << "Adding follower profiles to Bob" << endl;

t2.AddFollower(p1);

t2.AddFollower(p2);

t2.AddFollower(p3);

t2.PrintFollowers();

 

cout << "Removing Bill from John" << endl;

t1.RemoveFollower("Bill");

 

cout << "Removing Janet's profile from Bob" << endl << endl;

t2.RemoveFollower(p2);

 

t1.PrintFollowers();

t2.PrintFollowers();

 

 

 

}

output

-======

Adding followers to John

Followers for John

Bill

Jack

------

Adding follower profiles to Bob

Followers for Bob

Alice

Janet

Jim

------

Removing Bill from John

Removing Janet's profile from Bob

Followers for John

Jack

------

Followers for Bob

Alice

Jim

------

Explanation:

You might be interested in
The following pieces are known as (image shown above)
cestrela7 [59]

Answer:

Conjunction operators  

Explanation:

4 0
2 years ago
Read 2 more answers
A _____ is the viewing area for a web page, which is much smaller on a phone than on a traditional desktop.
-BARSIC- [3]
A viewport is the viewing area for a web page, which is much smaller on a phone than on a traditional desktop .
6 0
3 years ago
What are the three primary separation of concerns on the client-side of a dynamic web application? (Check all that apply)
nlexa [21]

Answer:

Behaviour

Style

Structure

Explanation:

Above are the three primary separation of concerns for a web application at client side.

Structure --> we can define the structure of the application at client side using HTML

style-->style is used to give some styling information like font,color,headings so on at client side .In general we use CSS to do this at client side

Behaviour--> it actually defines the functionality of the elements at client side like when we click button what it should do.We will use JavaScript to define the behaviours at client side

7 0
3 years ago
From your fist impression, write down what first comes to mind as to what is good and bad about the way the device works.
nalin [4]

Answer:

xczczxczx

Explanation:

6 0
3 years ago
Compare userNumber with compareNumber and display 'Numbers are not equal' if the numbers are different. Then, display 'Variables
masya89 [10]

Answer:

Following are attached images that will help you understand the complete code. The code is tested with different variables and different outputs are obtained. All the necessary description is given in the form o comments inside the code.

Explanation:

3 0
3 years ago
Other questions:
  • Find every number from 1 to n (inclusive) that is a palindrome which starts with the digit 3. Do not user a helper function.
    10·1 answer
  • Learning about public speaking can help improve your ________________.
    15·1 answer
  • Describe how to manipulate artwork in a presentation.
    13·1 answer
  • Write a Twitter class that sets the Twitter user first (who is to be followed) and lets the client add up to 5 followers, which
    10·1 answer
  • Which is an example of an incremental approach to solving a problem?
    15·1 answer
  • To discover how many cells in a range contain values that meet a single criterion, use the ___ function
    5·1 answer
  • Giusp minfg gấp vs ạ đáp án thôi nhé
    15·1 answer
  • What are the three algorithm constructs?
    7·1 answer
  • Suppose that you have declared a numeric array named numbers, and two of its elements are numbers[1] and numbers[4]. You know th
    10·1 answer
  • One of the most notable impacts of IT on business is improved
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!