Explain the flow of the code (Do not use flowchart). See attached photo for the problem. (This is not graded) bool add(entry* e) {         if(s->contains(e->country) == true)         {             return false;         }         int i;         for (i = 0; i < index; i++) {             entry* existing = array + (i * sizeof(entry)); // 0 + 0 * 5 = 0             if(e->compare(existing))             {                 break;             }         }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Explain the flow of the code (Do not use flowchart). See attached photo for the problem. (This is not graded)

bool add(entry* e) {
        if(s->contains(e->country) == true)
        {
            return false;
        }
        int i;
        for (i = 0; i < index; i++) {
            entry* existing = array + (i * sizeof(entry)); // 0 + 0 * 5 = 0
            if(e->compare(existing))
            {
                break;
            }
        }

        for (int j = index; j >= i; j--) {
             *(array + ( sizeof(entry) * (j) ) ) = *(array + ( sizeof(entry) * (j - 1) ) );
        }

        *(array + ( sizeof(entry) * i ) ) = *e;
        if(index < 5)
        {
            index++;
        }
        if(( sizeof(entry) * i ) < ( sizeof(entry) * 5 ))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    entry* get(int pos) {
        return array + (sizeof(entry) * (pos-1) );
    }
    
    bool ban_indefinitely(entry* e) {
        if(s->contains(e->country) == false)
        {
            s->add(e);
        }
        int temp = index;
        for (int i = 0; i < index; i++) {
            entry* existing = array + (sizeof(entry) * i);
            if (!strcmp(existing->country, e->country)) {
                for (int j = i; j < index - 1; j++) {
                    *(array + ( sizeof(entry) * (j) ) ) = *(array + ( sizeof(entry) * (j+1) ) );
                }
                index--;
                i--;
                }
            }
        if(temp != index)
        {
            return true;
        }
        
        return false;

    }

    bool unban(const char* nation) {
        if(s->contains(nation) == true)
        {
            s->remove(nation);
            return true;
        }
        return false;
    }
• bool add(entry* e)
Improve the add method where you will return true if the entry
has been successfully added (i.e. the entry is placed in the top
5), otherwise return false (i.e. if the entry did not make it to the
top 5 or this entry's nation has been banned).
Implement the following additional methods and make sure you
utilize the methods of the StringList field:
• bool ban_indefinitely(entry* e)
Removes all the entries in your BoardArray bearing the country
equal to the country of the given entry and also restricts future
additions bearing this country from ever being added by adding
this to the banned list. Return true if at least one entry has
been removed, otherwise return false.
• bool unban(const char* nation)
Unbans the said nation by removing it from the banned list.
Return true if the nation once exists in the banned list,
otherwise return false.
Transcribed Image Text:• bool add(entry* e) Improve the add method where you will return true if the entry has been successfully added (i.e. the entry is placed in the top 5), otherwise return false (i.e. if the entry did not make it to the top 5 or this entry's nation has been banned). Implement the following additional methods and make sure you utilize the methods of the StringList field: • bool ban_indefinitely(entry* e) Removes all the entries in your BoardArray bearing the country equal to the country of the given entry and also restricts future additions bearing this country from ever being added by adding this to the banned list. Return true if at least one entry has been removed, otherwise return false. • bool unban(const char* nation) Unbans the said nation by removing it from the banned list. Return true if the nation once exists in the banned list, otherwise return false.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY