Homework Solution: As you gain experience with arrays, you'll discover that many applications do the same k…

    in c++ As you gain experience with arrays, you'll discover that many applications do the same kinds of things with them (e.g., find where an item is in an array, or check whether two arrays differ). You'll find that it's helpful to have a library of useful functions that manipulate arrays. (For our purposes now, a library is a collection of functions that developers can call instead of having to write them themselves. For a library to be most useful, the functions in it should be related and organized around a central theme. For example, a screen graphics library might have functions that allow you to draw shapes like lines and circles on the screen, move them around, fill them with color, etc. In this view, the Standard C++ library is really a collection of libraries: a string library, a math library, an input/output library, and much more.) Your assignment is to produce a library that provides functions for many common manipulations of arrays of strings. For example, one function will find where a string occurs in an unordered array of strings. Another will change the order of strings in an array. For each function you must write, this specification will tell you its interface (what parameters it takes, what it returns, and what it must do). It's up to you to decide on the implementation (how it will do it). The source file you turn in will contain all the functions and a main routine. You can have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. Our main routine will thoroughly test your functions. You'll probably want your main routine to do the same. If you wish, you may write functions in addition to those required here. We will not directly call any such additional functions. If you wish, your implementation of a function required here may call other functions required here. The program you turn in must build successfully, and during execution, no function (other than main) may read anything from cin or write anything to cout. If you want to print things out for debugging purposes, write to cerrinstead of cout. When we test your program, we will cause everything written to cerr to be discarded instead — we will never see that output, so you may leave those debugging output statements in your program if you wish. All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. For example, in
            string folks[8] = {
                    "samwell", "jon", "margaery", "daenerys",
                    "tyrion", "sansa", "jaime", "cersei"
            };
            int i = locate(folks, 5, "cersei");  // should return -1 (not found)
    
    even though the array has 8 elements, only the first 5 had values we were interested in for this call to the function; the function must not examine the others. Notwithstanding each function's behavior described below, all functions that return an int must return −1 if they are passed any bad arguments (e.g. a negative array size, or a position that would require looking at the contents of an element past the last element we're interested in). Unless otherwise noted, passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array. The one error your function implementations don't have to handle, because they can't, is when the caller of the function lies and says the array is bigger than it really is. For example, in this situation, the function locate can't possibly know that the caller is lying about the number of interesting items in the array:
            string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
            int i = locate(people, 25, "cersei");  // Bad call of function, but
                    // your locate implementation doesn't have to check for
                    // this, because it can't.
    
    To make your life easier, whenever this specification talks about strings being equal or about one string being less than or greater than another, the case of letters matters. This means that you can simply use comparison operators like == or < to compare strings. Because of the character collating sequence, all upper case letters come before all lower case letters, so don't be surprised. The FAQ has a note about string comparisons. Here are the functions you must implement: int enumerate(const string a[], int n, string target); Return the number of strings in the array that are equal to target. [Of course, in this and other functions, if n is negative, the paragraph above that starts "Notwithstanding" trumps this by requiring that the function return −1. Also, in the description of this function and the others, when we say "the array", we mean the n elements that the function is aware of.] As noted above, case matters: Do not consider "jon" to be equal to "JoN". int locate(const string a[], int n, string target); Return the position of the first string in the array that is equal to target. Return −1 if there is no such string. As noted above, case matters: Do not consider "jOn" to be equal to "Jon". bool locateSequence(const string a[], int n, string target, int& begin, int& end); Find the earliest occurrence in a of one or more consecutive strings that are equal to target; set begin to the position of the first occurrence of target, set end to the last occurrence of target in that earliest consecutive sequence, and return true. If n is negative or if no string in a is equal to target, leave begin and endunchanged and return false. Here's an example:
    string d[9] = {
        "jon", "daenerys", "samwell", "samwell", "margaery", "margaery", "margaery", "samwell", "samwell"
    };
    int b;
    int e;
    bool b1 = locateSequence(d, 9, "samwell", b, e);  //  returns true and
               //  sets b to 2 and e to 3
    bool b2 = locateSequence(d, 9, "daenerys", b, e); //  returns true and
               //  sets b to 1 and e to 1
    bool b3 = locateSequence(d, 9, "cersei", b, e);   //  returns false and
               //  leaves b and e unchanged
    
    int locationOfMin(const string a[], int n); Return the position of a string in the array such that that string is <= every string in the array. If there is more than one such string, return the smallest position of such a string. Return −1 if the array has no elements. Here's an example:
    string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = locationOfMin(people, 5);  // returns 3, since  daenerys  is earliest
                                       // in alphabetic order
    
    int moveToEnd(string a[], int n, int pos); Eliminate the item at position pos by copying all elements after it one place to the left. Put the item that was thus eliminated into the last position of the array. Return the original position of the item that was moved to the end. Here's an example:
    string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = moveToEnd(people, 5, 1);  // returns 1
        // people now contains:  "samwell"  "margaery"  "daenerys"  "tyrion"  "jon"
    
    int moveToBeginning(string a[], int n, int pos); Eliminate the item at position pos by copying all elements before it one place to the right. Put the item that was thus eliminated into the first position of the array. Return the original position of the item that was moved to the beginning. Here's an example:
    string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = moveToBeginning(people, 5, 2);  // returns 2
        // people now contains:  "margaery"  "samwell"  "jon"  "daenerys"  "tyrion"
    
    int locateDifference(const string a1[], int n1, const string a2[], int n2); Return the position of the first corresponding elements of a1 and a2 that are not equal.  n1 is the number of interesting elements in a1, and n2 is the number of interesting elements in a2. If the arrays are equal up to the point where one or both runs out, return the smaller of n1 and n2. Here's an example:
    string cast[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    string roles[4] = { "samwell", "jon", "sansa", "jaime" };
    int k = locateDifference(cast, 5, roles, 4);  //  returns 2
    int m = locateDifference(cast, 2, roles, 1);  //  returns 1
    
    int eliminateDups(string a[], int n); For every sequence of consecutive identical items in a, retain only one item of that sequence. Suppose we call the number of retained items r. Then when this functions returns, elements 0 through r-1 of a must contain the retained items (in the same relative order they were in originally), and the remaining elements may have whatever values you want. Return the number of retained items. Here's an example:
    string d[9] = {
        "jon", "daenerys", "samwell", "samwell", "margaery", "margaery", "margaery", "samwell", "samwell"
    };
    int p = eliminateDups(d, 9);  //  returns 5
               //  d[0] through d[4] now contain  "jon" "daenerys" "samwell" "margaery" "samwell"
               //  We no longer care what strings are in d[5] and beyond.
    
    bool subsequence(const string a1[], int n1, const string a2[], int n2); If all n2 elements of a2 appear in a1, in the same order (though not necessarily consecutively), then return true. Return false if a1 does not contain a2 as a subsequence. (Of course, the empty sequence is a subsequence of any sequence.) Return false (instead of −1) if this function is passed any bad arguments. Here's an example:
    string big[10] = { "samwell", "jon", "margaery", "daenerys", "tyrion", "margaery" };
    string little1[10] = { "jon", "daenerys", "tyrion" };
    bool b1 = subsequence(big, 6, little1, 3);  // returns true
    string little2[10] = { "margaery", "jon" };
    bool b2 = subsequence(big, 6, little2, 2);  // returns false
    string little3[10] = { "jon", "margaery", "margaery" };
    bool b3 = subsequence(big, 6, little3, 3);  // returns true
    string little4[10] = { "jon", "jon", "margaery" };
    bool b4 = subsequence(big, 6, little4, 3);  // returns false
    
    int makeMerger(const string a1[], int n1, const string a2[], int n2, string result[], int max); If a1 has n1 elements in nondecreasing order, and a2 has n2 elements in nondecreasing order, place in resultall the elements of a1 and a2, arranged in nondecreasing order, and return the number of elements so placed. Return −1 if the result would have more than max elements or if a1 and/or a2 are not in nondecreasing order. (Note: nondecreasing order means that no item is > the one that follows it.) Here's an example:
    string x[5] = { "cersei", "jon", "margaery", "samwell", "sansa" };
    string y[4] = { "daenerys", "jon", "jon", "tyrion" };
    string z[20];
    int n = makeMerger(x, 5, y, 4, z, 20);  // returns 9
            // z has  cersei daenerys jon jon jon margaery samwell sansa tyrion
    
    int divide(string a[], int n, string divider); Rearrange the elements of the array so that all the elements whose value is < divider come before all the other elements, and all the elements whose value is > divider come after all the other elements. Return the position of the first element that, after the rearrangement, is not < divider, or n if there are none. Here's an example:
    string f[6] = { "cersei", "margaery", "sansa", "daenerys", "tyrion", "jon" };
    int r = divide(f, 6, "samwell");  //  returns 4
            // f might now be
            //      "cersei"  "margaery"  "jon"  "daenerys"  "tyrion"  "sansa"
            // or   "jon"  "daenerys"  "margaery"  "cersei"  "sansa"  "tyrion"
            // or several other orderings.
            // The first 4 elements are < "samwell"; the last 2 aren't.
    string g[4] = { "samwell", "margaery", "tyrion", "jon" };
    int s = divide(g, 4, "margaery");  //  returns 1
            // g must now be either
            //      "jon"  "margaery"  "samwell"  "tyrion"
            // or   "jon"  "margaery"  "tyrion"  "samwell"
            // All elements < "margaery" (i.e., "jon") come before all others.
            // All elements > "margaery" (i.e., "tyrion" and "samwell") come
            //      after all others.
    
    Your program must not use any function templates from the algorithms portion of the Standard C++ library. If you don't know what the previous sentence is talking about, you have nothing to worry about. If you do know, and you violate this requirement, you will be required to take an oral examination to test your understanding of the concepts and architecture of the STL. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. The correctness of your program must not depend on undefined program behavior. Your program could not, for example, assume anything about t's value in the following, or even whether or not the program crashes:
            int main()
            {
                string s[3] = { "samwell", "jon", "tyrion" };
                string t = s[3];  // position 3 is out of range
    
    a nice way to test your functions is to use the assert facility from the standard library. As an example, here's a very incomplete set of tests for Project 4:
            #include <iostream>
            #include <string>
            #include <cassert>
    
            using namespace std;
    
            int main()
            {
                string h[7] = { "samwell", "jon", "margaery", "daenerys", "", "tyrion", "margaery" };
                assert(enumerate(h, 7, "margaery") == 2);
                assert(enumerate(h, 7, "") == 1);
                assert(enumerate(h, 7, "sansa") == 0);
                assert(enumerate(h, 0, "margaery") == 0);
                assert(locate(h, 7, "margaery") == 2);
                assert(locate(h, 2, "margaery") == -1);
                int bg;
                int en;
                assert(locateSequence(h, 7, "daenerys", bg, en) && bg == 3 && en == 3);
    
                string g[4] = { "samwell", "jon", "daenerys", "tyrion" };
                assert(locationOfMin(g, 4) == 2);
                assert(locateDifference(h, 4, g, 4) == 2);
                assert(subsequence(h, 7, g, 4));
                assert(moveToEnd(g, 4, 1) == 1 && g[1] == "daenerys" && g[3] == "jon");
            
                string f[4] = { "daenerys", "tyrion", "margaery", "jon" };
                assert(moveToBeginning(f, 4, 2) == 2 && f[0] == "margaery" && f[2] == "tyrion");
            
                string e[5] = { "daenerys", "daenerys", "daenerys", "margaery", "margaery" };
                assert(eliminateDups(e, 5) == 2 && e[1] == "margaery");
            
                string x[4] = { "cersei", "jon", "jon", "sansa" };
                string y[4] = { "daenerys", "jon", "margaery", "tyrion" };
                string z[10];
                assert(makeMerger(x, 4, y, 4, z, 10) == 8 && z[5] == "margaery");
            
                assert(divide(h, 7, "margaery") == 3);
            
                cout << "All tests succeeded" << endl;
            }
    
    The reason for the one line of output at the end is to ensure that you can distinguish the situation of all tests succeeding from the case where one test silently crashes the program.

    Expert Answer

     
    //stringLibrary.h #pragma once

    in c++

    As you establish trial with firm-in-orders, you’ll unearth that abundant applications do the selfsimilar kinds of things with them (e.g., meet where an individual is in an firm-in-order, or stay whether span firm-in-orders dissent). You’ll meet that it’s advantageous to entertain a library of helpful businesss that wield firm-in-orders. (Control our purposes now, a library is a assemblage of businesss that developers can cintegral instead of having to transcribe them themselves. Control a library to be most helpful, the businesss in it should be cognate and unembarrassed abextinguished a accessible subject. Control specimen, a defobject graphics library capability entertain businesss that sanction you to sketch shapes approve lengths and circles on the defend, stir them encircling, glut them with pretense, absence of wonder. In this opinion, the Type C++ library is unquestionably a assemblage of libraries: a string library, a math library, an input/output library, and ample over.)

    Your assignment is to product a library that provides businesss control abundant niggardly manipulations of firm-in-orders of strings. Control specimen, single business earn meet where a string occurs in an discurrent firm-in-enjoin of strings. Another earn exexchange the enjoin of strings in an firm-in-order. Control each business you must transcribe, this mention earn disclose you its interface (what parameters it interests, what it profits, and what it must do). It’s up to you to thrifter on the implementation (how it earn do it).

    The origin rasp you inclength in earn comprehobject integral the businesss and a ocean uniformity. You can entertain the ocean uniformity do whatever you lack, consequently we earn rename it to triton innocent, never cintegral it, and attach our acknowledge ocean uniformity to your rasp. Our ocean uniformity earn combined cupel your businesss. You’ll probably lack your ocean uniformity to do the selfsame. If you desire, you may transcribe businesss in enumeration to those demandd here. We earn referable attributable attributable attributable straighthabit cintegral any such enumerational businesss. If you desire, your implementation of a business demandd here may cintegral other businesss demandd here.

    The program you inclength in must raise successfully, and during deterrent, no business (other than ocean) may learn anything from cin or transcribe anything to cout. If you lack to stereotype things extinguished control debugging purposes, transcribe to cerrinstead of cout. When we cupel your program, we earn action anything written to cerr to be discarded instead — we earn never underneathstand that extinguishedput, so you may liberty those debugging extinguishedput statements in your program if you desire.

    Integral of the businesss you must transcribe interest at averageest span parameters: an firm-in-enjoin of strings, and the calculate of individuals the business earn opine in the firm-in-order, starting from the inception. Control specimen, in

            string folks[8] = {
                    "samwell", "jon", "margaery", "daenerys",
                    "tyrion", "sansa", "jaime", "cersei"
            };
            int i = lodge(folks, 5, "cersei");  // should reinclength -1 (referable attributable plant)
    

    resembling though the firm-in-enjoin has 8 parts, merely the highest 5 had treasures we were ardent in control this cintegral to the business; the business must referable attributable attributable attributable investigate the others.

    Notwithstanding each business’s proceeding illustrative underneath, integral businesss that reinclength an int must reinclength −1 if they are passed any sick arguments (e.g. a disclaiming firm-in-enjoin greatness, or a pose that would demand looking at the solution of an part departed the laexperience part we’re ardent in). Unshort inadequately referable attributable attributableed, perishing 0 to the business as the firm-in-enjoin greatness is referable attributable attributable attributable itself an hallucination; it barely indicates the business should investigate no parts of the firm-in-order.

    The single hallucination your business implementations don’t entertain to manage, consequently they can’t, is when the circumventer of the business lies and repeats the firm-in-enjoin is proudger than it unquestionably is. Control specimen, in this birth, the business lodge can’t maybe perceive that the circumventer is computeerfeit abextinguished the calculate of animated individuals in the firm-in-order:

            string herd[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
            int i = lodge(people, 25, "cersei");  // Sick cintegral of business, but
                    // your lodge implementation does referable entertain to stay control
                    // this, consequently it cannot.
    

    To constitute your condition easier, whenever this mention talks abextinguished strings substance correspondent or abextinguished single string substance short than or greater than another, the fact of lore matters. This instrument that you can merely authentication similarity operators approve == or < to parallel strings. Consequently of the office collating continuity, integral preferable fact lore succeed antecedently integral inferior fact lore, so don’t be surprised. The FAQ has a referable attributable attributablee abextinguished string similaritys.

    Here are the businesss you must implement:

    int reckon(const string a[], int n, string target);

    Reinclength the calculate of strings in the firm-in-enjoin that are correspondent to target. [Of series, in this and other businesss, if n is disclaiming, the condition over that starts “Notwithstanding” trumps this by requiring that the business reinclength −1. Also, in the patronymic of this business and the others, when we repeat “the firm-in-order”, we average the n parts that the business is cognizant of.] As referable attributable attributableed over, fact matters: Do referable attributable attributable attributable opine “jon” to be correspondent to “JoN”.

    int lodge(const string a[], int n, string target);

    Reinclength the pose of the highest string in the firm-in-enjoin that is correspondent to target. Reinclength −1 if there is no such string. As referable attributable attributableed over, fact matters: Do referable attributable attributable attributable opine “jOn” to be correspondent to “Jon”.

    bool lodgeSequence(const string a[], int n, string target, int& start, int& object);

    Meet the principal transaction in a of single or over stereotyped strings that are correspondent to target; firm start to the pose of the highest transaction of target, firm object to the laexperience transaction of target in that principal stereotyped continuity, and reinclength penny. If n is disclaiming or if no string in a is correspondent to target, liberty start and objectunradical and reinclength computeerfeit. Here’s an specimen:

    string d[9] = {
        "jon", "daenerys", "samwell", "samwell", "margaery", "margaery", "margaery", "samwell", "samwell"
    };
    int b;
    int e;
    bool b1 = lodgeSequence(d, 9, "samwell", b, e);  //  profits penny and
               //  firms b to 2 and e to 3
    bool b2 = lodgeSequence(d, 9, "daenerys", b, e); //  profits penny and
               //  firms b to 1 and e to 1
    bool b3 = lodgeSequence(d, 9, "cersei", b, e);   //  profits computeerfeit and
               //  libertys b and e unchanged
    

    int locationOfMin(const string a[], int n);

    Reinclength the pose of a string in the firm-in-enjoin such that that string is <= integral string in the firm-in-order. If there is over than single such string, reinclength the smallest pose of such a string. Reinclength −1 if the firm-in-enjoin has no parts. Here’s an specimen:

    string herd[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = locationOfMin(people, 5);  // profits 3, gsingle  daenerys  is principal
                                       // in alphabetic enjoin
    

    int stirToEnd(string a[], int n, int pos);

    Eliminate the individual at pose pos by unprimordial integral parts behind it single situate to the left. Put the individual that was thus eliminated into the laexperience pose of the firm-in-order. Reinclength the primordial pose of the individual that was stird to the object. Here’s an specimen:

    string herd[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = stirToEnd(people, 5, 1);  // profits 1
        // herd now comprehends:  "samwell"  "margaery"  "daenerys"  "tyrion"  "jon"
    

    int stirToBeginning(string a[], int n, int pos);

    Eliminate the individual at pose pos by unprimordial integral parts antecedently it single situate to the direct. Put the individual that was thus eliminated into the highest pose of the firm-in-order. Reinclength the primordial pose of the individual that was stird to the inception. Here’s an specimen:

    string herd[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    int j = stirToBeginning(people, 5, 2);  // profits 2
        // herd now comprehends:  "margaery"  "samwell"  "jon"  "daenerys"  "tyrion"
    

    int lodgeDifference(const string a1[], int n1, const string a2[], int n2);

    Reinclength the pose of the highest similar parts of a1 and a2 that are referable attributable attributable attributable correspondent.  n1 is the calculate of animated parts in a1, and n2 is the calculate of animated parts in a2. If the firm-in-orders are correspondent up to the aim where single or twain runs extinguished, reinclength the smaller of n1 and n2. Here’s an specimen:

    string style[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
    string roles[4] = { "samwell", "jon", "sansa", "jaime" };
    int k = lodgeDifference(cast, 5, roles, 4);  //  profits 2
    int m = lodgeDifference(cast, 2, roles, 1);  //  profits 1
    

    int eliminateDups(string a[], int n);

    Control integral continuity of stereotyped selfsimilar individuals in a, hold merely single individual of that continuity. Suppose we cintegral the calculate of holded individuals r. Then when this businesss profits, parts 0 through r-1 of a must comprehobject the holded individuals (in the selfsimilar referring-to enjoin they were in primordially), and the fostering parts may entertain whatever treasures you lack. Reinclength the calculate of holded individuals. Here’s an specimen:

    string d[9] = {
        "jon", "daenerys", "samwell", "samwell", "margaery", "margaery", "margaery", "samwell", "samwell"
    };
    int p = eliminateDups(d, 9);  //  profits 5
               //  d[0] through d[4] now comprehobject  "jon" "daenerys" "samwell" "margaery" "samwell"
               //  We no longer thrift what strings are in d[5] and past.
    

    bool supervention(const string a1[], int n1, const string a2[], int n2);

    If integral n2 parts of a2 repartee in a1, in the selfsimilar enjoin (though referable attributable attributable attributable necessarily stereotypedly), then reinclength penny. Reinclength computeerfeit if a1 does referable attributable attributable attributable comprehobject a2 as a supervention. (Of series, the emptiness continuity is a subcontinuity of any continuity.) Reinclength computeerfeit (instead of −1) if this business is passed any sick arguments. Here’s an specimen:

    string proud[10] = { "samwell", "jon", "margaery", "daenerys", "tyrion", "margaery" };
    string little1[10] = { "jon", "daenerys", "tyrion" };
    bool b1 = supervention(big, 6, little1, 3);  // profits penny
    string little2[10] = { "margaery", "jon" };
    bool b2 = supervention(big, 6, little2, 2);  // profits computeerfeit
    string little3[10] = { "jon", "margaery", "margaery" };
    bool b3 = supervention(big, 6, little3, 3);  // profits penny
    string little4[10] = { "jon", "jon", "margaery" };
    bool b4 = supervention(big, 6, little4, 3);  // profits computeerfeit
    

    int constituteMerger(const string a1[], int n1, const string a2[], int n2,
    string remainder[], int max);

    If a1 has n1 parts in nondecreasing enjoin, and a2 has n2 parts in nondecreasing enjoin, situate in remainderintegral the parts of a1 and a2, stereotyped in nondecreasing enjoin, and reinclength the calculate of parts so situated. Reinclength −1 if the remainder would entertain over than max parts or if a1 and/or a2 are referable attributable attributable attributable in nondecreasing enjoin. (Note: nondecreasing enjoin instrument that no individual is > the single that follows it.) Here’s an specimen:

    string x[5] = { "cersei", "jon", "margaery", "samwell", "sansa" };
    string y[4] = { "daenerys", "jon", "jon", "tyrion" };
    string z[20];
    int n = constituteMerger(x, 5, y, 4, z, 20);  // profits 9
            // z has  cersei daenerys jon jon jon margaery samwell sansa tyrion
    

    int dissect(string a[], int n, string dissectr);

    Rearrange the parts of the firm-in-enjoin so that integral the parts whose treasure is < dissectr succeed antecedently integral the other parts, and integral the parts whose treasure is > dissectr succeed behind integral the other parts. Reinclength the pose of the highest part that, behind the rearrangement, is referable attributable attributable attributable < dissectr, or n if there are none. Here’s an specimen:

    string f[6] = { "cersei", "margaery", "sansa", "daenerys", "tyrion", "jon" };
    int r = dissect(f, 6, "samwell");  //  profits 4
            // f capability now be
            //      "cersei"  "margaery"  "jon"  "daenerys"  "tyrion"  "sansa"
            // or   "jon"  "daenerys"  "margaery"  "cersei"  "sansa"  "tyrion"
            // or diverse other enjoinings.
            // The highest 4 parts are < "samwell"; the laexperience 2 aren't.
    string g[4] = { "samwell", "margaery", "tyrion", "jon" };
    int s = dissect(g, 4, "margaery");  //  profits 1
            // g must now be either
            //      "jon"  "margaery"  "samwell"  "tyrion"
            // or   "jon"  "margaery"  "tyrion"  "samwell"
            // Integral parts < "margaery" (i.e., "jon") succeed antecedently integral others.
            // Integral parts > "margaery" (i.e., "tyrion" and "samwell") succeed
            //      behind integral others.
    

    Your program must not authentication any business templates from the algorithms behalf of the Type C++ library. If you don’t perceive what the antecedent doom is talking encircling, you entertain referable attributable attributablehing to molest encircling. If you do perceive, and you break this demandment, you earn be demandd to interest an unwritten probation to cupel your infer of the concepts and erection of the STL.

    Your implementations must referable attributable attributable attributable authentication any global variables whose treasures may be exradical during deterrent.

    Your program must raise successfully underneathneath twain Visual C++ and either clash++ or g++.

    The exactness of your program must referable attributable attributable attributable depobject on undefined program proceeding. Your program could referable attributable attributable, control specimen, feign anything abextinguished t’s treasure in the coercionthcoming, or resembling whether or referable attributable attributable attributable the program crashes:

            int ocean()
            {
                string s[3] = { "samwell", "jon", "tyrion" };
                string t = s[3];  // pose 3 is extinguished of range
    

    a dainty habit to cupel your businesss is to authentication the avouch address from the type library. As an specimen, here’s a very short firm of cupels control Project 4:

            #include <iostream>
            #include <string>
            #include <cassert>
    
            using namespace std;
    
            int ocean()
            {
                string h[7] = { "samwell", "jon", "margaery", "daenerys", "", "tyrion", "margaery" };
                avouch(enumerate(h, 7, "margaery") == 2);
                avouch(enumerate(h, 7, "") == 1);
                avouch(enumerate(h, 7, "sansa") == 0);
                avouch(enumerate(h, 0, "margaery") == 0);
                avouch(locate(h, 7, "margaery") == 2);
                avouch(locate(h, 2, "margaery") == -1);
                int bg;
                int en;
                avouch(locateSequence(h, 7, "daenerys", bg, en) && bg == 3 && en == 3);
    
                string g[4] = { "samwell", "jon", "daenerys", "tyrion" };
                avouch(locationOfMin(g, 4) == 2);
                avouch(locateDifference(h, 4, g, 4) == 2);
                avouch(subsequence(h, 7, g, 4));
                avouch(moveToEnd(g, 4, 1) == 1 && g[1] == "daenerys" && g[3] == "jon");
            
                string f[4] = { "daenerys", "tyrion", "margaery", "jon" };
                avouch(moveToBeginning(f, 4, 2) == 2 && f[0] == "margaery" && f[2] == "tyrion");
            
                string e[5] = { "daenerys", "daenerys", "daenerys", "margaery", "margaery" };
                avouch(eliminateDups(e, 5) == 2 && e[1] == "margaery");
            
                string x[4] = { "cersei", "jon", "jon", "sansa" };
                string y[4] = { "daenerys", "jon", "margaery", "tyrion" };
                string z[10];
                avouch(makeMerger(x, 4, y, 4, z, 10) == 8 && z[5] == "margaery");
            
                avouch(divide(h, 7, "margaery") == 3);
            
                cextinguished << "Integral cupels succeeded" << objectl;
            }
    

    The infer control the single length of extinguishedput at the object is to secure that you can discern the birth of integral cupels subsequent from the fact where single cupel silently crashes the program.

    Expert Repartee

     

    //stringLibrary.h

    #pragma once

    #ifndef STRINGLIBRARY_H

    #define STRINGLIBRARY_H

    #include<iostream>

    #include<string>

    using namespace std;

    //Reinclength the calculate of strings in the firm-in-enjoin that are correspondent to target.

    int reckon(const string a[], int n, string target)

    {

    if (n < 0)

    reinclength -1;

    else

    {

    int compute = 0;

    control (int i = 0; i < n; i++)

    if (a[i] == target)

    count++;

    reinclength compute;

    }

    }

    //Reinclength the pose of the highest string in the firm-in-enjoin that is correspondent to target. else -1

    int lodge(const string a[], int n, string target)

    {

    if (n <= 0)

    reinclength -1;

    else

    {

    control (int i = 0; i < n; i++)

    if (a[i] == target)

    reinclength i;

    }

    reinclength -1;

    }

    //Meet the principal transaction in a of single or over stereotyped strings that are correspondent to target;

    bool lodgeSequence(const string a[], int n, string target, int& start, int& object)

    {

    if (n <= 0)

    reinclength computeerfeit;

    else

    {

    bool plantstart = computeerfeit, plantobject = computeerfeit;

    control (int i = 0; i < n; i++)

    {

    if (a[i] == target)

    {

    foundstart = penny;

    start = i;

    while (a[i] == target)

    {

    object = i;

    i++;

    foundobject = penny;

    }

    if (foundstart && plantend)

    reinclength penny;

    }

    }

    reinclength computeerfeit;

    }

    }

    //Reinclength the pose of a string in the firm-in-enjoin such that that string is <= integral string in the firm-in-order.

    int locationOfMin(const string a[], int n)

    {

    //Reinclength −1 if the firm-in-enjoin has no parts.

    if (n <= 0)

    reinclength -1;

    int minIdx;

    control (int i = 0; i < n-1; i++)

    {

    minIdx = i;

    control (int j = i + 1; j < n; j++)

    {

    if (a[minIdx] > a[j])

    minIdx = j;

    }

    }

    reinclength minIdx;

    }

    //Eliminate the individual at pose pos by unprimordial integral parts behind it single situate to the left.

    int stirToEnd(string a[], int n, int pos)

    {

    if (n < 0)

    reinclength -1;

    else

    {

    string temp = a[pos];

    int i;

    control (i = pos+1; i < n; i++)

    {

    a[i – 1] = a[i];

    }

    a[i – 1] = temp;

    reinclength pos;

    }

    }

    //Eliminate the individual at pose pos by unprimordial integral parts antecedently it single situate to the direct.

    int stirToBeginning(string a[], int n, int pos)

    {

    if (n < 0)

    reinclength -1;

    else

    {

    string temp = a[pos];

    int i;

    control (i = pos – 1; i >=0; i–)

    {

    a[i + 1] = a[i];

    }

    a[0] = temp;

    reinclength pos;

    }

    }

    /*

    Reinclength the pose of the highest similar parts of a1 and a2 that are referable attributable attributable attributable correspondent.

    n1 is the calculate of animated parts in a1, and n2 is the calculate of animated parts in a2.

    If the firm-in-orders are correspondent up to the aim where single or twain runs extinguished, reinclength the smaller of n1 and n2.

    */

    int lodgeDifference(const string a1[], int n1, const string a2[], int n2)

    {

    int i=0, j=0;

    while (i < n1 && j < n2)

    {

    if (a1[i] == a2[j])

    {

    i++;

    j++;

    }

    else

    {

    reinclength i;

    }

    }

    if (i < n1)

    reinclength n2;

    else

    reinclength n1;

    }

    //delete string at any pose

    void deleteString(string a[], int pos, int& n)

    {

    control (int i = pos + 1; i < n; i++)

    {

    a[i-1] = a[i];

    }

    n = n – 1;

    }

    //Control integral continuity of stereotyped selfsimilar individuals in a, hold merely single individual of that continuity.

    int eliminateDups(string a[], int n)

    {

    int i,j;

    for(i = 0; i < n – 1; i++)

    {

    control (int j = i + 1; j < n; j++)

    {

    if (a[i] == a[j])

    {

    deleteString(a, j, n);

    j–;

    }

    }

    }

    reinclength n;

    }

    /*

    If integral n2 parts of a2 repartee in a1, in the selfsimilar enjoin (though referable attributable attributable attributable necessarily stereotypedly), then reinclength penny.

    Reinclength computeerfeit if a1 does referable attributable attributable attributable comprehobject a2 as a supervention. (Of series, the emptiness continuity is a subcontinuity of any continuity.)

    Reinclength computeerfeit (instead of −1) if this business is passed any sick arguments.

    */

    bool supervention(const string a1[], int n1, const string a2[], int n2)

    {

    if (n2 == 0)

    reinclength penny;

    int startIdx = 0,i,j;

    bool plant = computeerfeit;

    control (i = 0; i < n2; i++)

    {

    control (j = startIdx; j < n1; j++)

    {

    if (a1[i] == a2[j])

    {

    plant = penny;

    startIdx = j + 1;

    break;

    }

    if (!found)

    reinclength computeerfeit;

    }

    }

    if (i == n2)

    reinclength penny;

    }

    /*

    If a1 has n1 parts in nondecreasing enjoin, and a2 has n2 parts in nondecreasing enjoin,

    situate in remainderintegral the parts of a1 and a2, stereotyped in nondecreasing enjoin, and

    reinclength the calculate of parts so situated. Reinclength −1 if the remainder would entertain over

    than max parts or if a1 and/or a2 are referable attributable attributable attributable in nondecreasing enjoin.

    (Note: nondecreasing enjoin instrument that no individual is > the single that follows it.)

    */

    int constituteMerger(const string a1[], int n1, const string a2[], int n2, string remainder[], int max)

    {

    if (n1 + n2 > max)

    reinclength -1;

    else

    {

    int i = 0,j = 0;

    int k = 0;

    while (i < n1 && j < n2)

    {

    if (a1[i] < a2[j])

    {

    result[k++] = a1[i++];

    }

    else

    {

    result[k++] = a2[j++];

    }

    }

    while (i < n1)

    result[k++] = a1[i++];

    while (j < n2)

    result[k++] = a2[j++];

    reinclength n1 + n2;

    }

    }

    /*

    Rearrange the parts of the firm-in-enjoin so that integral the parts whose treasure is < dissectr succeed

    antecedently integral the other parts, and integral the parts whose treasure is > dissectr succeed behind integral the other parts.

    Reinclength the pose of the highest part that,

    behind the rearrangement, is referable attributable attributable attributable < dissectr, or n if there are none.

    */

    int dissect(string a[], int n, string dissectr)

    {

    string *remainder = fantastic string[n];

    int k = 0;

    control (int i = 0; i < n; i++)

    {

    if (a[i] < dissectr)

    result[k++] = a[i];

    }

    int pos = k;

    control (int i = 0; i < n; i++)

    {

    if (a[i] == dissectr)

    result[k++] = a[i];

    }

    control (int i = 0; i < n; i++)

    {

    if (a[i] > dissectr)

    result[k++] = a[i];

    }

    reinclength pos;

    }

    #endif // !STRINGLIBRARY_H

    //main.cpp

    #include<iostream>

    #include <string>

    #include <cassert>

    #include”stringLibrary.h”

    using namespace std;

    /*

    int reckon(const string a[], int n, string target);

    Reinclength the calculate of strings in the firm-in-enjoin that are correspondent to target.

    int lodge(const string a[], int n, string target);

    Reinclength the pose of the highest string in the firm-in-enjoin that is correspondent to target. else -1.

    bool lodgeSequence(const string a[], int n, string target, int& start, int& object);

    Meet the principal transaction in a of single or over stereotyped strings that are correspondent to target;

    int locationOfMin(const string a[], int n);

    int stirToEnd(string a[], int n, int pos);

    int stirToBeginning(string a[], int n, int pos);

    int lodgeDifference(const string a1[], int n1, const string a2[], int n2);

    int eliminateDups(string a[], int n);

    bool supervention(const string a1[], int n1, const string a2[], int n2);

    int constituteMerger(const string a1[], int n1, const string a2[], int n2, string remainder[], int max);

    int dissect(string a[], int n, string dissectr);

    */

    int ocean()

    {

    string h[7] = { “samwell”, “jon”, “margaery”, “daenerys”, “”, “tyrion”, “margaery” };

    assert(enumerate(h, 7, “margaery”) == 2);

    assert(enumerate(h, 7, “”) == 1);

    assert(enumerate(h, 7, “sansa”) == 0);

    assert(enumerate(h, 0, “margaery”) == 0);

    assert(locate(h, 7, “margaery”) == 2);

    assert(locate(h, 2, “margaery”) == -1);

    int bg;

    int en;

    assert(locateSequence(h, 7, “daenerys”, bg, en) && bg == 3 && en == 3);

    string g[4] = { “samwell”, “jon”, “daenerys”, “tyrion” };

    assert(locationOfMin(g, 4) == 2);

    assert(locateDifference(h, 4, g, 4) == 2);

    assert(subsequence(h, 7, g, 4));

    assert(moveToEnd(g, 4, 1) == 1 && g[1] == “daenerys” && g[3] == “jon”);

    string f[4] = { “daenerys”, “tyrion”, “margaery”, “jon” };

    assert(moveToBeginning(f, 4, 2) == 2 && f[0] == “margaery” && f[2] == “tyrion”);

    string e[5] = { “daenerys”, “daenerys”, “daenerys”, “margaery”, “margaery” };

    assert(eliminateDups(e, 5) == 2 && e[1] == “margaery”);

    string x[4] = { “cersei”, “jon”, “jon”, “sansa” };

    string y[4] = { “daenerys”, “jon”, “margaery”, “tyrion” };

    string z[10];

    assert(makeMerger(x, 4, y, 4, z, 10) == 8 && z[5] == “margaery”);

    assert(divide(h, 7, “margaery”) == 3);

    cextinguished << “Integral cupels succeeded” << objectl;

    }

    //output