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
Notice that the percentages range from just over 55% to just under 65%. This is a range of 10%, so we're going to use 5 evenly-s
vfiekz [6]

Answer:

import numpy as np

l_int = 55/100

h_int = 65/100

hist = np.histogram( paid_tax_preparers_list, bins=5, range=(l_int, h_int))

Explanation:

Numpy is a Python package used to ease mathematical and statistical research calculations. The package creates data structures called arrays that can be used as vector items, making it easy and fast for calculation to be done.

The np.histogram method is used to create or plot histograms of a list or array against the frequency of the items in the array. The bins and the range attributes are used to adjust the display of the histogram, with bins being the number of bin in the graph and range is the given length of the histogram.

7 0
2 years ago
The IntList class contains code for an integer list class. Study it; notice that the only things you can do are: create a list o
torisob [31]

Explanation:

public class Int_List

{

protected int[] list;

protected int numEle = 0;

 

public Int_List( int size )

{

list = new int[size];

public void add( int value )

{

if ( numEle == list.length )

{

System.out.println( "List is full" );

}

else

{

list[numEle] = value;

numEle++;

}

}

public String toString()

{

String returnStr = "";

for ( int x = 0; x < numEle; x++ )

{

returnStr += x + ": " + list[x] + "\n";

}

return returnStr;

}

}

public class Run_List_Test

{

public static void main( String[] args )

{

 

Int_List myList = new Int_List( 7 );

myList.add( 102 );

myList.add( 51 );

myList.add( 202 );

myList.add( 27 );

System.out.println( myList );

}

}

Note: Use appropriate keyword when you override "tostring" method

8 0
2 years ago
How to trigger watchers on initialization in vue.js ?
ale4655 [162]

Answer:

variable when the component is mounted. This triggers the watchers which then triggers an emit i have in the watcher. I do not want the emit to happen when the variable is only being initialized. The variable is from the data section of the vue component.

3 0
2 years ago
If a database is not maintained or if incorrect data is entered into the database, serious problems can occur. What problems cou
Archy [21]

Database is maintained by keeping only relevant data and updating existing data in a timely manner.

This is achieved by issuing proper insert, update and delete operations.

Incorrect data leads to incomplete information. Databases which hold transaction details, any inaccuracies lead to misinformation to its users.

Both the above lead to serious issues in data maintenance and prove the database ineffective. This indicates manhandling of the database.

No maintenance

Database is maintained when only relevant information is present. Irrelevant information includes information like information of past students, old information of current students, etc.

For students who have completed their courses and left, the database should be updated by removing data of such students.

Also, for newly enrolled students, their enrolment should reflect in the official records.

In case of changes in any of the student information, timely update operations should be performed to keep only current data in the database.

All these operations should be done timely in order to avoid any discrepancies in the real data and updated data in the system.

Incorrect data

In situations where incorrect data is input in the student database, incorrect data will be recorded for that particular student. Incorrect data can be related to ssn, name, address, course details and fees payment.

In case of incorrect transaction details like fees payment, this incorrect data will reflect in the student record as well as will affect the overall earnings of the school.

For enrolled students, correct enrollment details regarding the course and classroom should be recorded. Any error in this data will cause the student inconvenience and the respective student will be at loss.

Also, taking advantage of this situation, any outsider acting as an enrolled student, can gain access to the school.

This leads to mismatch of information and can lead to fraud situations against the educational institute.

3 0
3 years ago
A free-frame list Select one: a. is a set of all frames that are used for stack and heap memory. b. is a set of all frames that
zhuklara [117]

Answer:

b. is a set of all frames that are currently unallocated to any process

Explanation:

The free frame list is the list that used for all kind of the frames that presently non-allocated to any kind or process

Therefore as per the given situation, the correct option is b as it fits to the current situation

Hence, all the other options are wrong

So, only option b is correct

The same is to be considered

7 0
3 years ago
Other questions:
  • Which of these statements regarding mobile games is true? A. They are typically played indoors. B. They have detailed environmen
    7·1 answer
  • A site structure that contains multiple links to individual pages, allowing visitors to go through multiple paths to the site is
    9·1 answer
  • Jill is setting up a presentation and wants to use a built-in equation, such as the area of a triangle. To insert this in her pr
    14·2 answers
  • Nielsen purchases scanner data from retail transactions to track the sales of consumer packaged goods, gathered at the point of
    14·1 answer
  • Which of the following statements is true?A)Implicit data type conversion is performed when you mix values of different data typ
    5·1 answer
  • Maria is comparing her history project's second-place award to her classmate's first-place award. She starts planning how to win
    9·2 answers
  • 1.
    13·1 answer
  • What is the main advantage that a website builder offers for web development?
    9·2 answers
  • Wyjaśnij w jaki sposób wykonuje się nitowanie zakładkowe i nakładkowe, oraz wyjaśnij na czym polega pasowanie mieszane.
    7·1 answer
  • What are some things you think are worthwhile and are willing to work harder to accomplish? Check all that apply.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!