Question: I need help modifying a program I previously created Previous code: #include using namespace std; // struct representing a data type for class struct Profile

I need help modifying a program I previously created

Previous code:

#include  using namespace std; // struct representing a data type for class struct Profile { string username; int age; string state; bool operator==(Profile other) { return(username == other.username && age == other.age && state == other.state); } }; // overload operator<< for printing ostream& operator<<(ostream& out, const Profile& profile) { out << "Name : " << profile.username << " Age : " << profile.age << " State : " << profile.state; return out; } // generic class template  class Twitter { T user; T followers[5]; int num_follower; public: Twitter(T user); void AddFollower(T person); bool RemoveFollower(T person); void PrintFollower(); }; template  Twitter::Twitter(T user) { this->user = user; num_follower = 0; } template  void Twitter::AddFollower(T person) { if (num_follower < 5) { followers[num_follower] = person; num_follower++; } } template  bool Twitter::RemoveFollower(T person) { for (int i = 0;i < num_follower;i++) { if (followers[i] == person) { for (int j = i + 1;j < num_follower;j++) followers[j - 1] = followers[j]; num_follower--; return true; } } return false; } template  void Twitter::PrintFollower() { for (int i = 0;i < num_follower;i++) cout << followers[i] << endl; } int main() { Twitter twitter1("Kyle Tolle"); twitter1.AddFollower("Jessi Gray"); twitter1.AddFollower("Hunter Bond"); twitter1.AddFollower("Mallory Davis"); cout << " Followers : " << endl; twitter1.PrintFollower(); cout << " Updated Followers : " << endl; twitter1.RemoveFollower("Jessi Gray"); twitter1.PrintFollower(); Profile profile; profile.username = "Mickey Mouse"; profile.age = 25; profile.state = "Florida"; Twitter twitter2(profile); Profile profile1; profile1.username = "Daniel Smith"; profile1.age = 21; profile1.state = "California"; Profile profile2; profile2.username = "Max Frey"; profile2.age = 31; profile2.state = "Colorado"; Profile profile3; profile3.username = "Maddie Hanson"; profile3.age = 21; profile3.state = "Alaska"; twitter2.AddFollower(profile1); twitter2.AddFollower(profile2); twitter2.AddFollower(profile3); cout << " Followers : " << endl; twitter2.PrintFollower(); twitter2.RemoveFollower(profile2); cout << " Updated Followers : " << endl; twitter2.PrintFollower(); return 0; }

I now need is to be so that your followers should be stored in an Array object. Initialization needs to with the constructor with an array object of size 2. . Instead of working with a fixed size array, it should change the size of the array when it is full or only a small portion of the current capacity is used.

Therefore, it should use changeSize() function inside addFollower() and

removeFollower() functions.

a. should call changeSize() to double the size when the array is full.

b. should call changeSize() to cut the array into half if less than 25% of the array is being utilized.

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 Programming Questions!