Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify your HW1 in a way that your followers should be stored in an Array object (a dynamic array created by Array class). That means

Modify your HW1 in a way that your followers should be stored in an Array object (a dynamic array created by Array class). That means you should use the Array class we discussed in the class.

a. Do your initializations with the constructor. I recommend you to start with an Array object of size 2. 2.

Instead of working with a fixed size array, your program should change the size of the array when it is full or only a small portion of the current capacity is used. Therefore, you should use changeSize() function inside addFollower() and removeFollower() functions.

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

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

This is the code for hw#1. It is missing a constructor that does initialization for the followed user and number of followers, so please add one before starting:

#include #include "Twitter.h"

using namespace std;

struct Profile { string username; int age; string state; bool operator==(const Profile& p) const {//added this so that the operators in RemoveFollower function work return username == p.username && age == p.age && state == p.state; } };

// Overload the << operator for the Profile struct ostream& operator<<(ostream& os, const Profile& p) { os << "Username: " << p.username << endl; os << "Age: " << p.age << endl; os << "State: " << p.state << endl; return os; }

int main() { Twitter twitterStr; Twitter twitterProfile;

// Add followers to the string Twitter object /*twitterStr.AddFollower("User1"); twitterStr.AddFollower("User2"); twitterStr.AddFollower("User3"); twitterStr.AddFollower("User4"); twitterStr.AddFollower("User5"); twitterStr.AddFollower("User6"); This would prompt the "Follower list is full" output at the beginning, comment out for now

twitterStr.PrintFollowers(); cout<<" "<

// Add followers to the profile Twitter object Profile user1 = {"person1", 20, "NY"}; Profile user2 = {"person2", 40, "CA"}; Profile user3 = {"person3", 25, "FL"}; Profile user4 = {"person4", 15, "TX"}; Profile user5 = {"person5", 4, "MI"};

twitterProfile.AddFollower(user1); twitterProfile.AddFollower(user2); twitterProfile.AddFollower(user3); twitterProfile.AddFollower(user4); twitterProfile.AddFollower(user5);

// Remove a follower from the string Twitter object // twitterStr.RemoveFollower("User1"); //THIS PRINTS OUT THE FIRST LIST, WITHOUT PROFILES

// Remove a follower from the profile Twitter object twitterProfile.PrintFollowers(); cout<<" "<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions