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
Which of the following commands uses correct syntax for matching the patterns bunk or bank at the end of a line of text?
Alika [10]

Answer:

a. grep 'b[au]nk$' myLine

Explanation:

grep is a command used for searching a specified pattern in a given text.

Our goal is to match the character sequence - bank or bunk at the end of line in a  given line referenced by myLine.

The regular expression for the specified match criterion is:

b[au]nk$

The second character can be either a or u.

$ indicates match at end of line.

So the overall grep command is :

grep 'b[au]nk$' myLine

8 0
3 years ago
3. Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(i
never [62]

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char num1[20],num2[20],num3[20],num4[20];

//Checks where the conversion of string to long stops and is required by strtol

char *ptr;

//Stores the converted number string into long.

long result_num1,result_num2,result_num3,result_num4;

//Prompt to enter all the four hexadecimal numbers.

printf("Enter the first hexadecimal number: ");

scanf("%s",num1);

printf("Enter the second hexadecimal number: ");

scanf("%s",num2);

printf("Enter the third hexadecimal number: ");

scanf("%s",num3);

printf("Enter the fourth hexadecimal number: ");

scanf("%s",num4);

//Converting the hexadecimal numbers into long using strtol() function with base 16 for hexadecimal.

result_num1 = strtol(num1,&ptr,16);

result_num2 = strtol(num2,&ptr,16);

result_num3 = strtol(num3,&ptr,16);

result_num4 = strtol(num4,&ptr,16);

//Casting the long to unsigned chars.

unsigned char numb1 = (unsigned char)result_num1;

unsigned char numb2 = (unsigned char)result_num2;

unsigned char numb3 = (unsigned char)result_num3;

unsigned char numb4 = (unsigned char)result_num4;

//Applying the boolean operation on unsigned chars and storing the resultant value in result.

unsigned char result = ((numb1&numb2)|numb3)^numb4;

//Printing the result in capital hex ("%X" take care of this).

printf("%X",result);

return 0;

}

Code OUTPUT

Enter the first hexadecimal number: 1 Enter the second hexadecimal number:2

Enter the third hexadecimal number: 3 Enter the fourth hexadecimal number: 4 Resultant Value: 7 Process returned o (0×0) execution time : 3.076 s

Press any key to continue

4 0
3 years ago
Which variable name is the best to hold the area of a rectangle?<br> 1A<br> area<br> AREA<br> a
Fantom [35]

Answer:

Area

Explanation:

The variable name is the best to hold the area of a rectangle is area

plz give brainliest

3 0
4 years ago
Give a common business example that mimics the differences between a shared
Serhud [2]

An  business example that mimics the differences between a shared network segment and a dedicated network segment is that of connection of work station transmission.

<h3>What is Shared segment network?</h3>

In this type of network,  local area network or an aspect of the local area network is said to have a lot of workstations and the multiple workstations are linked by using a hub

Note that all the workstation do not need to share the network capacity with other workstations but  an  business example that mimics the differences between a shared network segment and a dedicated network segment is that of connection of work station transmission.

Learn more about network segment from

brainly.com/question/7181203

#SPJ1

6 0
2 years ago
Why is it important to carefully order events in a personal narrative?
Anna11 [10]

Why is it important to carefully order events in a personal narrative? because it strengthens the effect the beginning will have on readers, enabling them to relate to the experience because sequencing events in a way that makes sense will keep readers engaged and enable the story to have a strong impact because it will help the ending make more sense if the beginning and the middle are well written with many sensory details because the beginning sets the stage for everything that will be shown first

Hope this helps :)

3 0
4 years ago
Other questions:
  • Truck drivers probably cannot see your vehicle if you cannot
    6·2 answers
  • Which of the following are examples of how a company might use consumer data it had collected? a To decide what types of product
    10·1 answer
  • Let f be the following function: int f(char *s, char *t){char *p1, *p2;for(p1 = s, p2 = t; *p1 != ‘\0’&amp;&amp; *p2 != ‘\0’; p1
    6·1 answer
  • a webmaster can be hired as a contract labor for a company meaning they are not an employee of the company true or false
    5·2 answers
  • Explain what is meant by information technology (IT). Explain what is meant by information systems (IS). Why is it important to
    7·1 answer
  • You just bought a new hard drive for your computer to replace your primary hard drive. After backing your data up and, then, ins
    8·2 answers
  • Which componet is the smallest unit in a spreadsheet
    15·1 answer
  • All of the following are examples of software, except:
    5·2 answers
  • Please help i have 15 mins
    5·1 answer
  • Which one of the following does NOT contain a
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!