Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hey guys, Need help making a class (called facebook) that has the first facebook

ID: 3785138 • Letter: H

Question


hey guys,
Need help making a class (called facebook)

that has the first facebook user, which will be friended, and has them add up to 10 different
friends.

I believe I can make the friends in a string or Profile^1.

Main program: Has to delete any user from the list of friends. I think I can store them in an array with
the max of 10 in there. Then we want a function that can print all the friends.
I need to be able to call that function even after we remove friends.

-Class template in the main program
-Need a constructor that starts for a friend user or the number of friends.
-A "AddFriend" function.
-A "RemoveFriend" function
   (This will requrie an operator overloader if the user and array member are equal to each other)
-A "PrintFriend" Function


thanks for any help

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
const int SIZE = 5;
template <class Type>
class Facebook
{
        public:
                Facebook();
                ~Facebook();
                void AddFriend(Type item);
                void RemoveFriend(Type item);
                void PrintFriend();
        private:
                Type *A;
                Type word;
                int count;
};

template <class Type>
Facebook<Type>::Facebook()// constructor initilize the default value
{
        count = 0;
        A = new Type[SIZE];
}

template <class Type>
Facebook<Type>::~Facebook() // desctructor
{
        delete[] A;
        count = 0;
        A = 0;
}

template <class Type>
void Facebook<Type>::AddFriend(Type item) // add element to array and increament the array size
{
        if (count<SIZE)
        {
                A[count++] = item;
        }
        else
        {
                cout << "The array is full. ";
        }
}

template <class Type>
void Facebook<Type>::RemoveFriend(Type item)
{
        int i;
        word = item;
        for (i = 0; i < count; i++)
        {
                if (item == A[i]) // find the matching name and remove with element shifting
                {
                        for(int j=i; j<count; j++)
                                A[j]= A[i+1];
                        count--; // decreament the array size
                }
        }
}

template <class Type>
void Facebook<Type>::PrintFriend()
{
        int i;

        for (i = 0; i<count; i++)
        {
                cout << "A[" << i << "] = " << A[i] << endl;
        }
}
int main()
{
        Facebook<string> FriendsList;
        FriendsList.AddFriend("Jack");
        FriendsList.AddFriend("Mark");
        FriendsList.AddFriend("Abcd");
        FriendsList.PrintFriend();
        cout << endl;
        FriendsList.RemoveFriend("Abcd");

        FriendsList.PrintFriend();
        return 0;
}